http_client Extend API with function to retrieve content-type of previous
authorOlle E. Johansson <oej@edvina.net>
Tue, 31 May 2016 19:53:52 +0000 (21:53 +0200)
committerOlle E. Johansson <oej@edvina.net>
Tue, 31 May 2016 19:53:52 +0000 (21:53 +0200)
transaction in the same process

modules/http_client/README
modules/http_client/curl_api.c
modules/http_client/curl_api.h
modules/http_client/doc/http_client_devel.xml
modules/http_client/functions.c
modules/http_client/functions.h

index 8c6b4a4..4a439a1 100644 (file)
@@ -90,6 +90,7 @@ Hugh Waite
 
               1.2. int http_connection_exists(str *connection)
               1.3. http_query(msg, url, dest, post)
+              1.4. http_get_content_type(str connection)
 
    List of Examples
 
@@ -753,12 +754,14 @@ Chapter 2. Developer Guide
 
         1.2. int http_connection_exists(str *connection)
         1.3. http_query(msg, url, dest, post)
+        1.4. http_get_content_type(str connection)
 
 1. Available Functions
 
    1.1. http_connect(msg, connection, url, result, content_type, post)
    1.2. int http_connection_exists(str *connection)
    1.3. http_query(msg, url, dest, post)
+   1.4. http_get_content_type(str connection)
 
 1.1. http_connect(msg, connection, url, result, content_type, post)
 
@@ -815,3 +818,14 @@ Chapter 2. Developer Guide
        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.4. http_get_content_type(str connection)
+
+   Get the content-type of the last result for this connection. This will
+   be something like "text/html" for html or "application/json" for JSON
+   data.
+
+   Result will be a pointer to a char string (char *). This is per
+   process, so the connection will have to be done in the same process.
+   Returns a NULL pointer if the connection does not exist or there's no
+   previous connection data delivered.
index c0e9d71..26ed9ad 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015 Hugh Waite
+ * Copyright (C) 2016 Edvina AB, Olle E. Johansson
  *
  * This file is part of Kamailio, a free SIP server.
  *
@@ -31,6 +32,7 @@ int bind_httpc_api(httpc_api_t *api)
        api->http_connect = curl_con_query_url;
        api->http_query = http_query;
        api->http_connection_exists = http_connection_exists;
+       api->http_get_content_type = http_get_content_type;
 
        return 0;
 }
index cbca5e3..ef51edd 100644 (file)
 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 int (*httpcapi_curlcon_exists_f)(str* _name);
+typedef char * (*httpcapi_res_content_type_f)(const str* _name);
 
 
 typedef struct httpc_api {
        httpcapi_httpconnect_f  http_connect;
        httpcapi_httpquery_f    http_query;
        httpcapi_curlcon_exists_f       http_connection_exists;
+       httpcapi_res_content_type_f     http_get_content_type;
 } httpc_api_t;
 
 typedef int (*bind_httpc_api_f)(httpc_api_t *api);
index ad06026..623aee3 100644 (file)
                        </listitem>
                        </itemizedlist>
                </section>
+               <section>
+                       <title>
+                       <function moreinfo="none">http_get_content_type(str connection)</function>
+                       </title>
+                       <para>
+                       Get the content-type of the last result for this connection. This will
+                       be something like "text/html" for html or "application/json" for JSON data.
+                       </para>
+                       <para>
+                       Result will be a pointer to a char string (char *). This is per process,
+                       so the connection will have to be done in the same process. Returns a NULL
+                       pointer if the connection does not exist or there's no previous connection
+                       data delivered.
+                       </para>
+               </section>
 
 
        </section>
index b5184be..332f625 100644 (file)
@@ -593,3 +593,30 @@ int http_query(struct sip_msg* _m, char* _url, str* _dst, char* _post)
 
        return res;
 }
+
+
+char *http_get_content_type(const str *connection)
+{
+       curl_con_t *conn = NULL;
+       curl_con_pkg_t *pconn = NULL;
+       str rval;
+
+       /* Find connection if it exists */
+       if (!connection) {
+               LM_ERR("No cURL connection specified\n");
+               return NULL;
+       }
+       LM_DBG("******** CURL Connection %.*s\n", connection->len, connection->s);
+       conn = curl_get_connection((str*)connection);
+       if (conn == NULL) {
+               LM_ERR("No cURL connection found: %.*s\n", connection->len, connection->s);
+               return NULL;
+       }
+       pconn = curl_get_pkg_connection(conn);
+       if (pconn == NULL) {
+               LM_ERR("No cURL connection data found: %.*s\n", connection->len, connection->s);
+               return NULL;
+       }
+
+       return pconn->result_content_type;
+}
index 03a3318..e799e9a 100644 (file)
@@ -51,4 +51,6 @@ int curl_get_redirect(struct sip_msg* _m, const str *connection, str* result);
 int http_query(struct sip_msg* _m, char* _url, str* _dst, char* _post);
 
 
+char *http_get_content_type(const str *connection);
+
 #endif /* CURL_FUNCTIONS_H */