http_client Add a function to check if a connection exists to the development API
authorOlle E. Johansson <oej@edvina.net>
Thu, 12 May 2016 19:10:07 +0000 (21:10 +0200)
committerOlle E. Johansson <oej@edvina.net>
Thu, 12 May 2016 19:10:07 +0000 (21:10 +0200)
modules/http_client/curl_api.c
modules/http_client/curl_api.h
modules/http_client/curlcon.c
modules/http_client/curlcon.h
modules/http_client/doc/http_client_devel.xml

index c0f8fc5..c0e9d71 100644 (file)
@@ -30,6 +30,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;
 
        return 0;
 }
index 236aef6..cbca5e3 100644 (file)
 
 #include "../../sr_module.h"
 #include "functions.h"
+#include "curlcon.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 int (*httpcapi_curlcon_exists_f)(str* _name);
 
 
 typedef struct httpc_api {
        httpcapi_httpconnect_f  http_connect;
        httpcapi_httpquery_f    http_query;
+       httpcapi_curlcon_exists_f       http_connection_exists;
 } httpc_api_t;
 
 typedef int (*bind_httpc_api_f)(httpc_api_t *api);
index aa03fba..b2caa4a 100644 (file)
@@ -124,6 +124,20 @@ unsigned int curl_connection_count()
 }
 
 
+/*! Check if CURL connection exists
+ */
+int http_connection_exists(str *name)
+{
+       curl_con_t *cc;
+
+       if (curl_get_connection(name) != NULL) {
+               return 1;
+       }
+
+       LM_DBG("curl_connection_exists no success in looking for httpcon: [%.*s]\n", name->len, name->s);
+       return 0;
+}
+
 /*! Find CURL connection by name
  */
 curl_con_t* curl_get_connection(str *name)
index 0380648..f878258 100644 (file)
@@ -39,6 +39,10 @@ extern curl_con_t *_curl_con_root;
  */
 unsigned int curl_connection_count();
 
+/*! Check if CURL connection exists
+ */
+int http_connection_exists(str *name);
+
 int http_client_load_config(str *config_file);
 
 int curl_parse_param(char *val);
index 542f50e..ad06026 100644 (file)
                        </listitem>
                        </itemizedlist>
                </section>
+               <section>
+                       <title>
+                       <function moreinfo="none">int http_connection_exists(str *connection)</function>
+                       </title>
+                       <para>
+                       Check if a connection definition exists. Connections are defined as modparam's
+                       in the http_client modules.
+                       </para>
+                       <para>
+                       Returns 1 if the connection exists, 0 if a connection with the given name can't
+                       be found.
+                       </para>
+               </section>
                <section>
                        <title>
                        <function moreinfo="none">http_query(msg, url, dest, post)</function>