[sr-dev] git:master:ad93a206: curl Actually send POST data

Olle E. Johansson oej at edvina.net
Wed Oct 21 10:39:22 CEST 2015


Module: kamailio
Branch: master
Commit: ad93a2064861d8a8c56cf28d1c42b8250b0b9f05
URL: https://github.com/kamailio/kamailio/commit/ad93a2064861d8a8c56cf28d1c42b8250b0b9f05

Author: Olle E. Johansson <oej at edvina.net>
Committer: Olle E. Johansson <oej at edvina.net>
Date: 2015-10-21T10:39:13+02:00

curl Actually send POST data

---

Modified: modules/curl/functions.c

---

Diff:  https://github.com/kamailio/kamailio/commit/ad93a2064861d8a8c56cf28d1c42b8250b0b9f05.diff
Patch: https://github.com/kamailio/kamailio/commit/ad93a2064861d8a8c56cf28d1c42b8250b0b9f05.patch

---

diff --git a/modules/curl/functions.c b/modules/curl/functions.c
index 31034fe..7ad96dd 100644
--- a/modules/curl/functions.c
+++ b/modules/curl/functions.c
@@ -131,6 +131,8 @@ static int curL_query_url(struct sip_msg* _m, char* _url, char* _dst, const char
 	headerlist = curl_slist_append(headerlist, ctype);
 	res |= curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
 
+	/* Tell CURL we want to upload using POST */
+
  	res |= curl_easy_setopt(curl, CURLOPT_POSTFIELDS, _post);
 	
     }
@@ -246,8 +248,10 @@ int curl_con_query_url(struct sip_msg* _m, char *connection, char* _url, char* _
 	char connurlbuf[BUFSIZ/2];
 	char urlbuf[512];
 	unsigned int len = 0;
-	str postdata;
+	str postdatabuf;
+	char *postdata = NULL;
 	long maxdatasize = default_maxdatasize;
+	int res;
 
 	memset(usernamebuf,0,sizeof(usernamebuf));
 	memset(passwordbuf,0,sizeof(passwordbuf));
@@ -277,20 +281,28 @@ int curl_con_query_url(struct sip_msg* _m, char *connection, char* _url, char* _
 	LM_DBG("***** #### ***** CURL URL: %s \n", urlbuf);
 	if (_post && *_post) {
 		LM_DBG("***** #### ***** CURL POST data: %s \n", _post);
-		 if(pv_printf_s(_m, (pv_elem_t*)_post, &postdata) != 0) {
+		 if(pv_printf_s(_m, (pv_elem_t*)_post, &postdatabuf) != 0) {
                 	LM_ERR("curl :: unable to handle post data %s\n", _post);
                 	return -1;
         	}
-        	if(postdata.s==NULL || postdata.len == 0) {
+        	if(postdatabuf.s==NULL || postdatabuf.len == 0) {
                 	LM_ERR("curl :: invalid post data parameter\n");
                 	return -1;
         	}
-		LM_DBG("***** #### ***** CURL POST data: %s Content-type %s\n", postdata.s, contenttype);
+		/* Allocated using pkg_memory */
+		postdata = as_asciiz(&postdatabuf);
+		LM_DBG("***** #### ***** CURL POST data: %s Content-type %s\n", postdata, contenttype);
+		
 	}
 
 	/* TODO: Concatenate URL in connection with URL given in function */
-	return curL_query_url(_m, urlbuf, _result, usernamebuf, passwordbuf, (contenttype ? contenttype : "text/plain"), _post,
+	res = curL_query_url(_m, urlbuf, _result, usernamebuf, passwordbuf, (contenttype ? contenttype : "text/plain"), postdata,
 		conn->timeout, conn->http_follow_redirect, 0, (unsigned int) maxdatasize );
+
+	if (postdata != NULL) {
+		pkg_free(postdata);
+	}
+	return res;
 }
 
 




More information about the sr-dev mailing list