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


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o ecore\_con\_url\_cookies\_example ecore\_con\_url\_cookies\_example.c `pkg-config --libs --cflags ecore
       ecore-con eina`}

\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <\hyperlink{Eina_8h}{Eina.h}>}
\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <Ecore\_Con.h>}

\textcolor{preprocessor}{#define COOKIEJAR "cookies.jar"}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_url\_data\_cb(\textcolor{keywordtype}{void} *data \hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}, \textcolor{keywordtype}{int} type EINA\_UNUSED, \textcolor{keywordtype}{void} *event\_info)
\{
   \hyperlink{struct__Ecore__Con__Event__Url__Data}{Ecore\_Con\_Event\_Url\_Data} *url\_data = event\_info;
   \textcolor{keywordtype}{int} i;

   printf(\textcolor{stringliteral}{"\(\backslash\)nData received from server:\(\backslash\)n>>>>>\(\backslash\)n"});
   \textcolor{keywordflow}{for} (i = 0; i < url\_data->\hyperlink{struct__Ecore__Con__Event__Url__Data_a1d4725aa77f3875cc3405597a5fbff91}{size}; i++)
     printf(\textcolor{stringliteral}{"%c"}, url\_data->\hyperlink{struct__Ecore__Con__Event__Url__Data_aaa4c4dbc6575b071164f8152a7808268}{data}[i]);
   printf(\textcolor{stringliteral}{"\(\backslash\)n>>>>>>\(\backslash\)n\(\backslash\)n"});

   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};
\}

\textcolor{keyword}{static} \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}
\_url\_complete\_cb(\textcolor{keywordtype}{void} *data \hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}, \textcolor{keywordtype}{int} type \hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}, \textcolor{keywordtype}{void} *event\_info)
\{
   \hyperlink{struct__Ecore__Con__Event__Url__Complete}{Ecore\_Con\_Event\_Url\_Complete} *url\_complete = event\_info;
   \textcolor{keyword}{const} \hyperlink{struct__Eina__List}{Eina\_List} *headers, *l;
   \textcolor{keywordtype}{char} *str;

   printf(\textcolor{stringliteral}{"\(\backslash\)n"});
   printf(\textcolor{stringliteral}{"download completed with status code: %d\(\backslash\)n"}, url\_complete->\hyperlink{struct__Ecore__Con__Event__Url__Complete_ab842caa1615a911c3578e0dfeae5f773}{status});

   headers = \hyperlink{group__Ecore__Con__Url__Group_gad2b33c58653c013adbd0953555081fc6}{ecore\_con\_url\_response\_headers\_get}(url\_complete->
      \hyperlink{struct__Ecore__Con__Event__Url__Complete_a58335ec0eac21f9c0828695922807039}{url\_con});

   printf(\textcolor{stringliteral}{"response headers:\(\backslash\)n"});
   \hyperlink{group__Eina__List__Group_gac6efafc19f526d916cdb9757240a8773}{EINA\_LIST\_FOREACH}(headers, l, str)
     printf(\textcolor{stringliteral}{"header: %s"}, str);

   \hyperlink{group__Ecore__Con__Url__Group_gaa963de30a668dea0055ae94d940f00fa}{ecore\_con\_url\_cookies\_jar\_write}(url\_complete->
      \hyperlink{struct__Ecore__Con__Event__Url__Complete_a58335ec0eac21f9c0828695922807039}{url\_con});

   \hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}();

   \textcolor{keywordflow}{return} \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE};
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc, \textcolor{keyword}{const} \textcolor{keywordtype}{char} *argv[])
\{
   \hyperlink{group__Ecore__Con__Url__Group_gad928193ae403bd05c1ce5ba48a1d52ea}{Ecore\_Con\_Url} *ec\_url = NULL;
   \textcolor{keywordtype}{char} cmd = \textcolor{charliteral}{'\(\backslash\)0'};
   \hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool} r;

   \textcolor{keywordflow}{if} (argc < 2)
     \{
        printf(\textcolor{stringliteral}{"need at least one parameter: <url> [command]\(\backslash\)n"});
        \textcolor{keywordflow}{return} -1;
     \}

   \textcolor{keywordflow}{if} (argc > 2)
     cmd = argv[2][0];

   \hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}();
   \hyperlink{group__Ecore__Con__Lib__Group_gacf5ecf42c516bb9c8b6759721e9559bd}{ecore\_con\_init}();
   \hyperlink{group__Ecore__Con__Url__Group_gac3fbeaf9cde529362e4567fc37e45c9f}{ecore\_con\_url\_init}();

   ec\_url = \hyperlink{group__Ecore__Con__Url__Group_gae40b7c1a94413166c61524b707118f19}{ecore\_con\_url\_new}(argv[1]);
   \textcolor{keywordflow}{if} (!ec\_url)
     \{
        printf(\textcolor{stringliteral}{"error when creating ecore con url object.\(\backslash\)n"});
        \textcolor{keywordflow}{goto} end;
     \}

   \hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}(\hyperlink{group__Ecore__Con__Events__Group_ga6ebe51236dac1bc1255b5b390cc9e6e3}{ECORE\_CON\_EVENT\_URL\_DATA}, 
      \_url\_data\_cb, NULL);
   \hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}(\hyperlink{group__Ecore__Con__Events__Group_gae90b9b857e1e0adc0c7f24e7ccecb44b}{ECORE\_CON\_EVENT\_URL\_COMPLETE},
       \_url\_complete\_cb, NULL);

   \hyperlink{group__Ecore__Con__Url__Group_ga1f9939c84aa5128d5197f1939d8cffeb}{ecore\_con\_url\_additional\_header\_add}(ec\_url, \textcolor{stringliteral}{"User-Agent"}, \textcolor{stringliteral}{"Ecore\_Con
       client"});

   \hyperlink{group__Ecore__Con__Url__Group_gae5c1b9a66fefc8787639f7c8a93385f7}{ecore\_con\_url\_cookies\_init}(ec\_url);
   \textcolor{keywordflow}{if} (cmd != \textcolor{charliteral}{'c'} && cmd != \textcolor{charliteral}{'s'})
     \hyperlink{group__Ecore__Con__Url__Group_ga77166d4a6fc33910e695535c8e856719}{ecore\_con\_url\_cookies\_file\_add}(ec\_url, COOKIEJAR);
   \hyperlink{group__Ecore__Con__Url__Group_gaf82657c0ae5ff8028ef10bda18178611}{ecore\_con\_url\_cookies\_jar\_file\_set}(ec\_url, COOKIEJAR);

   \textcolor{keywordflow}{switch} (cmd)
     \{
      \textcolor{keywordflow}{case} \textcolor{charliteral}{'c'}: \textcolor{comment}{// clear}
        printf(\textcolor{stringliteral}{"Cleaning previously set cookies.\(\backslash\)n"});
        \hyperlink{group__Ecore__Con__Url__Group_ga551d90e851f84148c3c5d130513538d9}{ecore\_con\_url\_cookies\_clear}(ec\_url);
        \textcolor{keywordflow}{break};

      \textcolor{keywordflow}{case} \textcolor{charliteral}{'s'}: \textcolor{comment}{// clear session}
        printf(\textcolor{stringliteral}{"Cleaning previously set session cookies.\(\backslash\)n"});
        \hyperlink{group__Ecore__Con__Url__Group_ga683faee0b33eda35c0d5e818829161c0}{ecore\_con\_url\_cookies\_session\_clear}(ec\_url);
        \textcolor{keywordflow}{break};

      \textcolor{keywordflow}{case} \textcolor{charliteral}{'i'}: \textcolor{comment}{// ignore session}
        printf(\textcolor{stringliteral}{"Ignoring old session cookies.\(\backslash\)n"});
        \hyperlink{group__Ecore__Con__Url__Group_ga0261c1100b21b04b4bfad979fa9f9a39}{ecore\_con\_url\_cookies\_ignore\_old\_session\_set}(ec\_url, 
      \hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE});
     \}

   r = \hyperlink{group__Ecore__Con__Url__Group_ga46f75358256eec26bd99eef96b25ffa8}{ecore\_con\_url\_get}(ec\_url);
   \textcolor{keywordflow}{if} (!r)
     \{
        printf(\textcolor{stringliteral}{"could not realize request.\(\backslash\)n"});
        \textcolor{keywordflow}{goto} free\_ec\_url;
     \}

   \hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}();

free\_ec\_url:
   \hyperlink{group__Ecore__Con__Url__Group_ga711510886aaece16f5dee6903c603fb2}{ecore\_con\_url\_free}(ec\_url);
end:
   \hyperlink{group__Ecore__Con__Url__Group_ga0da252aa2c919722894dd41cc6549435}{ecore\_con\_url\_shutdown}();
   \hyperlink{group__Ecore__Con__Lib__Group_gaccfd8dd2a1187b71339b5cc39dc83938}{ecore\_con\_shutdown}();
   \hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}
 