aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/examples/ecore_con_url_cookies_example.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/ecore/src/examples/ecore_con_url_cookies_example.c')
-rw-r--r--libraries/ecore/src/examples/ecore_con_url_cookies_example.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/libraries/ecore/src/examples/ecore_con_url_cookies_example.c b/libraries/ecore/src/examples/ecore_con_url_cookies_example.c
new file mode 100644
index 0000000..64f37d2
--- /dev/null
+++ b/libraries/ecore/src/examples/ecore_con_url_cookies_example.c
@@ -0,0 +1,119 @@
1#include <stdio.h>
2#include <Eina.h>
3#include <Ecore.h>
4#include <Ecore_Con.h>
5
6#ifdef HAVE_CONFIG_H
7# include "config.h"
8#else
9# define __UNUSED__
10#endif
11
12#define COOKIEJAR "cookies.jar"
13
14static Eina_Bool
15_url_data_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
16{
17 Ecore_Con_Event_Url_Data *url_data = event_info;
18 int i;
19
20 printf("\nData received from server:\n>>>>>\n");
21 for (i = 0; i < url_data->size; i++)
22 printf("%c", url_data->data[i]);
23 printf("\n>>>>>>\n\n");
24
25 return EINA_TRUE;
26}
27
28static Eina_Bool
29_url_complete_cb(void *data __UNUSED__, int type __UNUSED__, void *event_info)
30{
31 Ecore_Con_Event_Url_Complete *url_complete = event_info;
32 const Eina_List *headers, *l;
33 char *str;
34
35 printf("\n");
36 printf("download completed with status code: %d\n", url_complete->status);
37
38 headers = ecore_con_url_response_headers_get(url_complete->url_con);
39
40 printf("response headers:\n");
41 EINA_LIST_FOREACH(headers, l, str)
42 printf("header: %s", str);
43
44 ecore_con_url_cookies_jar_write(url_complete->url_con);
45
46 ecore_main_loop_quit();
47
48 return EINA_TRUE;
49}
50
51int main(int argc, const char *argv[])
52{
53 Ecore_Con_Url *ec_url = NULL;
54 char cmd = '\0';
55 Eina_Bool r;
56
57 if (argc < 2)
58 {
59 printf("need at least one parameter: <url> [command]\n");
60 return -1;
61 }
62
63 if (argc > 2)
64 cmd = argv[2][0];
65
66 ecore_init();
67 ecore_con_init();
68 ecore_con_url_init();
69
70 ec_url = ecore_con_url_new(argv[1]);
71 if (!ec_url)
72 {
73 printf("error when creating ecore con url object.\n");
74 goto end;
75 }
76
77 ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL);
78 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);
79
80 ecore_con_url_additional_header_add(ec_url, "User-Agent", "Ecore_Con client");
81
82 ecore_con_url_cookies_init(ec_url);
83 if (cmd != 'c' && cmd != 's')
84 ecore_con_url_cookies_file_add(ec_url, COOKIEJAR);
85 ecore_con_url_cookies_jar_file_set(ec_url, COOKIEJAR);
86
87 switch (cmd)
88 {
89 case 'c': // clear
90 printf("Cleaning previously set cookies.\n");
91 ecore_con_url_cookies_clear(ec_url);
92 break;
93 case 's': // clear session
94 printf("Cleaning previously set session cookies.\n");
95 ecore_con_url_cookies_session_clear(ec_url);
96 break;
97 case 'i': // ignore session
98 printf("Ignoring old session cookies.\n");
99 ecore_con_url_cookies_ignore_old_session_set(ec_url, EINA_TRUE);
100 }
101
102 r = ecore_con_url_get(ec_url);
103 if (!r)
104 {
105 printf("could not realize request.\n");
106 goto free_ec_url;
107 }
108
109 ecore_main_loop_begin();
110
111free_ec_url:
112 ecore_con_url_free(ec_url);
113end:
114 ecore_con_url_shutdown();
115 ecore_con_shutdown();
116 ecore_shutdown();
117
118 return 0;
119}