<p>Dovid Bender has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/15074">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">modified: configs/samples/res_curl.conf.sample<br> modified: funcs/func_curl.c<br><br>Change-Id: I19d28239e1019cb76a08559097335c982c4fb2db<br>---<br>M configs/samples/res_curl.conf.sample<br>M funcs/func_curl.c<br>2 files changed, 25 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/15074/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 b511899..2487bb2 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,4 +6,4 @@</span><br><span> proxytype=http</span><br><span> proxyport=8001</span><br><span> ;proxyuserpwd=asterisk:asteriskrocks</span><br><span style="color: hsl(0, 100%, 40%);">-;failurecode=404,503</span><br><span style="color: hsl(120, 100%, 40%);">+;failurecodes=404,408,503</span><br><span>diff --git a/funcs/func_curl.c b/funcs/func_curl.c</span><br><span>index f6dddac..d1bb820 100644</span><br><span>--- a/funcs/func_curl.c</span><br><span>+++ b/funcs/func_curl.c</span><br><span>@@ -187,8 +187,8 @@</span><br><span> </enum></span><br><span> </enumlist></span><br><span> </enum></span><br><span style="color: hsl(0, 100%, 40%);">- <enum name="failurecode"></span><br><span style="color: hsl(0, 100%, 40%);">- <para>Interrupt based on specific http real curl error</para></span><br><span style="color: hsl(120, 100%, 40%);">+ <enum name="failurecodes"></span><br><span style="color: hsl(120, 100%, 40%);">+ <para>A comma separated list of HTTP response codes to be treated as errors</para></span><br><span> </enum></span><br><span> </enumlist></span><br><span> </parameter></span><br><span>@@ -323,9 +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(0, 100%, 40%);">- } else if (!strcasecmp(name, "failurecode")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (!strcasecmp(name, "failurecodes")) {</span><br><span> *key = CURLOPT_SPECIAL_FAILURE_CODE;</span><br><span style="color: hsl(0, 100%, 40%);">- *ot = OT_INTEGER;</span><br><span style="color: hsl(120, 100%, 40%);">+ *ot = OT_STRING;</span><br><span> } else {</span><br><span> return -1;</span><br><span> }</span><br><span>@@ -665,7 +665,9 @@</span><br><span> struct ast_str *escapebuf = ast_str_thread_get(&thread_escapebuf, 16);</span><br><span> int ret = 0;</span><br><span> long http_code = 0; /* read curl response */</span><br><span style="color: hsl(0, 100%, 40%);">- long hasfailurecode=0;</span><br><span style="color: hsl(120, 100%, 40%);">+ size_t i;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_vector_int hasfailurecode = { NULL };</span><br><span style="color: hsl(120, 100%, 40%);">+ char *failurecodestrings,*found;</span><br><span> CURL **curl;</span><br><span> struct curl_settings *cur;</span><br><span> struct curl_slist *headers = NULL;</span><br><span>@@ -692,6 +694,7 @@</span><br><span> ast_autoservice_start(chan);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_INIT(&hasfailurecode, 0); /*Initialize vector*/</span><br><span> AST_LIST_LOCK(&global_curl_info);</span><br><span> AST_LIST_TRAVERSE(&global_curl_info, cur, list) {</span><br><span> if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {</span><br><span>@@ -699,7 +702,10 @@</span><br><span> } else if (cur->key == CURLOPT_HTTPHEADER) {</span><br><span> headers = curl_slist_append(headers, (char*) cur->value);</span><br><span> } else if (cur->key == CURLOPT_SPECIAL_FAILURE_CODE) {</span><br><span style="color: hsl(0, 100%, 40%);">- hasfailurecode = (long) cur->value;</span><br><span style="color: hsl(120, 100%, 40%);">+ failurecodestrings=(char*)cur->value;</span><br><span style="color: hsl(120, 100%, 40%);">+ while( (found = strsep(&failurecodestrings,",")) != NULL ) {</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_APPEND(&hasfailurecode,atoi(found));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> curl_easy_setopt(*curl, cur->key, cur->value);</span><br><span> }</span><br><span>@@ -719,7 +725,10 @@</span><br><span> } else if (cur->key == CURLOPT_HTTPHEADER) {</span><br><span> headers = curl_slist_append(headers, (char*) cur->value);</span><br><span> } else if (cur->key == CURLOPT_SPECIAL_FAILURE_CODE) {</span><br><span style="color: hsl(0, 100%, 40%);">- hasfailurecode = (long) cur->value;</span><br><span style="color: hsl(120, 100%, 40%);">+ failurecodestrings=(char*)cur->value;</span><br><span style="color: hsl(120, 100%, 40%);">+ while( (found = strsep(&failurecodestrings,",")) != NULL ) {</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_APPEND(&hasfailurecode,atoi(found));</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> } else {</span><br><span> curl_easy_setopt(*curl, cur->key, cur->value);</span><br><span> }</span><br><span>@@ -755,9 +764,13 @@</span><br><span> curl_easy_getinfo (*curl, CURLINFO_RESPONSE_CODE, &http_code);</span><br><span> </span><br><span> ast_log(LOG_NOTICE, "CURL response code (%ld).\n",http_code);</span><br><span style="color: hsl(0, 100%, 40%);">- if (http_code == hasfailurecode){</span><br><span style="color: hsl(0, 100%, 40%);">- ret=-1;</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < AST_VECTOR_SIZE(&hasfailurecode); ++i) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (http_code == AST_VECTOR_GET(&hasfailurecode,i)){</span><br><span style="color: hsl(120, 100%, 40%);">+ ret=-1;</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> }</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_VECTOR_FREE(&hasfailurecode); /* Release the vector*/</span><br><span> </span><br><span> if (store) {</span><br><span> AST_LIST_UNLOCK(list);</span><br><span>@@ -902,8 +915,8 @@</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(0, 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 style="color: hsl(120, 100%, 40%);">+" failurecodes - A comma separated list of HTTP response codes to be treated as errors\n"</span><br><span> "",</span><br><span> .read = acf_curlopt_read,</span><br><span> .read2 = acf_curlopt_read2,</span><br><span>@@ -991,3 +1004,4 @@</span><br><span> .load_pri = AST_MODPRI_REALTIME_DEPEND2,</span><br><span> .requires = "res_curl",</span><br><span> );</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/15074">change 15074</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/+/15074"/><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: I19d28239e1019cb76a08559097335c982c4fb2db </div>
<div style="display:none"> Gerrit-Change-Number: 15074 </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>