\hypertarget{ecore_con_url_cookies_example_8c-example}{}\doxysection{ecore\+\_\+con\+\_\+url\+\_\+cookies\+\_\+example.\+c}
Shows how to manage cookies on a \mbox{\hyperlink{group__Ecore__Con__Url__Group_gad928193ae403bd05c1ce5ba48a1d52ea}{Ecore\+\_\+\+Con\+\_\+\+Url}} object. See the complete example description at \mbox{\hyperlink{ecore_con_url_cookies_example_c}{Ecore\+\_\+\+Con\+\_\+\+Url -\/ Managing cookies}}.


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{\textcolor{comment}{//Compile with:}}
\DoxyCodeLine{\textcolor{comment}{// gcc -\/o ecore\_con\_url\_cookies\_example ecore\_con\_url\_cookies\_example.c `pkg-\/config -\/-\/libs -\/-\/cflags ecore ecore-\/con eina`}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <\mbox{\hyperlink{Eina_8h}{Eina.h}}>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Ecore.h>}}
\DoxyCodeLine{\textcolor{preprocessor}{\#include <Ecore\_Con.h>}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{preprocessor}{\#define COOKIEJAR "{}cookies.jar"{}}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_url\_data\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data}{Ecore\_Con\_Event\_Url\_Data}} *url\_data = event\_info;}
\DoxyCodeLine{   \textcolor{keywordtype}{int} i;}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}\(\backslash\)nData received from server:\(\backslash\)n>>>>>\(\backslash\)n"{}});}
\DoxyCodeLine{   \textcolor{keywordflow}{for} (i = 0; i < url\_data-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data_a1d4725aa77f3875cc3405597a5fbff91}{size}}; i++)}
\DoxyCodeLine{     printf(\textcolor{stringliteral}{"{}\%c"{}}, url\_data-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Data_aaa4c4dbc6575b071164f8152a7808268}{data}}[i]);}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}\(\backslash\)n>>>>>>\(\backslash\)n\(\backslash\)n"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}}
\DoxyCodeLine{\_url\_complete\_cb(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{void} *event\_info)}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{struct__Ecore__Con__Event__Url__Complete}{Ecore\_Con\_Event\_Url\_Complete}} *url\_complete = event\_info;}
\DoxyCodeLine{   \textcolor{keyword}{const} \mbox{\hyperlink{struct__Eina__List}{Eina\_List}} *headers, *l;}
\DoxyCodeLine{   \textcolor{keywordtype}{char} *str;}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}\(\backslash\)n"{}});}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}download completed with status code: \%d\(\backslash\)n"{}}, url\_complete-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Complete_ab842caa1615a911c3578e0dfeae5f773}{status}});}
\DoxyCodeLine{}
\DoxyCodeLine{   headers = \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga3e76e9c1aaf660cf203a164803d70b50}{ecore\_con\_url\_response\_headers\_get}}(url\_complete-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Complete_a58335ec0eac21f9c0828695922807039}{url\_con}});}
\DoxyCodeLine{}
\DoxyCodeLine{   printf(\textcolor{stringliteral}{"{}response headers:\(\backslash\)n"{}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__List__Group_gac6efafc19f526d916cdb9757240a8773}{EINA\_LIST\_FOREACH}}(headers, l, str)}
\DoxyCodeLine{     printf(\textcolor{stringliteral}{"{}header: \%s"{}}, str);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga5776168771246f117c38bb2f1bc2fff4}{ecore\_con\_url\_cookies\_jar\_write}}(url\_complete-\/>\mbox{\hyperlink{struct__Ecore__Con__Event__Url__Complete_a58335ec0eac21f9c0828695922807039}{url\_con}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{\textcolor{keywordtype}{int}}
\DoxyCodeLine{main(\textcolor{keywordtype}{int} argc, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *argv[])}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_gad928193ae403bd05c1ce5ba48a1d52ea}{Ecore\_Con\_Url}} *ec\_url = NULL;}
\DoxyCodeLine{   \textcolor{keywordtype}{char} cmd = \textcolor{charliteral}{'\(\backslash\)0'};}
\DoxyCodeLine{   \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} r;}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (argc < 2)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}need at least one parameter: <url> [command]\(\backslash\)n"{}});}
\DoxyCodeLine{        \textcolor{keywordflow}{return} -\/1;}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (argc > 2)}
\DoxyCodeLine{     cmd = argv[2][0];}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Lib__Group_gacf5ecf42c516bb9c8b6759721e9559bd}{ecore\_con\_init}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga47ad809433853db53742f3fd5ce89ac9}{ecore\_con\_url\_init}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   ec\_url = \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga2c98956bd920dcf0a42fa9f65997931e}{ecore\_con\_url\_new}}(argv[1]);}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!ec\_url)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}error when creating ecore con url object.\(\backslash\)n"{}});}
\DoxyCodeLine{        \textcolor{keywordflow}{goto} end;}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga6ebe51236dac1bc1255b5b390cc9e6e3}{ECORE\_CON\_EVENT\_URL\_DATA}}, \_url\_data\_cb, NULL);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_gae90b9b857e1e0adc0c7f24e7ccecb44b}{ECORE\_CON\_EVENT\_URL\_COMPLETE}}, \_url\_complete\_cb, NULL);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_gadc647289df759b5f79faae4103b11220}{ecore\_con\_url\_additional\_header\_add}}(ec\_url, \textcolor{stringliteral}{"{}User-\/Agent"{}}, \textcolor{stringliteral}{"{}Ecore\_Con client"{}});}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga75188398a164ec1ee57c2bf9195d6a8b}{ecore\_con\_url\_cookies\_init}}(ec\_url);}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (cmd != \textcolor{charliteral}{'c'} \&\& cmd != \textcolor{charliteral}{'s'})}
\DoxyCodeLine{     \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga0e45149c704e5303b1aecb29066c1454}{ecore\_con\_url\_cookies\_file\_add}}(ec\_url, COOKIEJAR);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga5be3eadea97987953bc8cd3038dfd8d8}{ecore\_con\_url\_cookies\_jar\_file\_set}}(ec\_url, COOKIEJAR);}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{switch} (cmd)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{      \textcolor{keywordflow}{case} \textcolor{charliteral}{'c'}: \textcolor{comment}{// clear}}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}Cleaning previously set cookies.\(\backslash\)n"{}});}
\DoxyCodeLine{        \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga4afcd3abe8e99acb3d0c2745c6953aac}{ecore\_con\_url\_cookies\_clear}}(ec\_url);}
\DoxyCodeLine{        \textcolor{keywordflow}{break};}
\DoxyCodeLine{}
\DoxyCodeLine{      \textcolor{keywordflow}{case} \textcolor{charliteral}{'s'}: \textcolor{comment}{// clear session}}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}Cleaning previously set session cookies.\(\backslash\)n"{}});}
\DoxyCodeLine{        \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga1313aef4b39ef417e648c25e099d705c}{ecore\_con\_url\_cookies\_session\_clear}}(ec\_url);}
\DoxyCodeLine{        \textcolor{keywordflow}{break};}
\DoxyCodeLine{}
\DoxyCodeLine{      \textcolor{keywordflow}{case} \textcolor{charliteral}{'i'}: \textcolor{comment}{// ignore session}}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}Ignoring old session cookies.\(\backslash\)n"{}});}
\DoxyCodeLine{        \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga2849116f723e3a9469d1f8756d1f2cca}{ecore\_con\_url\_cookies\_ignore\_old\_session\_set}}(ec\_url, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   r = \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga25474c61332fa89a0db7e572c4519bdb}{ecore\_con\_url\_get}}(ec\_url);}
\DoxyCodeLine{   \textcolor{keywordflow}{if} (!r)}
\DoxyCodeLine{     \{}
\DoxyCodeLine{        printf(\textcolor{stringliteral}{"{}could not realize request.\(\backslash\)n"{}});}
\DoxyCodeLine{        \textcolor{keywordflow}{goto} free\_ec\_url;}
\DoxyCodeLine{     \}}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();}
\DoxyCodeLine{}
\DoxyCodeLine{free\_ec\_url:}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_ga276545b915a8adf226e9407165e09173}{ecore\_con\_url\_free}}(ec\_url);}
\DoxyCodeLine{end:}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Url__Group_gad2a823bd44d0bd0c1960842cca90bcbf}{ecore\_con\_url\_shutdown}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Con__Lib__Group_gaccfd8dd2a1187b71339b5cc39dc83938}{ecore\_con\_shutdown}}();}
\DoxyCodeLine{   \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}
\DoxyCodeLine{}

\end{DoxyCodeInclude}
 