Преглед на файлове

http_client Expand API with the "old" http_query function

This is for developers who do not want to use the connection definitions,
just fire away freely. The default settings set in http_client modparam's will be used.
Olle E. Johansson преди 9 години
родител
ревизия
03296efa1c
променени са 4 файла, в които са добавени 74 реда и са изтрити 2 реда
  1. 27 1
      modules/http_client/README
  2. 1 0
      modules/http_client/curl_api.c
  3. 3 0
      modules/http_client/curl_api.h
  4. 43 1
      modules/http_client/doc/http_client_devel.xml

+ 27 - 1
modules/http_client/README

@@ -84,6 +84,8 @@ Hugh Waite
               1.1. http_connect(msg, connection, url, result,
                       content_type, post)
 
+              1.2. http_query(msg, url, dest, post)
+
    List of Examples
 
    1.1. Set httpredirect parameter
@@ -739,13 +741,18 @@ Chapter 2. Developer Guide
         1.1. http_connect(msg, connection, url, result, content_type,
                 post)
 
+        1.2. http_query(msg, url, dest, post)
+
 1. Available Functions
 
    1.1. http_connect(msg, connection, url, result, content_type, post)
+   1.2. http_query(msg, url, dest, post)
 
 1.1. http_connect(msg, connection, url, result, content_type, post)
 
-   Sends HTTP GET or POST request to a given connection.
+   Sends HTTP GET or POST request to a given connection. If content_type
+   and post are NULL GET will be used. If post is not null the data will
+   be POSTed using the specified content_type.
 
    Returns the status code of the HTTP response (if >= 100), or a curl
    error code (if < 100)
@@ -769,3 +776,22 @@ Chapter 2. Developer Guide
      * const str *post
        A string containing the message body to send. Use NULL when a
        message body is not required.
+
+1.2. http_query(msg, url, dest, post)
+
+   Sends HTTP GET or POST request to a given connection. If post data is
+   defined, POST will be used, otherwise GET. The default settings defined
+   as module params of the http_client module will be used for the
+   connection.
+
+   Meaning of the parameters is as follows:
+     * struct sip_msg *msg
+       The current sip message structure.
+     * const char *url
+       A string that will be used as the URL specified in the connection.
+     * str *dest
+       A pointer to a string that will contain the first line of the
+       response body. On success, the data is allocated in pkg memory by
+       the http_client module and must be freed by the caller.
+     * const char *post
+       If not null, the data will be posted to the URL.

+ 1 - 0
modules/http_client/curl_api.c

@@ -29,6 +29,7 @@ int bind_httpc_api(httpc_api_t *api)
 		return -1;
 	}
 	api->http_connect = curl_con_query_url;
+	api->http_query = http_query;
 
 	return 0;
 }

+ 3 - 0
modules/http_client/curl_api.h

@@ -32,9 +32,12 @@
 #include "functions.h"
 
 typedef int (*httpcapi_httpconnect_f)(struct sip_msg *msg, const str *connection, const str* _url, str* _result, const char *contenttype, const str* _post);
+typedef int (*httpcapi_httpquery_f)(struct sip_msg* _m, char* _url, str* _dst, char* _post);
+
 
 typedef struct httpc_api {
 	httpcapi_httpconnect_f	http_connect;
+	httpcapi_httpquery_f	http_query;
 } httpc_api_t;
 
 typedef int (*bind_httpc_api_f)(httpc_api_t *api);

+ 43 - 1
modules/http_client/doc/http_client_devel.xml

@@ -19,7 +19,9 @@
 			<function moreinfo="none">http_connect(msg, connection, url, result, content_type, post)</function>
 			</title>
 			<para>
-			Sends HTTP GET or POST request to a given connection.
+			Sends HTTP GET or POST request to a given connection. If content_type and post
+			are NULL GET will be used. If post is not null the data will be POSTed using
+			the specified content_type.
 			</para>
 			<para>
 			Returns the status code of the HTTP response (if &gt;= 100), or a curl error code (if &lt; 100)
@@ -69,6 +71,46 @@
 			</listitem>
 			</itemizedlist>
 		</section>
+		<section>
+			<title>
+			<function moreinfo="none">http_query(msg, url, dest, post)</function>
+			</title>
+			<para>
+			Sends HTTP GET or POST request to a given connection. If post data 
+			is defined, POST will be used, otherwise GET. The default settings
+			defined as module params of the http_client module will be used for
+			the connection.
+			</para>
+			<para>Meaning of the parameters is as follows:</para>
+			<itemizedlist>
+			<listitem>
+				<para><emphasis>struct sip_msg *msg</emphasis></para>
+				<para>
+				The current sip message structure.
+				</para>
+			</listitem>
+			<listitem>
+				<para><emphasis>const char *url</emphasis></para>
+				<para>
+				A string that will be used as the URL specified in the connection.
+				</para>
+			</listitem>
+			<listitem>
+				<para><emphasis>str *dest</emphasis></para>
+				<para>
+				A pointer to a string that will contain the first line of the response body.
+				On success, the data is allocated in pkg memory by the http_client module
+				and must be freed by the caller.
+				</para>
+			</listitem>
+			<listitem>
+				<para><emphasis>const char *post</emphasis></para>
+				<para>
+				If not null, the data will be posted to the URL.
+				</para>
+			</listitem>
+			</itemizedlist>
+		</section>
 
 
 	</section>