-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wed, 13 Feb 2008 15:43:13 +0100
"Cedric BAIL" <[EMAIL PROTECTED]> wrote:
> You should use fwrite and use the size of the received data instead of
> calling fputs. You can't be sure that the terminate '\0' is in this
> data packet and with binary data you must assume that fputs will
> truncate the data on the first '\0'.
>
> --
> Cedric BAIL
Here's my working code, very thank to Cedric for the tip.
As said in IRC, if my code sounds good, feel free to put in
test/orig/ecore/examples, if you like, it could be useful for others :)
Massimiliano
- --
Massimiliano Calamelli
http://mcalamelli.netsons.org
[EMAIL PROTECTED]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.4 (MingW32)
iD8DBQFHsxTVleGEL56NNP4RAg9nAKDFTo6+vHWNczM1afAXM2BYbXV8NACfZ+VR
EfqxBqApjxDZbSgjZVu0sqQ=
=WRAL
-----END PGP SIGNATURE-----
/* Compile: gcc -o ecore_con_wget ecore_con_wget.c `pkg-config --libs --cflags ecore-con` */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Ecore.h>
#include <Ecore_Con.h>
char *urldata;
char *source;
const char *dest;
FILE *fh;
static int _url_complete (void *data, int type, void *event);
static int _url_data (void *data, int type, void *event);
static int
_url_complete (void *data, int ev_type, void *ev)
{
Ecore_Con_Event_Url_Complete *euc;
euc = (Ecore_Con_Event_Url_Complete *)ev;
printf("URL COMPLETE with status: %d\n", euc->status);
fclose(fh);
ecore_main_loop_quit();
return 0;
}
static int
_url_data (void *data, int ev_type, void *ev)
{
Ecore_Con_Event_Url_Data *eud;
static int cntr = 0;
static int fsize = 0;
eud = (Ecore_Con_Event_Url_Data *)ev;
fsize = fsize + eud->size;
printf("### URL DATA received, CHUNK %d (%d), currsize %d ###\n", cntr++, eud->size, fsize);
fwrite(eud->data, sizeof(unsigned char),eud->size, fh);
return 0;
}
int
main (int argc, char **argv)
{
Ecore_Con_Url *ecu;
char *source;
char *dest;
if (argc < 3)
{
printf("Usage:\n");
printf("ecore_con_wget <url> <dest>\n");
return 1;
}
source = argv[1];
dest = argv[2];
if (!ecore_con_url_init())
{
printf("ERROR: cannot init ecore_con_url\n");
return 1;
}
ecu = ecore_con_url_new(source);
if(!ecu)
{
printf("ecore_con_url_new ERROR.\n");
return 1;
}
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data, NULL);
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete, NULL);
fh = fopen(dest, "ab+");
ecore_con_url_send(ecu, NULL, 0, NULL);
ecore_main_loop_begin();
ecore_con_url_destroy(ecu);
ecore_con_url_shutdown();
return 0;
}
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel