ecore_con_url_cookies_example.c

Shows how to manage cookies on a Ecore_Con_Url object. See the complete example description at Ecore_Con_Url - Managing cookies.

//Compile with:
// gcc -o ecore_con_url_cookies_example ecore_con_url_cookies_example.c `pkg-config --libs --cflags ecore ecore-con eina`
#include <stdio.h>
#include <Eina.h>
#include <Ecore.h>
#include <Ecore_Con.h>
#define COOKIEJAR "cookies.jar"
static Eina_Bool
_url_data_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
{
Ecore_Con_Event_Url_Data *url_data = event_info;
int i;
printf("\nData received from server:\n>>>>>\n");
for (i = 0; i < url_data->size; i++)
printf("%c", url_data->data[i]);
printf("\n>>>>>>\n\n");
return EINA_TRUE;
}
static Eina_Bool
_url_complete_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
{
Ecore_Con_Event_Url_Complete *url_complete = event_info;
const Eina_List *headers, *l;
char *str;
printf("\n");
printf("download completed with status code: %d\n", url_complete->status);
headers = ecore_con_url_response_headers_get(url_complete->url_con);
printf("response headers:\n");
EINA_LIST_FOREACH(headers, l, str)
printf("header: %s", str);
return EINA_TRUE;
}
int
main(int argc, const char *argv[])
{
Ecore_Con_Url *ec_url = NULL;
char cmd = '\0';
if (argc < 2)
{
printf("need at least one parameter: <url> [command]\n");
return -1;
}
if (argc > 2)
cmd = argv[2][0];
ec_url = ecore_con_url_new(argv[1]);
if (!ec_url)
{
printf("error when creating ecore con url object.\n");
goto end;
}
ecore_con_url_additional_header_add(ec_url, "User-Agent", "Ecore_Con client");
if (cmd != 'c' && cmd != 's')
ecore_con_url_cookies_file_add(ec_url, COOKIEJAR);
switch (cmd)
{
case 'c': // clear
printf("Cleaning previously set cookies.\n");
break;
case 's': // clear session
printf("Cleaning previously set session cookies.\n");
break;
case 'i': // ignore session
printf("Ignoring old session cookies.\n");
}
r = ecore_con_url_get(ec_url);
if (!r)
{
printf("could not realize request.\n");
goto free_ec_url;
}
free_ec_url:
end:
return 0;
}