summaryrefslogtreecommitdiff
path: root/src/modules/mega/mega_event.c
blob: b55f658c1622870a813b9e7d1e843b1602eae598 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "mega.h"

Eina_Bool
mega_event_data(void *data, int type, void *event_info)
{
   Mega *mega;
   Mega_Action *ma;
   Ecore_Con_Event_Url_Data *url_data = event_info;
   unsigned int i;

   mega = ecore_con_url_data_get(url_data->url_con);
   if (mega != data)
     return EINA_TRUE;

   ma = mega->action;

   switch (ma->type)
     {
      case MEGA_LOGIN:
        {
           printf("Received %i bytes\n", url_data->size);
           eina_strbuf_append_length(ma->u.al.buf,
                                     url_data->data, url_data->size);
           break;
        }
      default:
        break;
     }
   return EINA_TRUE;
}

Eina_Bool
mega_event_complete(void *data, int type, void *event_info)
{
   Mega *mega;
   Mega_Action *ma;
   Ecore_Con_Event_Url_Complete *url_complete = event_info;

   printf("download completed with status code: %d\n", url_complete->status);

   mega = ecore_con_url_data_get(url_complete->url_con);
   if (mega != data)
     return EINA_TRUE;

   ma = mega->action;

   switch (ma->type)
     {
      case MEGA_LOGIN:
        {
           char *buf;
           size_t buf_len;
           cJSON *json;

           buf_len = eina_strbuf_length_get(ma->u.al.buf);
           buf = eina_strbuf_string_steal(ma->u.al.buf);
           buf[buf_len-1] = 0;

           json = cJSON_Parse(buf+1);
           printf("JSON = \n%s\n", cJSON_Print(json));


           eina_strbuf_free(ma->u.al.buf);
           free(ma);
           break;
        }
      default:
        break;
     }

   return EINA_TRUE;
}