<p>Dovid Bender has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15066">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">Mofified funcs/func_curl.c so that we can set what consitutes a failure for curl requests.<br><br>Change-Id: I94443e508343e0a3e535e51ea6e0562767639987<br>---<br>M configs/samples/res_curl.conf.sample<br>M funcs/func_curl.c<br>2 files changed, 26 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/15066/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/configs/samples/res_curl.conf.sample b/configs/samples/res_curl.conf.sample</span><br><span>index cc47298..b511899 100644</span><br><span>--- a/configs/samples/res_curl.conf.sample</span><br><span>+++ b/configs/samples/res_curl.conf.sample</span><br><span>@@ -6,3 +6,4 @@</span><br><span> proxytype=http</span><br><span> proxyport=8001</span><br><span> ;proxyuserpwd=asterisk:asteriskrocks</span><br><span style="color: hsl(120, 100%, 40%);">+;failurecode=404,503</span><br><span>diff --git a/funcs/func_curl.c b/funcs/func_curl.c</span><br><span>index cc3b195..f6dddac 100644</span><br><span>--- a/funcs/func_curl.c</span><br><span>+++ b/funcs/func_curl.c</span><br><span>@@ -187,6 +187,9 @@</span><br><span>                                                    </enum></span><br><span>                                                </enumlist></span><br><span>                                    </enum></span><br><span style="color: hsl(120, 100%, 40%);">+                                 <enum name="failurecode"></span><br><span style="color: hsl(120, 100%, 40%);">+                                             <para>Interrupt based on specific http real curl error</para></span><br><span style="color: hsl(120, 100%, 40%);">+                                     </enum></span><br><span>                                </enumlist></span><br><span>                    </parameter></span><br><span>           </syntax></span><br><span>@@ -206,6 +209,8 @@</span><br><span> </span><br><span> #define CURLOPT_SPECIAL_HASHCOMPAT ((CURLoption) -500)</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+#define CURLOPT_SPECIAL_FAILURE_CODE 999</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static void curlds_free(void *data);</span><br><span> </span><br><span> static const struct ast_datastore_info curl_info = {</span><br><span>@@ -318,6 +323,9 @@</span><br><span>        } else if (!strcasecmp(name, "hashcompat")) {</span><br><span>              *key = CURLOPT_SPECIAL_HASHCOMPAT;</span><br><span>           *ot = OT_ENUM;</span><br><span style="color: hsl(120, 100%, 40%);">+        } else if (!strcasecmp(name, "failurecode")) {</span><br><span style="color: hsl(120, 100%, 40%);">+              *key = CURLOPT_SPECIAL_FAILURE_CODE;</span><br><span style="color: hsl(120, 100%, 40%);">+          *ot = OT_INTEGER;</span><br><span>    } else {</span><br><span>             return -1;</span><br><span>   }</span><br><span>@@ -655,7 +663,9 @@</span><br><span> static int acf_curl_helper(struct ast_channel *chan, struct curl_args *args)</span><br><span> {</span><br><span>         struct ast_str *escapebuf = ast_str_thread_get(&thread_escapebuf, 16);</span><br><span style="color: hsl(0, 100%, 40%);">-      int ret = -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ int ret = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+  long http_code = 0; /* read curl response */</span><br><span style="color: hsl(120, 100%, 40%);">+  long hasfailurecode=0;</span><br><span>       CURL **curl;</span><br><span>         struct curl_settings *cur;</span><br><span>   struct curl_slist *headers = NULL;</span><br><span>@@ -688,6 +698,8 @@</span><br><span>                     hashcompat = (long) cur->value;</span><br><span>           } else if (cur->key == CURLOPT_HTTPHEADER) {</span><br><span>                      headers = curl_slist_append(headers, (char*) cur->value);</span><br><span style="color: hsl(120, 100%, 40%);">+          } else if (cur->key == CURLOPT_SPECIAL_FAILURE_CODE) {</span><br><span style="color: hsl(120, 100%, 40%);">+                     hasfailurecode = (long) cur->value;</span><br><span>               } else {</span><br><span>                     curl_easy_setopt(*curl, cur->key, cur->value);</span><br><span>                 }</span><br><span>@@ -706,6 +718,8 @@</span><br><span>                                      hashcompat = (long) cur->value;</span><br><span>                           } else if (cur->key == CURLOPT_HTTPHEADER) {</span><br><span>                                      headers = curl_slist_append(headers, (char*) cur->value);</span><br><span style="color: hsl(120, 100%, 40%);">+                          } else if (cur->key == CURLOPT_SPECIAL_FAILURE_CODE) {</span><br><span style="color: hsl(120, 100%, 40%);">+                                     hasfailurecode = (long) cur->value;</span><br><span>                               } else {</span><br><span>                                     curl_easy_setopt(*curl, cur->key, cur->value);</span><br><span>                                 }</span><br><span>@@ -721,10 +735,9 @@</span><br><span>             curl_easy_setopt(*curl, CURLOPT_POSTFIELDS, args->postdata);</span><br><span>      }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-   /* Always assign the headers - even when NULL - in case we had</span><br><span style="color: hsl(0, 100%, 40%);">-   * custom headers the last time we used this shared cURL</span><br><span style="color: hsl(0, 100%, 40%);">-         * instance */</span><br><span style="color: hsl(0, 100%, 40%);">-  curl_easy_setopt(*curl, CURLOPT_HTTPHEADER, headers);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (headers) {</span><br><span style="color: hsl(120, 100%, 40%);">+                curl_easy_setopt(*curl, CURLOPT_HTTPHEADER, headers);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span>        /* Temporarily assign a buffer for curl to write errors to. */</span><br><span>       curl_errbuf[0] = curl_errbuf[CURL_ERROR_SIZE] = '\0';</span><br><span>@@ -739,6 +752,12 @@</span><br><span>          * here, but the source allows it. See: "typecheck: allow NULL to unset</span><br><span>          * CURLOPT_ERRORBUFFER" (62bcf005f4678a93158358265ba905bace33b834). */</span><br><span>  curl_easy_setopt(*curl, CURLOPT_ERRORBUFFER, (char*)NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+    curl_easy_getinfo (*curl, CURLINFO_RESPONSE_CODE, &http_code);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_log(LOG_NOTICE, "CURL response code (%ld).\n",http_code);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (http_code == hasfailurecode){</span><br><span style="color: hsl(120, 100%, 40%);">+             ret=-1;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span> </span><br><span>        if (store) {</span><br><span>                 AST_LIST_UNLOCK(list);</span><br><span>@@ -775,7 +794,6 @@</span><br><span>                         ast_free(fields);</span><br><span>                    ast_free(values);</span><br><span>            }</span><br><span style="color: hsl(0, 100%, 40%);">-               ret = 0;</span><br><span>     }</span><br><span> </span><br><span>        if (chan) {</span><br><span>@@ -884,6 +902,7 @@</span><br><span> "  userpwd        - A <user>:<pass> to use for authentication\n"</span><br><span> "  ssl_verifypeer - Whether to verify the peer certificate (boolean)\n"</span><br><span> "  hashcompat     - Result data will be compatible for use with HASH()\n"</span><br><span style="color: hsl(120, 100%, 40%);">+"  failurecode    - Interrupt based on specific http error code(integer)\n"</span><br><span> "                 - if value is \"legacy\", will translate '+' to ' '\n"</span><br><span> "",</span><br><span>      .read = acf_curlopt_read,</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15066">change 15066</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/15066"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I94443e508343e0a3e535e51ea6e0562767639987 </div>
<div style="display:none"> Gerrit-Change-Number: 15066 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Dovid Bender <dovid@telecurve.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>