Browse Source

curl Add maxdatasize to the curlcon modparam

Olle E. Johansson 10 years ago
parent
commit
1faef129e1
5 changed files with 40 additions and 6 deletions
  1. 8 1
      modules/curl/README
  2. 1 1
      modules/curl/curl.h
  3. 19 3
      modules/curl/curlcon.c
  4. 11 1
      modules/curl/doc/curl_admin.xml
  5. 1 0
      modules/curl/functions.c

+ 8 - 1
modules/curl/README

@@ -125,7 +125,12 @@ Chapter 1. Admin Guide
    This module implements protocol functions that use the libcurl library
    This module implements protocol functions that use the libcurl library
    to fetch data from external HTTP servers or post data to HTTP servers.
    to fetch data from external HTTP servers or post data to HTTP servers.
    The module is using a concept of "connections" to define properties of
    The module is using a concept of "connections" to define properties of
-   sessions in a simple way.
+   HTTP sessions in a simple way.
+
+   The curl module has multiple settings, some of them applies to a
+   defined connection. You can set timeouts, max data sizes for download
+   and much more either using modparam settings or parameters to the
+   connection definition.
 
 
    Function http_query allows Kamailio to issue an HTTP GET request and
    Function http_query allows Kamailio to issue an HTTP GET request and
    get access to parts of the reply. This function has been ported from
    get access to parts of the reply. This function has been ported from
@@ -282,6 +287,8 @@ modparam("curl", "tlsverifyserver", 1)
    Parameters
    Parameters
      * httpredirect Set to 1 for following HTTP 302 redirect. 0 to
      * httpredirect Set to 1 for following HTTP 302 redirect. 0 to
        disable. Default is the setting for the httpredirect modparam.
        disable. Default is the setting for the httpredirect modparam.
+     * maxdatasize The maximum datasize for a response. Overrides the
+       maxdatasize modparam setting.
      * timeout Timeout used for this connection. Overrides the default
      * timeout Timeout used for this connection. Overrides the default
        timeout for the module.
        timeout for the module.
      * useragent Useragent used for HTTP requests. Overrides useragent
      * useragent Useragent used for HTTP requests. Overrides useragent

+ 1 - 1
modules/curl/curl.h

@@ -76,7 +76,7 @@ typedef struct _curl_con
 	int http_follow_redirect;	/*!< TRUE if we should follow HTTP 302 redirects */
 	int http_follow_redirect;	/*!< TRUE if we should follow HTTP 302 redirects */
 	unsigned int port;		/*!< The port to connect to */
 	unsigned int port;		/*!< The port to connect to */
 	int timeout;			/*!< Timeout for this connection */
 	int timeout;			/*!< Timeout for this connection */
-	long maxdatasize;		/*!< Maximum data download on GET or POST */
+	unsigned int maxdatasize;	/*!< Maximum data download on GET or POST */
 	curl_res_stream_t *stream;	/*!< Curl stream */
 	curl_res_stream_t *stream;	/*!< Curl stream */
 	struct _curl_con *next;		/*!< next connection */
 	struct _curl_con *next;		/*!< next connection */
 	char redirecturl[512];		/*!< Last redirect URL - to use for $curlredirect(curlcon) pv */
 	char redirecturl[512];		/*!< Last redirect URL - to use for $curlredirect(curlcon) pv */

+ 19 - 3
modules/curl/curlcon.c

@@ -90,6 +90,13 @@ curl_con_t* curl_get_connection(str *name)
  *
  *
  *		the url is very much like CURLs syntax
  *		the url is very much like CURLs syntax
  *		the url is a base url where you can add local address
  *		the url is a base url where you can add local address
+ *	Parameters
+ *		httpredirect
+ *		timeout
+ *		useragent
+ *		failover
+ *		maxdatasize
+ *
  */
  */
 int curl_parse_param(char *val)
 int curl_parse_param(char *val)
 {
 {
@@ -100,6 +107,8 @@ int curl_parse_param(char *val)
 	str password	= STR_NULL;
 	str password	= STR_NULL;
 	str params	= STR_NULL;
 	str params	= STR_NULL;
 	str failover	= STR_NULL;
 	str failover	= STR_NULL;
+
+	unsigned int maxdatasize = default_maxdatasize;
 	unsigned int timeout	= default_connection_timeout;
 	unsigned int timeout	= default_connection_timeout;
 	str useragent   = { default_useragent, strlen(default_useragent) };
 	str useragent   = { default_useragent, strlen(default_useragent) };
 	unsigned int http_follow_redirect = default_http_follow_redirect;
 	unsigned int http_follow_redirect = default_http_follow_redirect;
@@ -284,6 +293,13 @@ int curl_parse_param(char *val)
 				failover = tok;
 				failover = tok;
 				LM_DBG("curl [%.*s] - failover [%.*s]\n", pit->name.len, pit->name.s,
 				LM_DBG("curl [%.*s] - failover [%.*s]\n", pit->name.len, pit->name.s,
 						failover.len, failover.s);
 						failover.len, failover.s);
+			} else if(pit->name.len==11 && strncmp(pit->name.s, "maxdatasize", 11)==0) {
+				if(str2int(&tok, &maxdatasize)!=0) {
+					/* Bad timeout */
+					LM_DBG("curl connection [%.*s]: timeout bad value. Using default\n", name.len, name.s);
+					maxdatasize = default_maxdatasize;
+				}
+				LM_DBG("curl [%.*s] - timeout [%d]\n", pit->name.len, pit->name.s, maxdatasize);
 			} else {
 			} else {
 				LM_ERR("curl Unknown parameter [%.*s] \n", pit->name.len, pit->name.s);
 				LM_ERR("curl Unknown parameter [%.*s] \n", pit->name.len, pit->name.s);
 			}
 			}
@@ -291,11 +307,10 @@ int curl_parse_param(char *val)
 	}
 	}
 
 
 	/* The URL ends either with nothing or parameters. Parameters start with ; */
 	/* The URL ends either with nothing or parameters. Parameters start with ; */
-	
 
 
-	LM_DBG("cname: [%.*s] url: [%.*s] username [%.*s] password [%.*s] failover [%.*s] timeout [%d] useragent [%.*s]\n", 
+	LM_DBG("cname: [%.*s] url: [%.*s] username [%.*s] password [%.*s] failover [%.*s] timeout [%d] useragent [%.*s] maxdatasize [%d]\n", 
 			name.len, name.s, url.len, url.s, username.len, username.s,
 			name.len, name.s, url.len, url.s, username.len, username.s,
-			password.len, password.s, failover.len, failover.s, timeout, useragent.len, useragent.s);
+			password.len, password.s, failover.len, failover.s, timeout, useragent.len, useragent.s, maxdatasize);
 
 
 	if(conparams != NULL) {
 	if(conparams != NULL) {
 		free_params(conparams);
 		free_params(conparams);
@@ -312,6 +327,7 @@ int curl_parse_param(char *val)
 	cc->useragent = useragent;
 	cc->useragent = useragent;
 	cc->url = url;
 	cc->url = url;
 	cc->timeout = timeout;
 	cc->timeout = timeout;
+	cc->maxdatasize = maxdatasize;
 	cc->http_follow_redirect = http_follow_redirect;
 	cc->http_follow_redirect = http_follow_redirect;
 	return 0;
 	return 0;
 
 

+ 11 - 1
modules/curl/doc/curl_admin.xml

@@ -23,7 +23,13 @@
 	This module implements protocol functions that use the libcurl library
 	This module implements protocol functions that use the libcurl library
 	to fetch data from external HTTP servers or post data to HTTP servers.
 	to fetch data from external HTTP servers or post data to HTTP servers.
 	The module is using a concept of "connections" to define properties
 	The module is using a concept of "connections" to define properties
-	of sessions in a simple way.
+	of HTTP sessions in a simple way.
+	</para>
+	<para>
+	The curl module has multiple settings, some of them applies to
+	a defined connection. You can set timeouts, max data sizes for download
+	and much more either using modparam settings or parameters to the
+	connection definition.
 	</para>
 	</para>
 	<para>
 	<para>
 	Function http_query allows &kamailio; to issue an HTTP GET
 	Function http_query allows &kamailio; to issue an HTTP GET
@@ -264,6 +270,10 @@ modparam("curl", "tlsverifyserver", 1)
 				redirect. 0 to disable. Default is the setting for the httpredirect modparam.
 				redirect. 0 to disable. Default is the setting for the httpredirect modparam.
 				</para></listitem>
 				</para></listitem>
 				<listitem><para>
 				<listitem><para>
+				<emphasis>maxdatasize</emphasis> The maximum datasize for a response. Overrides
+				the maxdatasize modparam setting.
+				</para></listitem>
+				<listitem><para>
 				<emphasis>timeout</emphasis> Timeout used for this connection. Overrides the 
 				<emphasis>timeout</emphasis> Timeout used for this connection. Overrides the 
 				default timeout for the module.
 				default timeout for the module.
 				</para></listitem>
 				</para></listitem>

+ 1 - 0
modules/curl/functions.c

@@ -293,6 +293,7 @@ int curl_con_query_url(struct sip_msg* _m, char *connection, char* _url, char* _
 	strncpy(usernamebuf, conn->username.s, conn->username.len);
 	strncpy(usernamebuf, conn->username.s, conn->username.len);
 	strncpy(passwordbuf, conn->password.s, conn->password.len);
 	strncpy(passwordbuf, conn->password.s, conn->password.len);
 	strncpy(connurlbuf, conn->url.s, conn->url.len);
 	strncpy(connurlbuf, conn->url.s, conn->url.len);
+	maxdatasize = conn->maxdatasize;
 
 
 	LM_DBG("******** CURL Connection found %s\n", connection);
 	LM_DBG("******** CURL Connection found %s\n", connection);