summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/modules/mega/mega.h34
-rw-r--r--src/modules/mega/mega_event.c55
-rw-r--r--src/modules/mega/mega_login.c8
3 files changed, 91 insertions, 6 deletions
diff --git a/src/modules/mega/mega.h b/src/modules/mega/mega.h
index 2a9967d..e7f4f80 100644
--- a/src/modules/mega/mega.h
+++ b/src/modules/mega/mega.h
@@ -3,11 +3,16 @@
3#include <cencode.h> 3#include <cencode.h>
4#include <cJSON.h> 4#include <cJSON.h>
5 5
6typedef enum _Mega_Action_Type
7{
8 MEGA_LOGIN
9} Mega_Action_Type;
6 10
7typedef struct _Mega 11typedef struct _Mega
8{ 12{
9 Skypunch *skypunch; 13 Skypunch *skypunch;
10 Ecore_Con_Url *ecu; 14 Ecore_Con_Url *ecu;
15 void *action;
11 16
12 struct 17 struct
13 { 18 {
@@ -17,8 +22,10 @@ typedef struct _Mega
17 22
18 struct 23 struct
19 { 24 {
20 char password[16]; 25 char password[16],
21 unsigned int id; 26 *id,
27 *private_key,
28 *master_key;
22 } session; 29 } session;
23 30
24 struct 31 struct
@@ -28,6 +35,29 @@ typedef struct _Mega
28 } ev; 35 } ev;
29} Mega; 36} Mega;
30 37
38typedef struct _Mega_Action_Login
39{
40 Eina_Strbuf *buf;
41} Mega_Action_Login;
42
43typedef struct _Mega_Action
44{
45 Mega_Action_Type type;
46
47 Mega *mega;
48 void *data;
49
50 union
51 {
52 Mega_Action_Login al;
53 } u;
54
55 struct
56 {
57
58 } cb;
59} Mega_Action;
60
31Eina_Bool mega_event_data(void *data, int type, void *event_info); 61Eina_Bool mega_event_data(void *data, int type, void *event_info);
32Eina_Bool mega_event_complete(void *data, int type, void *event_info); 62Eina_Bool mega_event_complete(void *data, int type, void *event_info);
33 63
diff --git a/src/modules/mega/mega_event.c b/src/modules/mega/mega_event.c
index e87b816..b55f658 100644
--- a/src/modules/mega/mega_event.c
+++ b/src/modules/mega/mega_event.c
@@ -3,23 +3,70 @@
3Eina_Bool 3Eina_Bool
4mega_event_data(void *data, int type, void *event_info) 4mega_event_data(void *data, int type, void *event_info)
5{ 5{
6 Mega *mega;
7 Mega_Action *ma;
6 Ecore_Con_Event_Url_Data *url_data = event_info; 8 Ecore_Con_Event_Url_Data *url_data = event_info;
7 unsigned int i; 9 unsigned int i;
8 10
9 printf("Received %i bytes\n", url_data->size); 11 mega = ecore_con_url_data_get(url_data->url_con);
10 for (i = 0; i < url_data->size; i++) 12 if (mega != data)
11 printf("%c", url_data->data[i]); 13 return EINA_TRUE;
12 printf("\n");
13 14
15 ma = mega->action;
16
17 switch (ma->type)
18 {
19 case MEGA_LOGIN:
20 {
21 printf("Received %i bytes\n", url_data->size);
22 eina_strbuf_append_length(ma->u.al.buf,
23 url_data->data, url_data->size);
24 break;
25 }
26 default:
27 break;
28 }
14 return EINA_TRUE; 29 return EINA_TRUE;
15} 30}
16 31
17Eina_Bool 32Eina_Bool
18mega_event_complete(void *data, int type, void *event_info) 33mega_event_complete(void *data, int type, void *event_info)
19{ 34{
35 Mega *mega;
36 Mega_Action *ma;
20 Ecore_Con_Event_Url_Complete *url_complete = event_info; 37 Ecore_Con_Event_Url_Complete *url_complete = event_info;
21 38
22 printf("download completed with status code: %d\n", url_complete->status); 39 printf("download completed with status code: %d\n", url_complete->status);
23 40
41 mega = ecore_con_url_data_get(url_complete->url_con);
42 if (mega != data)
43 return EINA_TRUE;
44
45 ma = mega->action;
46
47 switch (ma->type)
48 {
49 case MEGA_LOGIN:
50 {
51 char *buf;
52 size_t buf_len;
53 cJSON *json;
54
55 buf_len = eina_strbuf_length_get(ma->u.al.buf);
56 buf = eina_strbuf_string_steal(ma->u.al.buf);
57 buf[buf_len-1] = 0;
58
59 json = cJSON_Parse(buf+1);
60 printf("JSON = \n%s\n", cJSON_Print(json));
61
62
63 eina_strbuf_free(ma->u.al.buf);
64 free(ma);
65 break;
66 }
67 default:
68 break;
69 }
70
24 return EINA_TRUE; 71 return EINA_TRUE;
25} 72}
diff --git a/src/modules/mega/mega_login.c b/src/modules/mega/mega_login.c
index 1628b50..7cce9aa 100644
--- a/src/modules/mega/mega_login.c
+++ b/src/modules/mega/mega_login.c
@@ -6,6 +6,7 @@
6Eina_Bool 6Eina_Bool
7mega_login_send(Mega *mega, const char *json) 7mega_login_send(Mega *mega, const char *json)
8{ 8{
9 Mega_Action *ma;
9 char *data; 10 char *data;
10 size_t len; 11 size_t len;
11 12
@@ -17,6 +18,13 @@ mega_login_send(Mega *mega, const char *json)
17 18
18 printf("sending %s\n", data); 19 printf("sending %s\n", data);
19 20
21 ma = calloc(1, sizeof(Mega_Action));
22 ma->type = MEGA_LOGIN;
23 ma->mega = mega;
24 ma->u.al.buf = eina_strbuf_new();
25
26 mega->action = ma;
27
20 mega->ecu = ecore_con_url_new(URL"cs?id=fxbkjndgmz&ak="APIKEY); 28 mega->ecu = ecore_con_url_new(URL"cs?id=fxbkjndgmz&ak="APIKEY);
21 ecore_con_url_data_set(mega->ecu, mega); 29 ecore_con_url_data_set(mega->ecu, mega);
22 ecore_con_url_post(mega->ecu, data, len+2, NULL); 30 ecore_con_url_post(mega->ecu, data, len+2, NULL);