summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-17 15:13:53 -0300
committerGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-17 15:13:53 -0300
commit9b93f36e323682a553848b197b24bbf13374bd5f (patch)
treeb195355015a78f9d352a2aba0d3d99683b813770
parentce324a5891d83167ee32bce0274b72b780c0da8c (diff)
soap_model: custom url/action.
-rw-r--r--src/lib/soap_model.c26
-rw-r--r--src/lib/soap_model.eo6
-rw-r--r--src/lib/soap_model_private.h2
-rw-r--r--src/tests/soap_model_test_soap_model.c3
4 files changed, 31 insertions, 6 deletions
diff --git a/src/lib/soap_model.c b/src/lib/soap_model.c
index 755dd32..e2f760a 100644
--- a/src/lib/soap_model.c
+++ b/src/lib/soap_model.c
@@ -18,6 +18,7 @@ typedef struct _Soap_Model_Perform_Data
18 Soap_Model_Data *pd; 18 Soap_Model_Data *pd;
19 Eina_Strbuf *response; 19 Eina_Strbuf *response;
20 struct curl_slist *header; 20 struct curl_slist *header;
21 char *soap_action;
21 CURL *curl; 22 CURL *curl;
22 Ecore_Thread *thread; 23 Ecore_Thread *thread;
23} Soap_Model_Perform_Data; 24} Soap_Model_Perform_Data;
@@ -122,9 +123,16 @@ _soap_model_eo_base_constructor(Eo *obj, Soap_Model_Data *pd)
122 123
123static void 124static void
124_soap_model_constructor(Eo *obj EINA_UNUSED, 125_soap_model_constructor(Eo *obj EINA_UNUSED,
125 Soap_Model_Data *pd EINA_UNUSED) 126 Soap_Model_Data *pd EINA_UNUSED,
127 const char *url,
128 const char *action)
126{ 129{
127 DBG("(%p)", obj); 130 DBG("(%p)", obj);
131 EINA_SAFETY_ON_NULL_RETURN(url);
132 EINA_SAFETY_ON_NULL_RETURN(action);
133
134 pd->url = strdup(url);
135 pd->action = strdup(action);
128} 136}
129 137
130static void 138static void
@@ -133,6 +141,8 @@ _soap_model_eo_base_destructor(Eo *obj, Soap_Model_Data *pd)
133 DBG("(%p)", obj); 141 DBG("(%p)", obj);
134 142
135 _soap_model_clear(pd); 143 _soap_model_clear(pd);
144 free(pd->url);
145 free(pd->action);
136 146
137 eo_do_super(obj, MY_CLASS, eo_destructor()); 147 eo_do_super(obj, MY_CLASS, eo_destructor());
138} 148}
@@ -367,15 +377,20 @@ _soap_model_perform(Soap_Model_Data *pd, const char *xml)
367 data->pd = pd; 377 data->pd = pd;
368 data->response = eina_strbuf_new(); 378 data->response = eina_strbuf_new();
369 379
380 const char *SOAP_ACTION = "SOAPAction:";
381 const size_t soap_action_lenght = strlen(SOAP_ACTION) + strlen(pd->action) + 1;
382 data->soap_action = malloc(soap_action_lenght);
383 snprintf(data->soap_action, soap_action_lenght, "%s%s", SOAP_ACTION, pd->action);
384
370 data->header = curl_slist_append(data->header, "Content-Type:application/soap+xml"); 385 data->header = curl_slist_append(data->header, "Content-Type:application/soap+xml");
371 data->header = curl_slist_append(data->header, "SOAPAction:http://ws.apache.org/axis2/c/samples/echoString"); 386 data->header = curl_slist_append(data->header, data->soap_action);
372 data->header = curl_slist_append(data->header, "Transfer-Encoding: chunked"); 387 data->header = curl_slist_append(data->header, "Transfer-Encoding: chunked");
373 data->header = curl_slist_append(data->header, "Expect:"); 388 data->header = curl_slist_append(data->header, "Expect:");
374 389
375 data->curl = curl_easy_init(); 390 data->curl = curl_easy_init();
376 EINA_SAFETY_ON_NULL_RETURN(data->curl); 391 EINA_SAFETY_ON_NULL_RETURN(data->curl);
377 392
378 curl_easy_setopt(data->curl, CURLOPT_URL, "http://127.0.0.1:9090/axis2/services/echo"); 393 curl_easy_setopt(data->curl, CURLOPT_URL, pd->url);
379 curl_easy_setopt(data->curl, CURLOPT_POST, 1L); 394 curl_easy_setopt(data->curl, CURLOPT_POST, 1L);
380 curl_easy_setopt(data->curl, CURLOPT_WRITEFUNCTION, _soap_model_write_data_cb); 395 curl_easy_setopt(data->curl, CURLOPT_WRITEFUNCTION, _soap_model_write_data_cb);
381 curl_easy_setopt(data->curl, CURLOPT_WRITEDATA, data->response); 396 curl_easy_setopt(data->curl, CURLOPT_WRITEDATA, data->response);
@@ -398,7 +413,6 @@ _soap_model_perform_cb(Soap_Model_Perform_Data *data, Ecore_Thread *thread)
398 { 413 {
399 ERR("Could not perform: %d", res); 414 ERR("Could not perform: %d", res);
400 ecore_thread_cancel(thread); 415 ecore_thread_cancel(thread);
401 return;
402 } 416 }
403} 417}
404 418
@@ -409,7 +423,7 @@ _soap_model_perform_end_cb(Soap_Model_Perform_Data *data,
409 DBG("(%p)", data->pd->obj); 423 DBG("(%p)", data->pd->obj);
410 const char *response = eina_strbuf_string_get(data->response); 424 const char *response = eina_strbuf_string_get(data->response);
411 425
412 DBG("(%p) response: ", data->pd->obj, response); 426 DBG("(%p) response: %s", data->pd->obj, response);
413 427
414 Eo *child = eo_add(EFLAT_XML_MODEL_CLASS, NULL, 428 Eo *child = eo_add(EFLAT_XML_MODEL_CLASS, NULL,
415 eflat_xml_model_constructor(response)); 429 eflat_xml_model_constructor(response));
@@ -440,6 +454,8 @@ _soap_model_perform_data_free(Soap_Model_Perform_Data *data)
440 DBG("(%p)", data->pd->obj); 454 DBG("(%p)", data->pd->obj);
441 curl_easy_cleanup(data->curl); 455 curl_easy_cleanup(data->curl);
442 eina_strbuf_free(data->response); 456 eina_strbuf_free(data->response);
457 curl_slist_free_all(data->header);
458 free(data->soap_action);
443 free(data); 459 free(data);
444} 460}
445 461
diff --git a/src/lib/soap_model.eo b/src/lib/soap_model.eo
index 37105d4..57aef24 100644
--- a/src/lib/soap_model.eo
+++ b/src/lib/soap_model.eo
@@ -6,7 +6,13 @@ class Soap.Model (Eo.Base, Emodel) {
6 Custom Soap_Model constructor. 6 Custom Soap_Model constructor.
7 @def soap_model_constructor 7 @def soap_model_constructor
8 @since 1.13 8 @since 1.13
9 @in url
10 @in action
9 */ 11 */
12 params {
13 @in const(char)* url; /*@ The webservice URL */
14 @in const(char)* action; /*@ The soap action */
15 }
10 } 16 }
11 } 17 }
12 implements { 18 implements {
diff --git a/src/lib/soap_model_private.h b/src/lib/soap_model_private.h
index db25bfd..1087213 100644
--- a/src/lib/soap_model_private.h
+++ b/src/lib/soap_model_private.h
@@ -30,6 +30,8 @@ struct _Soap_Model_Data
30 Emodel_Load load; 30 Emodel_Load load;
31 Eina_List *children_list; 31 Eina_List *children_list;
32 EFlat_Xml_Model *xml; 32 EFlat_Xml_Model *xml;
33 char *url;
34 char *action;
33}; 35};
34 36
35#endif 37#endif
diff --git a/src/tests/soap_model_test_soap_model.c b/src/tests/soap_model_test_soap_model.c
index 9a4b306..40dfc03 100644
--- a/src/tests/soap_model_test_soap_model.c
+++ b/src/tests/soap_model_test_soap_model.c
@@ -163,7 +163,8 @@ static Soap_Model *
163_create_soap_model() 163_create_soap_model()
164{ 164{
165 Emodel *soap = eo_add(SOAP_MODEL_CLASS, NULL, 165 Emodel *soap = eo_add(SOAP_MODEL_CLASS, NULL,
166 soap_model_constructor()); 166 soap_model_constructor("http://127.0.0.1:9090/axis2/services/echo",
167 "http://ws.apache.org/axis2/c/samples/echoString"));
167 ck_assert_ptr_ne(NULL, soap); 168 ck_assert_ptr_ne(NULL, soap);
168 return soap; 169 return soap;
169} 170}