[Asterisk-code-review] modified: configs/samples/res curl.conf.sample modified: funcs/... (asterisk[16])

Dovid Bender asteriskteam at digium.com
Wed Oct 28 13:08:13 CDT 2020


Dovid Bender has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/15074 )


Change subject: 	modified:   configs/samples/res_curl.conf.sample 	modified:   funcs/func_curl.c
......................................................................

modified:   configs/samples/res_curl.conf.sample
	modified:   funcs/func_curl.c

Change-Id: I19d28239e1019cb76a08559097335c982c4fb2db
---
M configs/samples/res_curl.conf.sample
M funcs/func_curl.c
2 files changed, 25 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/74/15074/1

diff --git a/configs/samples/res_curl.conf.sample b/configs/samples/res_curl.conf.sample
index b511899..2487bb2 100644
--- a/configs/samples/res_curl.conf.sample
+++ b/configs/samples/res_curl.conf.sample
@@ -6,4 +6,4 @@
 proxytype=http
 proxyport=8001
 ;proxyuserpwd=asterisk:asteriskrocks
-;failurecode=404,503
+;failurecodes=404,408,503
diff --git a/funcs/func_curl.c b/funcs/func_curl.c
index f6dddac..d1bb820 100644
--- a/funcs/func_curl.c
+++ b/funcs/func_curl.c
@@ -187,8 +187,8 @@
 							</enum>
 						</enumlist>
 					</enum>
-					<enum name="failurecode">
-						<para>Interrupt based on specific http real curl error</para>
+					<enum name="failurecodes">
+						<para>A comma separated list of HTTP response codes to be treated as errors</para>
 					</enum>
 				</enumlist>
 			</parameter>
@@ -323,9 +323,9 @@
 	} else if (!strcasecmp(name, "hashcompat")) {
 		*key = CURLOPT_SPECIAL_HASHCOMPAT;
 		*ot = OT_ENUM;
-	} else if (!strcasecmp(name, "failurecode")) {
+	} else if (!strcasecmp(name, "failurecodes")) {
 		*key = CURLOPT_SPECIAL_FAILURE_CODE;
-		*ot = OT_INTEGER;
+		*ot = OT_STRING;
 	} else {
 		return -1;
 	}
@@ -665,7 +665,9 @@
 	struct ast_str *escapebuf = ast_str_thread_get(&thread_escapebuf, 16);
 	int ret = 0;
 	long http_code = 0; /* read curl response */
-	long hasfailurecode=0;
+	size_t i;
+	struct ast_vector_int hasfailurecode = { NULL };
+	char *failurecodestrings,*found;
 	CURL **curl;
 	struct curl_settings *cur;
 	struct curl_slist *headers = NULL;
@@ -692,6 +694,7 @@
 		ast_autoservice_start(chan);
 	}
 
+	AST_VECTOR_INIT(&hasfailurecode, 0); /*Initialize vector*/
 	AST_LIST_LOCK(&global_curl_info);
 	AST_LIST_TRAVERSE(&global_curl_info, cur, list) {
 		if (cur->key == CURLOPT_SPECIAL_HASHCOMPAT) {
@@ -699,7 +702,10 @@
 		} else if (cur->key == CURLOPT_HTTPHEADER) {
 			headers = curl_slist_append(headers, (char*) cur->value);
 		} else if (cur->key == CURLOPT_SPECIAL_FAILURE_CODE) {
-			hasfailurecode = (long) cur->value;
+			failurecodestrings=(char*)cur->value;
+			while( (found = strsep(&failurecodestrings,",")) != NULL ) {
+				AST_VECTOR_APPEND(&hasfailurecode,atoi(found));
+			}
 		} else {
 			curl_easy_setopt(*curl, cur->key, cur->value);
 		}
@@ -719,7 +725,10 @@
 				} else if (cur->key == CURLOPT_HTTPHEADER) {
 					headers = curl_slist_append(headers, (char*) cur->value);
 				} else if (cur->key == CURLOPT_SPECIAL_FAILURE_CODE) {
-					hasfailurecode = (long) cur->value;
+					failurecodestrings=(char*)cur->value;
+					while( (found = strsep(&failurecodestrings,",")) != NULL ) {
+						AST_VECTOR_APPEND(&hasfailurecode,atoi(found));
+					}
 				} else {
 					curl_easy_setopt(*curl, cur->key, cur->value);
 				}
@@ -755,9 +764,13 @@
 	curl_easy_getinfo (*curl, CURLINFO_RESPONSE_CODE, &http_code);
 
 	ast_log(LOG_NOTICE, "CURL response code (%ld).\n",http_code);
-	if (http_code == hasfailurecode){
-		ret=-1;
+	for (i = 0; i < AST_VECTOR_SIZE(&hasfailurecode); ++i) {
+		if (http_code == AST_VECTOR_GET(&hasfailurecode,i)){
+			ret=-1;
+			break;
+		}
 	}
+	AST_VECTOR_FREE(&hasfailurecode); /* Release the vector*/
 
 	if (store) {
 		AST_LIST_UNLOCK(list);
@@ -902,8 +915,8 @@
 "  userpwd        - A <user>:<pass> to use for authentication\n"
 "  ssl_verifypeer - Whether to verify the peer certificate (boolean)\n"
 "  hashcompat     - Result data will be compatible for use with HASH()\n"
-"  failurecode    - Interrupt based on specific http error code(integer)\n"
 "                 - if value is \"legacy\", will translate '+' to ' '\n"
+"  failurecodes   - A comma separated list of HTTP response codes to be treated as errors\n"
 "",
 	.read = acf_curlopt_read,
 	.read2 = acf_curlopt_read2,
@@ -991,3 +1004,4 @@
 	.load_pri = AST_MODPRI_REALTIME_DEPEND2,
 	.requires = "res_curl",
 );
+

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15074
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I19d28239e1019cb76a08559097335c982c4fb2db
Gerrit-Change-Number: 15074
Gerrit-PatchSet: 1
Gerrit-Owner: Dovid Bender <dovid at telecurve.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20201028/0dc7199b/attachment.html>


More information about the asterisk-code-review mailing list