aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/ecore/src/examples/ecore_con_url_headers_example.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/ecore/src/examples/ecore_con_url_headers_example.c104
1 files changed, 0 insertions, 104 deletions
diff --git a/libraries/ecore/src/examples/ecore_con_url_headers_example.c b/libraries/ecore/src/examples/ecore_con_url_headers_example.c
deleted file mode 100644
index 262823b..0000000
--- a/libraries/ecore/src/examples/ecore_con_url_headers_example.c
+++ /dev/null
@@ -1,104 +0,0 @@
1#include <stdio.h>
2#include <Eina.h>
3#include <Ecore.h>
4#include <Ecore_Con.h>
5
6static Eina_Bool
7_url_data_cb(void *data, int type, void *event_info)
8{
9 Ecore_Con_Event_Url_Data *url_data = event_info;
10 int i;
11
12 for (i = 0; i < url_data->size; i++)
13 printf("%c", url_data->data[i]);
14
15 return EINA_TRUE;
16}
17
18static Eina_Bool
19_url_complete_cb(void *data, int type, void *event_info)
20{
21 Ecore_Con_Event_Url_Complete *url_complete = event_info;
22 const Eina_List *headers, *l;
23 char *str;
24
25 printf("\n");
26 printf("download completed with status code: %d\n", url_complete->status);
27
28 headers = ecore_con_url_response_headers_get(url_complete->url_con);
29
30 EINA_LIST_FOREACH(headers, l, str)
31 printf("header: %s\n", str);
32
33 ecore_main_loop_quit();
34
35 return EINA_TRUE;
36}
37
38int main(int argc, const char *argv[])
39{
40 Ecore_Con_Url *ec_url = NULL;
41 const char *type;
42 Eina_Bool r;
43
44 if (argc < 3)
45 {
46 printf("need at least two parameters: < POST|GET > <url1>\n");
47 return -1;
48 }
49
50 type = argv[1];
51
52 if (strcmp(type, "POST") && (strcmp(type, "GET")))
53 {
54 printf("only POST or GET are supported by this example.\n");
55 return -1;
56 }
57
58 ecore_init();
59 ecore_con_init();
60 ecore_con_url_init();
61
62 // check if requests are being pipelined, and set them if not:
63 if (!ecore_con_url_pipeline_get())
64 ecore_con_url_pipeline_set(EINA_TRUE);
65
66 ec_url = ecore_con_url_custom_new(argv[2], type);
67 if (!ec_url)
68 {
69 printf("error when creating ecore con url object.\n");
70 goto end;
71 }
72
73 ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL);
74 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);
75
76 ecore_con_url_additional_header_add(ec_url, "User-Agent", "blablabla");
77 ecore_con_url_verbose_set(ec_url, EINA_TRUE);
78
79 ecore_con_url_httpauth_set(ec_url, "user", "password", EINA_FALSE);
80
81 ecore_con_url_time(ec_url, ECORE_CON_URL_TIME_IFMODSINCE, 0);
82
83 if (!strcmp(type, "GET"))
84 r = ecore_con_url_get(ec_url);
85 else
86 r = ecore_con_url_post(ec_url, NULL, 0, NULL);
87
88 if (!r)
89 {
90 printf("could not realize request.\n");
91 goto free_ec_url;
92 }
93
94 ecore_main_loop_begin();
95
96free_ec_url:
97 ecore_con_url_free(ec_url);
98end:
99 ecore_con_url_shutdown();
100 ecore_con_shutdown();
101 ecore_shutdown();
102
103 return 0;
104}