parent
128074a2bd
commit
46d4358209
39 changed files with 4742 additions and 0 deletions
@ -0,0 +1,186 @@ |
||||
MAINTAINERCLEANFILES = Makefile.in
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
-I$(top_srcdir)/src/lib/eina \ |
||||
-I$(top_srcdir)/src/lib/eo \ |
||||
-I$(top_srcdir)/src/lib/evas \ |
||||
-I$(top_srcdir)/src/lib/ecore \ |
||||
-I$(top_srcdir)/src/lib/ecore_input \ |
||||
-I$(top_srcdir)/src/lib/ecore_con \ |
||||
-I$(top_srcdir)/src/lib/ecore_evas \ |
||||
-I$(top_builddir)/src/lib/eina \ |
||||
-I$(top_builddir)/src/lib/eo \ |
||||
-I$(top_builddir)/src/lib/evas \ |
||||
-I$(top_builddir)/src/lib/ecore \ |
||||
-I$(top_builddir)/src/lib/ecore_input \ |
||||
-I$(top_builddir)/src/lib/ecore_con \ |
||||
-I$(top_builddir)/src/lib/ecore_evas \ |
||||
-DPACKAGE_EXAMPLES_DIR=\"$(datadir)/ecore/examples\" \
|
||||
@ECORE_CFLAGS@ |
||||
|
||||
EXTRA_PROGRAMS = \
|
||||
ecore_animator_example \ |
||||
ecore_client_bench \ |
||||
ecore_con_client_simple_example \ |
||||
ecore_con_lookup_example \ |
||||
ecore_con_server_http_example \ |
||||
ecore_con_server_simple_example \ |
||||
ecore_con_url_cookies_example \ |
||||
ecore_con_url_download_example \ |
||||
ecore_con_url_headers_example \ |
||||
ecore_evas_basics_example \ |
||||
ecore_evas_buffer_example_01 \ |
||||
ecore_evas_buffer_example_02 \ |
||||
ecore_evas_callbacks \ |
||||
ecore_evas_ews_example \ |
||||
ecore_evas_object_example \ |
||||
ecore_evas_window_sizes_example \ |
||||
ecore_event_example_01 \ |
||||
ecore_event_example_02 \ |
||||
ecore_exe_example \ |
||||
ecore_exe_example_child \ |
||||
ecore_fd_handler_example \ |
||||
ecore_idler_example \ |
||||
ecore_job_example \ |
||||
ecore_pipe_simple_example \ |
||||
ecore_poller_example \ |
||||
ecore_server_bench \ |
||||
ecore_thread_example \ |
||||
ecore_time_functions_example \ |
||||
ecore_timer_example |
||||
|
||||
ecore_animator_example_SOURCES = ecore_animator_example.c
|
||||
ecore_animator_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_client_bench_SOURCES = ecore_client_bench.c
|
||||
ecore_client_bench_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_con_client_simple_example_SOURCES = ecore_con_client_simple_example.c
|
||||
ecore_con_client_simple_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_con_lookup_example_SOURCES = ecore_con_lookup_example.c
|
||||
ecore_con_lookup_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_con_server_http_example_SOURCES = ecore_con_server_http_example.c
|
||||
ecore_con_server_http_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_con_server_simple_example_SOURCES = ecore_con_server_simple_example.c
|
||||
ecore_con_server_simple_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_con_url_cookies_example_SOURCES = ecore_con_url_cookies_example.c
|
||||
ecore_con_url_cookies_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_con_url_download_example_SOURCES = ecore_con_url_download_example.c
|
||||
ecore_con_url_download_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_con_url_headers_example_SOURCES = ecore_con_url_headers_example.c
|
||||
ecore_con_url_headers_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_evas_basics_example_SOURCES = ecore_evas_basics_example.c
|
||||
ecore_evas_basics_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_evas_buffer_example_01_SOURCES = ecore_evas_buffer_example_01.c
|
||||
ecore_evas_buffer_example_01_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_evas_buffer_example_02_SOURCES = ecore_evas_buffer_example_02.c
|
||||
ecore_evas_buffer_example_02_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_evas_callbacks_SOURCES = ecore_evas_callbacks.c
|
||||
ecore_evas_callbacks_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_evas_ews_example_SOURCES = ecore_evas_ews_example.c
|
||||
ecore_evas_ews_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_evas_object_example_SOURCES = ecore_evas_object_example.c
|
||||
ecore_evas_object_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_evas_window_sizes_example_SOURCES = ecore_evas_window_sizes_example.c
|
||||
ecore_evas_window_sizes_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_event_example_01_SOURCES = ecore_event_example_01.c
|
||||
ecore_event_example_01_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_event_example_02_SOURCES = ecore_event_example_02.c
|
||||
ecore_event_example_02_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_exe_example_SOURCES = ecore_exe_example.c
|
||||
ecore_exe_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_exe_example_child_SOURCES = ecore_exe_example_child.c
|
||||
ecore_exe_example_child_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_fd_handler_example_SOURCES = ecore_fd_handler_example.c
|
||||
ecore_fd_handler_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_idler_example_SOURCES = ecore_idler_example.c
|
||||
ecore_idler_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_job_example_SOURCES = ecore_job_example.c
|
||||
ecore_job_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_pipe_simple_example_SOURCES = ecore_pipe_simple_example.c
|
||||
ecore_pipe_simple_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_poller_example_SOURCES = ecore_poller_example.c
|
||||
ecore_poller_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_server_bench_SOURCES = ecore_server_bench.c
|
||||
ecore_server_bench_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_thread_example_SOURCES = ecore_thread_example.c
|
||||
ecore_thread_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_time_functions_example_SOURCES = ecore_time_functions_example.c
|
||||
ecore_time_functions_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
ecore_timer_example_SOURCES = ecore_timer_example.c
|
||||
ecore_timer_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
|
||||
|
||||
SRCS = \
|
||||
ecore_animator_example \ |
||||
ecore_client_bench \ |
||||
ecore_con_client_simple_example \ |
||||
ecore_con_lookup_example \ |
||||
ecore_con_server_http_example \ |
||||
ecore_con_server_simple_example \ |
||||
ecore_con_url_cookies_example \ |
||||
ecore_con_url_download_example \ |
||||
ecore_con_url_headers_example \ |
||||
ecore_evas_basics_example \ |
||||
ecore_evas_buffer_example_01 \ |
||||
ecore_evas_buffer_example_02 \ |
||||
ecore_evas_callbacks \ |
||||
ecore_evas_ews_example \ |
||||
ecore_evas_object_example \ |
||||
ecore_evas_window_sizes_example \ |
||||
ecore_event_example_01 \ |
||||
ecore_event_example_02 \ |
||||
ecore_exe_example \ |
||||
ecore_exe_example_child \ |
||||
ecore_fd_handler_example \ |
||||
ecore_idler_example \ |
||||
ecore_job_example \ |
||||
ecore_pipe_simple_example \ |
||||
ecore_poller_example \ |
||||
ecore_server_bench \ |
||||
ecore_thread_example \ |
||||
ecore_time_functions_example \ |
||||
ecore_timer_example |
||||
|
||||
EXTRA_DIST = red.png
|
||||
|
||||
examples: $(EXTRA_PROGRAMS) |
||||
|
||||
clean-local: |
||||
rm -f $(EXTRA_PROGRAMS)
|
||||
|
||||
install-examples: |
||||
mkdir -p $(datadir)/ecore/examples
|
||||
$(install_sh_DATA) -c $(SRCS) $(datadir)/ecore/examples
|
||||
$(install_sh_DATA) -c red.png $(datadir)/ecore/examples
|
||||
|
||||
uninstall-local: |
||||
rm -f $(datadir)/ecore/examples/red.png
|
||||
for f in $(SRCS) ; do \
|
||||
rm -f $(datadir)/ecore/examples/$$f ; \
|
||||
done
|
@ -0,0 +1,117 @@ |
||||
//Compile with:
|
||||
//gcc -g -Wall `pkg-config --cflags --libs ecore-evas` -o ecore_animator_example ecore_animator_example.c
|
||||
|
||||
#include <Ecore.h> |
||||
#include <Ecore_Evas.h> |
||||
|
||||
static Eina_Bool _advance_frame(void *data, double pos); |
||||
static Eina_Bool _advance_frame2(void *data, double pos); |
||||
static Eina_Bool _advance_frame3(void *data); |
||||
static Eina_Bool _start_second_anim(void *data); |
||||
static Eina_Bool _freeze_third_anim(void *data); |
||||
static Eina_Bool _thaw_third_anim(void *data); |
||||
|
||||
int |
||||
main(int argc, char *argv[]) |
||||
{ |
||||
Evas_Object *rect, *bg, *rect2; |
||||
Ecore_Evas *ee; |
||||
Evas *evas; |
||||
Ecore_Animator *anim; |
||||
|
||||
ecore_evas_init(); |
||||
|
||||
ee = ecore_evas_new(NULL, 0, 0, 300, 400, NULL); |
||||
ecore_evas_show(ee); |
||||
evas = ecore_evas_get(ee); |
||||
|
||||
bg = evas_object_rectangle_add(evas); |
||||
evas_object_resize(bg, 300, 400); |
||||
evas_object_show(bg); |
||||
|
||||
rect = evas_object_rectangle_add(evas); |
||||
evas_object_color_set(rect, 0, 0, 255, 255); |
||||
evas_object_resize(rect, 50, 50); |
||||
evas_object_show(rect); |
||||
|
||||
rect2 = evas_object_rectangle_add(evas); |
||||
evas_object_color_set(rect2, 0, 55, 0, 255); |
||||
evas_object_resize(rect2, 50, 50); |
||||
evas_object_show(rect2); |
||||
|
||||
ecore_animator_frametime_set(1. / 50); |
||||
ecore_animator_timeline_add(5, _advance_frame, rect); |
||||
|
||||
anim = ecore_animator_add(_advance_frame3, rect2); |
||||
|
||||
ecore_timer_add(10, _start_second_anim, rect); |
||||
ecore_timer_add(5, _freeze_third_anim, anim); |
||||
ecore_timer_add(10, _thaw_third_anim, anim); |
||||
ecore_main_loop_begin(); |
||||
|
||||
evas_object_del(rect); |
||||
ecore_evas_free(ee); |
||||
ecore_animator_del(anim); |
||||
ecore_evas_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_advance_frame(void *data, double pos) |
||||
{ |
||||
double frame = pos; |
||||
frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_SPRING, 1.2, 15); |
||||
|
||||
evas_object_resize(data, 50 * (1 + frame), 50 * (1 + frame)); |
||||
evas_object_move(data, 100 * frame, 100 * frame); |
||||
evas_object_color_set(data, 255 * frame, 0, 255 * (1 - frame), 255); |
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_start_second_anim(void *data) |
||||
{ |
||||
ecore_animator_frametime_set(1. / 10); |
||||
ecore_animator_timeline_add(20, _advance_frame2, data); |
||||
return EINA_FALSE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_advance_frame2(void *data, double pos) |
||||
{ |
||||
double frame = pos; |
||||
frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_BOUNCE, 1.2, 50); |
||||
|
||||
evas_object_resize(data, 100 - (50 * frame), 100 - (50 * frame)); |
||||
evas_object_move(data, 100 * (1 - frame), 100 * (1 - frame)); |
||||
evas_object_color_set(data, 255 * (1 - frame), 0, 255 * frame, 255); |
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_advance_frame3(void *data) |
||||
{ |
||||
static int x = 0; |
||||
|
||||
if (x >= 250) |
||||
x = 0; |
||||
evas_object_move(data, ++x, 350); |
||||
|
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_freeze_third_anim(void *data) |
||||
{ |
||||
ecore_animator_freeze(data); |
||||
return EINA_FALSE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_thaw_third_anim(void *data) |
||||
{ |
||||
ecore_animator_thaw(data); |
||||
return EINA_FALSE; |
||||
} |
||||
|
@ -0,0 +1,79 @@ |
||||
#include <stdio.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
/* Ecore_Con client example
|
||||
* 2010 Mike Blumenkrantz |
||||
*/ |
||||
|
||||
#define NUM_CLIENTS 30000 |
||||
|
||||
static Eina_Counter *counter; |
||||
static int add = 0; |
||||
static int del = 0; |
||||
|
||||
Eina_Bool |
||||
_add(void *data, int type, Ecore_Con_Event_Server_Add *ev) |
||||
{ |
||||
++add; |
||||
printf("Connection #%i!\n", add); |
||||
if (add == NUM_CLIENTS) |
||||
ecore_main_loop_quit(); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_del(void *data, int type, Ecore_Con_Event_Server_Add *ev) |
||||
{ |
||||
++del; |
||||
printf("Connection lost! #%i!\n", del); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
static void |
||||
_spawn(void *data) |
||||
{ |
||||
int x; |
||||
|
||||
for (x = 0; x < NUM_CLIENTS; x++) |
||||
{ |
||||
// printf("Creating connection %i\n", x);
|
||||
if (!ecore_con_server_connect(ECORE_CON_REMOTE_NODELAY, "127.0.0.1", 8080, NULL)) |
||||
{ |
||||
printf("CRITICAL ERROR!\n" |
||||
"Could not create connection #%i!\n", x); |
||||
exit(1); |
||||
} |
||||
} |
||||
printf("***Job done***\n"); |
||||
} |
||||
|
||||
int |
||||
main(void) |
||||
{ |
||||
double done; |
||||
eina_init(); |
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
|
||||
eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR); |
||||
eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR); |
||||
counter = eina_counter_new("client"); |
||||
eina_counter_start(counter); |
||||
done = ecore_time_get(); |
||||
|
||||
ecore_job_add(_spawn, NULL); |
||||
|
||||
/* set event handler for server connect */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_del, NULL); |
||||
|
||||
/* start client */ |
||||
ecore_main_loop_begin(); |
||||
eina_counter_stop(counter, 1); |
||||
printf("\nTime elapsed for %i connections: %f seconds\n%s", NUM_CLIENTS, ecore_time_get() - done, eina_counter_dump(counter)); |
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,92 @@ |
||||
#include <stdio.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
/* Ecore_Con client example
|
||||
* 2010 Mike Blumenkrantz |
||||
*/ |
||||
|
||||
/* comment if not using gnutls */ |
||||
static void |
||||
tls_log_func(int level, const char *str) |
||||
{ |
||||
fprintf(stderr, "|<%d>| %s", level, str); |
||||
} |
||||
|
||||
Eina_Bool |
||||
_add(void *data, int type, Ecore_Con_Event_Server_Add *ev) |
||||
{ |
||||
printf("Server with ip %s connected!\n", ecore_con_server_ip_get(ev->server)); |
||||
ecore_con_server_send(ev->server, "hello!", 6); |
||||
ecore_con_server_flush(ev->server); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_del(void *data, int type, Ecore_Con_Event_Server_Del *ev) |
||||
{ |
||||
printf("Lost server with ip %s!\n", ecore_con_server_ip_get(ev->server)); |
||||
ecore_main_loop_quit(); |
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_data(void *data, int type, Ecore_Con_Event_Server_Data *ev) |
||||
{ |
||||
char fmt[128]; |
||||
|
||||
snprintf(fmt, sizeof(fmt), |
||||
"Received %i bytes from server:\n" |
||||
">>>>>\n" |
||||
"%%.%is\n" |
||||
">>>>>\n", |
||||
ev->size, ev->size); |
||||
|
||||
printf(fmt, ev->data); |
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
int |
||||
main() |
||||
{ |
||||
Ecore_Con_Server *svr; |
||||
Eina_Iterator *it; |
||||
const char *ca; |
||||
|
||||
eina_init(); |
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
|
||||
/* comment if not using gnutls */ |
||||
gnutls_global_set_log_level(9); |
||||
gnutls_global_set_log_function(tls_log_func); |
||||
|
||||
if (!(it = eina_file_ls("/etc/ssl/certs"))) |
||||
exit(1); |
||||
|
||||
if (!(svr = ecore_con_server_connect(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_MIXED, "www.verisign.com", 443, NULL))) |
||||
exit(1); |
||||
|
||||
/* add all the CAs */ |
||||
EINA_ITERATOR_FOREACH(it, ca) |
||||
{ |
||||
if (!ecore_con_ssl_server_cafile_add(svr, ca)) |
||||
printf("Could not load CA: %s!\n", ca); |
||||
eina_stringshare_del(ca); |
||||
} |
||||
|
||||
eina_iterator_free(it); |
||||
ecore_con_ssl_server_verify(svr); |
||||
|
||||
/* set event handler for server connect */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL); |
||||
/* set event handler for server disconnect */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb)_del, NULL); |
||||
/* set event handler for receiving server data */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb)_data, NULL); |
||||
|
||||
/* start client */ |
||||
ecore_main_loop_begin(); |
||||
} |
||||
|
@ -0,0 +1,126 @@ |
||||
#include <stdio.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
#ifdef HAVE_CONFIG_H |
||||
# include "config.h" |
||||
#else |
||||
# define EINA_UNUSED |
||||
#endif |
||||
|
||||
struct _Server |
||||
{ |
||||
int sdata; |
||||
}; |
||||
|
||||
Eina_Bool |
||||
_add(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Server_Add *ev) |
||||
{ |
||||
char welcome[] = "hello! - sent from the client"; |
||||
struct _Server *server = malloc(sizeof(*server)); |
||||
server->sdata = 0; |
||||
|
||||
ecore_con_server_data_set(ev->server, server); |
||||
printf("Server with ip %s, name %s, port %d, connected = %d!\n", |
||||
ecore_con_server_ip_get(ev->server), |
||||
ecore_con_server_name_get(ev->server), |
||||
ecore_con_server_port_get(ev->server), |
||||
ecore_con_server_connected_get(ev->server)); |
||||
ecore_con_server_send(ev->server, welcome, sizeof(welcome)); |
||||
ecore_con_server_flush(ev->server); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_del(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Server_Del *ev) |
||||
{ |
||||
if (!ev->server) |
||||
{ |
||||
printf("Failed to establish connection to the server.\nExiting.\n"); |
||||
ecore_main_loop_quit(); |
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
struct _Server *server = ecore_con_server_data_get(ev->server); |
||||
|
||||
printf("Lost server with ip %s!\n", ecore_con_server_ip_get(ev->server)); |
||||
|
||||
if (server) |
||||
{ |
||||
printf("Total data received from this server: %d\n", server->sdata); |
||||
free(server); |
||||
} |
||||
|
||||
ecore_con_server_del(ev->server); |
||||
|
||||
ecore_main_loop_quit(); |
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_data(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Server_Data *ev) |
||||
{ |
||||
char fmt[128]; |
||||
struct _Server *server = ecore_con_server_data_get(ev->server); |
||||
|
||||
snprintf(fmt, sizeof(fmt), |
||||
"Received %i bytes from server:\n" |
||||
">>>>>\n" |
||||
"%%.%is\n" |
||||
">>>>>\n", |
||||
ev->size, ev->size); |
||||
|
||||
printf(fmt, ev->data); |
||||
|
||||
server->sdata += ev->size; |
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
int |
||||
main(int argc, const char *argv[]) |
||||
{ |
||||
Ecore_Con_Server *svr; |
||||
const char *address; |
||||
int port = 8080; |
||||
|
||||
if (argc < 2) |
||||
{ |
||||
printf("wrong usage. Command syntax is:\n"); |
||||
printf("\tecore_con_client_simple_example <address> [port]\n"); |
||||
exit(1); |
||||
} |
||||
|
||||
address = argv[1]; |
||||
|
||||
if (argc > 2) |
||||
port = atoi(argv[2]); |
||||
|
||||
eina_init(); |
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
|
||||
if (!(svr = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, address, port, NULL))) |
||||
{ |
||||
printf("could not connect to the server: %s, port %d.\n", |
||||
address, port); |
||||
exit(2); |
||||
} |
||||
|
||||
/* set event handler for server connect */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL); |
||||
/* set event handler for server disconnect */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb)_del, NULL); |
||||
/* set event handler for receiving server data */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb)_data, NULL); |
||||
|
||||
/* start client */ |
||||
ecore_main_loop_begin(); |
||||
|
||||
ecore_con_init(); |
||||
ecore_init(); |
||||
eina_init(); |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,40 @@ |
||||
#include <stdio.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
static void |
||||
_lookup_done_cb(const char *canonname, const char *ip, struct sockaddr *addr, int addrlen, void *data) |
||||
{ |
||||
printf("canonname = %s\n", canonname); |
||||
printf("ip = %s\n", ip); |
||||
printf("addr = %p\n", addr); |
||||
printf("addrlen = %d\n", addrlen); |
||||
} |
||||
|
||||
int |
||||
main(int argc, const char *argv[]) |
||||
{ |
||||
if (argc < 2) |
||||
{ |
||||
printf("need one parameter: <address>\n"); |
||||
return -1; |
||||
} |
||||
|
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
|
||||
if (!ecore_con_lookup(argv[1], _lookup_done_cb, NULL)) |
||||
{ |
||||
printf("error when trying to start lookup for %s\n", argv[1]); |
||||
goto end; |
||||
} |
||||
|
||||
ecore_main_loop_begin(); |
||||
|
||||
end: |
||||
ecore_con_shutdown(); |
||||
ecore_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,81 @@ |
||||
#include <stdio.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
/* Ecore_Con server example
|
||||
* 2010 Mike Blumenkrantz |
||||
*/ |
||||
|
||||
/* comment if not using gnutls */ |
||||
static void |
||||
tls_log_func(int level, const char *str) |
||||
{ |
||||
fprintf(stderr, "|<%d>| %s", level, str); |
||||
} |
||||
|
||||
Eina_Bool |
||||
_add(void *data, int type, Ecore_Con_Event_Client_Add *ev) |
||||
{ |
||||
printf("Client with ip %s connected!\n", ecore_con_client_ip_get(ev->client)); |
||||
ecore_con_client_send(ev->client, "hello!", 6); |
||||
// ecore_con_client_flush(ev->client);
|
||||
ecore_con_client_timeout_set(ev->client, 5); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_del(void *data, int type, Ecore_Con_Event_Client_Del *ev) |
||||
{ |
||||
printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client)); |
||||
ecore_main_loop_quit(); |
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_data(void *data, int type, Ecore_Con_Event_Client_Data *ev) |
||||
{ |
||||
char fmt[128]; |
||||
|
||||
snprintf(fmt, sizeof(fmt), |
||||
"Received %i bytes from client:\n" |
||||
">>>>>\n" |
||||
"%%.%is\n" |
||||
">>>>>\n", |
||||
ev->size, ev->size); |
||||
|
||||
printf(fmt, ev->data); |
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
int |
||||
main() |
||||
{ |
||||
Ecore_Con_Server *svr; |
||||
eina_init(); |
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
|
||||
/* comment if not using gnutls */ |
||||
gnutls_global_set_log_level(9); |
||||
gnutls_global_set_log_function(tls_log_func); |
||||
|
||||
/* to use a PEM certificate with TLS and SSL3, uncomment the lines below */ |
||||
if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_TLS | ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT, "127.0.0.1", 8080, NULL))) |
||||
/* to use simple tcp with ssl/tls, use this line */ |
||||
// if (!ecore_con_server_add(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_SSL3, "127.0.0.1", 8080, NULL))
|
||||
exit(1); |
||||
|
||||
ecore_con_ssl_server_cert_add(svr, "server.pem"); |
||||
ecore_con_ssl_server_privkey_add(svr, "server.pem"); |
||||
/* set event handler for client connect */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL); |
||||
/* set event handler for client disconnect */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL); |
||||
/* set event handler for receiving client data */ |
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb)_data, NULL); |
||||
|
||||
/* start server */ |
||||
ecore_main_loop_begin(); |
||||
} |
||||
|
@ -0,0 +1,136 @@ |
||||
#include <stdio.h> |
||||
#include <sys/time.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
#ifdef HAVE_CONFIG_H |
||||
# include "config.h" |
||||
#else |
||||
# define EINA_UNUSED |
||||
#endif |
||||
|
||||
static const char response_template[] = |
||||
"HTTP/1.0 200 OK\r\n" |
||||
"Server: Ecore_Con custom server\r\n" |
||||
"Content-Length: %zd\r\n" |
||||
"Content-Type: text/html; charset=UTF-8\r\n" |
||||
"Set-Cookie: MYCOOKIE=1; path=/; expires=%s\r\n" |
||||
"Set-Cookie: SESSIONCOOKIE=1; path=/\r\n" |
||||
"\r\n" |
||||
"%s"; |
||||
|
||||
struct _Client |
||||
{ |
||||
int sdata; |
||||
}; |
||||
|
||||
Eina_Bool |
||||
_add(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Add *ev) |
||||
{ |
||||
struct _Client *client = malloc(sizeof(*client)); |
||||
client->sdata = 0; |
||||
static char buf[4096]; |
||||
char welcome[] = "Welcome to Ecore_Con server!"; |
||||
time_t t; |
||||
|
||||
printf("Client with ip %s, port %d, connected = %d!\n", |
||||
ecore_con_client_ip_get(ev->client), |
||||
ecore_con_client_port_get(ev->client), |
||||
ecore_con_client_connected_get(ev->client)); |
||||
|
||||
ecore_con_client_data_set(ev->client, client); |
||||
|
||||
t = time(NULL); |
||||
t += 60 * 60 * 24; |
||||
snprintf(buf, sizeof(buf), response_template, sizeof(welcome) - 1, ctime(&t), welcome); |
||||
|
||||
ecore_con_client_send(ev->client, buf, strlen(buf)); |
||||
ecore_con_client_flush(ev->client); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_del(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Del *ev) |
||||
{ |
||||
struct _Client *client; |
||||
|
||||
if (!ev->client) |
||||
return ECORE_CALLBACK_RENEW; |
||||
|
||||
client = ecore_con_client_data_get(ev->client); |
||||
|
||||
printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client)); |
||||
printf("Total data received from this client: %d\n", client->sdata); |
||||
printf("Client was connected for %0.3f seconds.\n", |
||||
ecore_con_client_uptime_get(ev->client)); |
||||
|
||||
if (client) |
||||
free(client); |
||||
|
||||
ecore_con_client_del(ev->client); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_data(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Data *ev) |
||||
{ |
||||
char fmt[128]; |
||||
struct _Client *client = ecore_con_client_data_get(ev->client); |
||||
|
||||
snprintf(fmt, sizeof(fmt), |
||||
"\nReceived %i bytes from client %s port %d:\n" |
||||
">>>>>\n" |
||||
"%%.%is\n" |
||||
">>>>>\n\n", |
||||
ev->size, ecore_con_client_ip_get(ev->client), |
||||
ecore_con_client_port_get(ev->client), ev->size); |
||||
|
||||
printf(fmt, ev->data); |
||||
|
||||
client->sdata += ev->size; |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
int |
||||
main(void) |
||||
{ |
||||
Ecore_Con_Server *svr; |
||||
Ecore_Con_Client *cl; |
||||
const Eina_List *clients, *l; |
||||
|
||||
eina_init(); |
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
|
||||
if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "127.0.0.1", 8080, NULL))) |
||||
exit(1); |
||||
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb)_data, NULL); |
||||
ecore_con_server_client_limit_set(svr, 3, 0); |
||||
|
||||
ecore_main_loop_begin(); |
||||
|
||||
clients = ecore_con_server_clients_get(svr); |
||||
printf("Clients still connected to this server when exiting: %d\n", |
||||
eina_list_count(clients)); |
||||
EINA_LIST_FOREACH(clients, l, cl) |
||||
{ |
||||
printf("%s\n", ecore_con_client_ip_get(cl)); |
||||
free(ecore_con_client_data_get(cl)); |
||||
} |
||||
|
||||
printf("Server was up for %0.3f seconds\n", |
||||
ecore_con_server_uptime_get(svr)); |
||||
|
||||
ecore_con_shutdown(); |
||||
ecore_shutdown(); |
||||
eina_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,133 @@ |
||||
#include <stdio.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
#ifdef HAVE_CONFIG_H |
||||
# include "config.h" |
||||
#else |
||||
# define EINA_UNUSED |
||||
#endif |
||||
|
||||
struct _Client |
||||
{ |
||||
int sdata; |
||||
}; |
||||
|
||||
Eina_Bool |
||||
_add(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Add *ev) |
||||
{ |
||||
char welcome[] = "hello! - sent from the server"; |
||||
Ecore_Con_Server *srv; |
||||
Ecore_Con_Client *cl; |
||||
const Eina_List *clients, *l; |
||||
|
||||
struct _Client *client = malloc(sizeof(*client)); |
||||
client->sdata = 0; |
||||
|
||||
printf("Client with ip %s, port %d, connected = %d!\n", |
||||
ecore_con_client_ip_get(ev->client), |
||||
ecore_con_client_port_get(ev->client), |
||||
ecore_con_client_connected_get(ev->client)); |
||||
|
||||
ecore_con_client_send(ev->client, welcome, sizeof(welcome)); |
||||
ecore_con_client_flush(ev->client); |
||||
|
||||
ecore_con_client_timeout_set(ev->client, 6); |
||||
|
||||
ecore_con_client_data_set(ev->client, client); |
||||
|
||||
srv = ecore_con_client_server_get(ev->client); |
||||
printf("Clients connected to this server:\n"); |
||||
clients = ecore_con_server_clients_get(srv); |
||||
EINA_LIST_FOREACH(clients, l, cl) |
||||
printf("%s\n", ecore_con_client_ip_get(cl)); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_del(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Del *ev) |
||||
{ |
||||
struct _Client *client; |
||||
|
||||
if (!ev->client) |
||||
return ECORE_CALLBACK_RENEW; |
||||
|
||||
client = ecore_con_client_data_get(ev->client); |
||||
|
||||
printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client)); |
||||
printf("Total data received from this client: %d\n", client->sdata); |
||||
printf("Client was connected for %0.3f seconds.\n", |
||||
ecore_con_client_uptime_get(ev->client)); |
||||
|
||||
if (client) |
||||
free(client); |
||||
|
||||
ecore_con_client_del(ev->client); |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
Eina_Bool |
||||
_data(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Data *ev) |
||||
{ |
||||
char fmt[128]; |
||||
struct _Client *client = ecore_con_client_data_get(ev->client); |
||||
|
||||
snprintf(fmt, sizeof(fmt), |
||||
"Received %i bytes from client %s port %d:\n" |
||||
">>>>>\n" |
||||
"%%.%is\n" |
||||
">>>>>\n", |
||||
ev->size, ecore_con_client_ip_get(ev->client), |
||||
ecore_con_client_port_get(ev->client), ev->size); |
||||
|
||||
printf(fmt, ev->data); |
||||
|
||||
client->sdata += ev->size; |
||||
|
||||
return ECORE_CALLBACK_RENEW; |
||||
} |
||||
|
||||
int |
||||
main(void) |
||||
{ |
||||
Ecore_Con_Server *svr; |
||||
Ecore_Con_Client *cl; |
||||
const Eina_List *clients, *l; |
||||
|
||||
eina_init(); |
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
|
||||
if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "127.0.0.1", 8080, NULL))) |
||||
exit(1); |
||||
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb)_data, NULL); |
||||
|
||||
ecore_con_server_timeout_set(svr, 10); |
||||
ecore_con_server_client_limit_set(svr, 3, 0); |
||||
|
||||
ecore_main_loop_begin(); |
||||
|
||||
clients = ecore_con_server_clients_get(svr); |
||||
printf("Clients connected to this server when exiting: %d\n", |
||||
eina_list_count(clients)); |
||||
EINA_LIST_FOREACH(clients, l, cl) |
||||
{ |
||||
printf("%s\n", ecore_con_client_ip_get(cl)); |
||||
free(ecore_con_client_data_get(cl)); |
||||
} |
||||
|
||||
printf("Server was up for %0.3f seconds\n", |
||||
ecore_con_server_uptime_get(svr)); |
||||
|
||||
ecore_con_shutdown(); |
||||
ecore_shutdown(); |
||||
eina_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,123 @@ |
||||
#include <stdio.h> |
||||
#include <Eina.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
#ifdef HAVE_CONFIG_H |
||||
# include "config.h" |
||||
#else |
||||
# define EINA_UNUSED |
||||
#endif |
||||
|
||||
#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); |
||||
|
||||
ecore_con_url_cookies_jar_write(url_complete->url_con); |
||||
|
||||
ecore_main_loop_quit(); |
||||
|
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
int |
||||
main(int argc, const char *argv[]) |
||||
{ |
||||
Ecore_Con_Url *ec_url = NULL; |
||||
char cmd = '\0'; |
||||
Eina_Bool r; |
||||
|
||||
if (argc < 2) |
||||
{ |
||||
printf("need at least one parameter: <url> [command]\n"); |
||||
return -1; |
||||
} |
||||
|
||||
if (argc > 2) |
||||
cmd = argv[2][0]; |
||||
|
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
ecore_con_url_init(); |
||||
|
||||
ec_url = ecore_con_url_new(argv[1]); |
||||
if (!ec_url) |
||||
{ |
||||
printf("error when creating ecore con url object.\n"); |
||||
goto end; |
||||
} |
||||
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL); |
||||
|
||||
ecore_con_url_additional_header_add(ec_url, "User-Agent", "Ecore_Con client"); |
||||
|
||||
ecore_con_url_cookies_init(ec_url); |
||||
if (cmd != 'c' && cmd != 's') |
||||
ecore_con_url_cookies_file_add(ec_url, COOKIEJAR); |
||||
ecore_con_url_cookies_jar_file_set(ec_url, COOKIEJAR); |
||||
|
||||
switch (cmd) |
||||
{ |
||||
case 'c': // clear
|
||||
printf("Cleaning previously set cookies.\n"); |
||||
ecore_con_url_cookies_clear(ec_url); |
||||
break; |
||||
|
||||
case 's': // clear session
|
||||
printf("Cleaning previously set session cookies.\n"); |
||||
ecore_con_url_cookies_session_clear(ec_url); |
||||
break; |
||||
|
||||
case 'i': // ignore session
|
||||
printf("Ignoring old session cookies.\n"); |
||||
ecore_con_url_cookies_ignore_old_session_set(ec_url, EINA_TRUE); |
||||
} |
||||
|
||||
r = ecore_con_url_get(ec_url); |
||||
if (!r) |
||||
{ |
||||
printf("could not realize request.\n"); |
||||
goto free_ec_url; |
||||
} |
||||
|
||||
ecore_main_loop_begin(); |
||||
|
||||
free_ec_url: |
||||
ecore_con_url_free(ec_url); |
||||
end: |
||||
ecore_con_url_shutdown(); |
||||
ecore_con_shutdown(); |
||||
ecore_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,115 @@ |
||||
#include <stdio.h> |
||||
#include <sys/types.h> |
||||
#include <sys/stat.h> |
||||
#include <fcntl.h> |
||||
#include <unistd.h> |
||||
|
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
struct _request |
||||
{ |
||||
long size; |
||||
}; |
||||
|
||||
static Eina_Bool |
||||
_url_progress_cb(void *data, int type, void *event_info) |
||||
{ |
||||
Ecore_Con_Event_Url_Progress *url_progress = event_info; |
||||
float percent; |
||||
|
||||
if (url_progress->down.total > 0) |
||||
{ |
||||
struct _request *req = ecore_con_url_data_get(url_progress->url_con); |
||||
req->size = url_progress->down.now; |
||||
|
||||
percent = (url_progress->down.now / url_progress->down.total) * 100; |
||||
printf("Total of download complete: %0.1f (%0.0f)%%\n", |
||||
percent, url_progress->down.now); |
||||
} |
||||
|
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_url_complete_cb(void *data, int type, void *event_info) |
||||
{ |
||||
Ecore_Con_Event_Url_Complete *url_complete = event_info; |
||||
|
||||
struct _request *req = ecore_con_url_data_get(url_complete->url_con); |
||||
int nbytes = ecore_con_url_received_bytes_get(url_complete->url_con); |
||||
|
||||
printf("\n"); |
||||
printf("download completed with status code: %d\n", url_complete->status); |
||||
printf("Total size of downloaded file: %ld bytes\n", req->size); |
||||
printf("Total size of downloaded file: %d bytes " |
||||
"(from received_bytes_get)\n", nbytes); |
||||
ecore_main_loop_quit(); |
||||
|
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
int |
||||
main(int argc, const char *argv[]) |
||||
{ |
||||
Ecore_Con_Url *ec_url = NULL; |
||||
struct _request *req; |
||||
int fd; |
||||
const char *filename = "downloadedfile.dat"; |
||||
|
||||
if (argc < 2) |
||||
{ |
||||
printf("need one parameter: <url>\n"); |
||||
return -1; |
||||
} |
||||
|
||||
fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644); |
||||
|
||||
if (fd == -1) |
||||
{ |
||||
printf("error: could not open file for writing: \"%s\"\n", |
||||
filename); |
||||
return -1; |
||||
} |
||||
|
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
ecore_con_url_init(); |
||||
|
||||
ec_url = ecore_con_url_new(argv[1]); |
||||
if (!ec_url) |
||||
{ |
||||
printf("error when creating ecore con url object.\n"); |
||||
goto end; |
||||
} |
||||
|
||||
req = malloc(sizeof(*req)); |
||||
req->size = 0; |
||||
ecore_con_url_data_set(ec_url, req); |
||||
|
||||
ecore_con_url_fd_set(ec_url, fd); |
||||
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_PROGRESS, _url_progress_cb, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL); |
||||
|
||||
if (!ecore_con_url_get(ec_url)) |
||||
{ |
||||
printf("could not realize request.\n"); |
||||
goto free_ec_url; |
||||
} |
||||
|
||||
ecore_main_loop_begin(); |
||||
|
||||
free_ec_url: |
||||
free(req); |
||||
ecore_con_url_free(ec_url); |
||||
end: |
||||
|
||||
close(fd); |
||||
ecore_con_url_shutdown(); |
||||
ecore_con_shutdown(); |
||||
ecore_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,106 @@ |
||||
#include <stdio.h> |
||||
#include <Eina.h> |
||||
#include <Ecore.h> |
||||
#include <Ecore_Con.h> |
||||
|
||||
static Eina_Bool |
||||
_url_data_cb(void *data, int type, void *event_info) |
||||
{ |
||||
Ecore_Con_Event_Url_Data *url_data = event_info; |
||||
int i; |
||||
|
||||
for (i = 0; i < url_data->size; i++) |
||||
printf("%c", url_data->data[i]); |
||||
|
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
static Eina_Bool |
||||
_url_complete_cb(void *data, int type, 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); |
||||
|
||||
EINA_LIST_FOREACH(headers, l, str) |
||||
printf("header: %s\n", str); |
||||
|
||||
ecore_main_loop_quit(); |
||||
|
||||
return EINA_TRUE; |
||||
} |
||||
|
||||
int |
||||
main(int argc, const char *argv[]) |
||||
{ |
||||
Ecore_Con_Url *ec_url = NULL; |
||||
const char *type; |
||||
Eina_Bool r; |
||||
|
||||
if (argc < 3) |
||||
{ |
||||
printf("need at least two parameters: < POST|GET > <url1>\n"); |
||||
return -1; |
||||
} |
||||
|
||||
type = argv[1]; |
||||
|
||||
if (strcmp(type, "POST") && (strcmp(type, "GET"))) |
||||
{ |
||||
printf("only POST or GET are supported by this example.\n"); |
||||
return -1; |
||||
} |
||||
|
||||
ecore_init(); |
||||
ecore_con_init(); |
||||
ecore_con_url_init(); |
||||
|
||||
// check if requests are being pipelined, and set them if not:
|
||||
if (!ecore_con_url_pipeline_get()) |
||||
ecore_con_url_pipeline_set(EINA_TRUE); |
||||
|
||||
ec_url = ecore_con_url_custom_new(argv[2], type); |
||||
if (!ec_url) |
||||
{ |
||||
printf("error when creating ecore con url object.\n"); |
||||
goto end; |
||||
} |
||||
|
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL); |
||||
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL); |
||||
|
||||
ecore_con_url_additional_header_add(ec_url, "User-Agent", "blablabla"); |
||||
ecore_con_url_verbose_set(ec_url, EINA_TRUE); |
||||
|
||||
ecore_con_url_httpauth_set(ec_url, "user", "password", EINA_FALSE); |
||||
|
||||
ecore_con_url_time(ec_url, ECORE_CON_URL_TIME_IFMODSINCE, 0); |
||||
|
||||
if (!strcmp(type, "GET")) |
||||
r = ecore_con_url_get(ec_url); |
||||
else |
||||
r = ecore_con_url_post(ec_url, NULL, 0, NULL); |
||||
|
||||
if (!r) |
||||
{ |
||||
printf("could not realize request.\n"); |
||||
goto free_ec_url; |
||||
} |
||||
|
||||
ecore_main_loop_begin(); |
||||
|
||||
free_ec_url: |
||||
ecore_con_url_free(ec_url); |
||||
end: |
||||
ecore_con_url_shutdown(); |
||||
ecore_con_shutdown(); |
||||
ecore_shutdown(); |
||||
|
||||
return 0; |
||||
} |
||||
|
@ -0,0 +1,89 @@ |
||||
/**
|
||||
* Ecore example illustrating the basics of ecore evas usage. |
||||
* |
||||
* You'll need at least one Evas engine built for it (excluding the |
||||
* buffer one). See stdout/stderr for output. |
||||
* |
||||
* @verbatim |
||||