[Asterisk-code-review] func_sayfiles: Retrieve say file names (asterisk[master])

Kevin Harwell asteriskteam at digium.com
Fri Aug 20 16:47:59 CDT 2021


Attention is currently required from: N A, Joshua Colp, George Joseph.
Kevin Harwell has posted comments on this change. ( https://gerrit.asterisk.org/c/asterisk/+/16226 )

Change subject: func_sayfiles: Retrieve say file names
......................................................................


Patch Set 13: Code-Review-1

(5 comments)

File funcs/func_sayfiles.c:

https://gerrit.asterisk.org/c/asterisk/+/16226/comment/5717ef0c_60d1bf57 
PS12, Line 165: 	struct ast_str *expr, *result;
              : 
              : 	switch (cmd) {
              : 	case TEST_INIT:
              : 		info->name = "test_SAYFILES_function";
              : 		info->category = "/funcs/func_sayfiles/";
              : 		info->summary = "Test SAYFILES function substitution";
              : 		info->description =
              : 			"Executes a series of variable substitutions using the SAYFILES function and ensures that the expected results are received.";
              : 		return AST_TEST_NOT_RUN;
              : 	case TEST_EXECUTE:
              : 		break;
              : 	}
              : 
              : 	ast_test_status_update(test, "Testing SAYFILES() substitution ...\n");
              : 
              : 	if (!(expr = ast_str_create(16))) {
              : 		return AST_TEST_FAIL;
              : 	}
              : 	if (!(result = ast_str_create(16))) {
              : 		ast_free(expr);
              : 		return AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(hi Th3re,alpha)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "letters/h&letters/i&letters/space&letters/t&letters/h&digits/3&letters/r&letters/e") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(hi Th3re,alpha) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(phreak,phonetic)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "phonetic/p_p&phonetic/h_p&phonetic/r_p&phonetic/e_p&phonetic/a_p&phonetic/k_p") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(phreak,phonetic) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(35,digits)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/3&digits/5") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(35,digits) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(35,number)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/30&digits/5") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(35,number) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(1042,number)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/1&digits/thousand&digits/40&digits/2") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(1042,number) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(0,number)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/0") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(0,digits) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(2001000001,number)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/2&digits/billion&digits/1&digits/million&digits/1") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(2001000001,number) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(7,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/h-7") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(7,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(35,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/30&digits/h-5") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(35,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(1042,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/1&digits/thousand&digits/40&digits/h-2") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(1042,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(11042,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/11&digits/thousand&digits/40&digits/h-2") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(11042,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(40000,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/40&digits/h-thousand") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(40000,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(43638,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/40&digits/3&digits/thousand&digits/6&digits/hundred&digits/30&digits/h-8") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(43638,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(1000000,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/1&digits/h-million") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(1000000,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(1000001,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/1&digits/million&digits/h-1") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(1000001,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(2001000001,ordinal)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/2&digits/billion&digits/1&digits/million&digits/h-1") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(2001000001,ordinal) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(0,money)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/0&cents") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(0,money) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(0.01,money)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/1&cent") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(0.01,money) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(0.42,money)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/40&digits/2&cents") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(0.42,money) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(1.00,money)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/1&letters/dollar") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(1.00,money) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(1.42,money)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/1&letters/dollar_&and&digits/40&digits/2&cents") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(1.42,money) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(2.00,money)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/2&dollars") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(2.00,money) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_str_set(&expr, 0, "${SAYFILES(2.42,money)}");
              : 	ast_str_substitute_variables(&result, 0, NULL, ast_str_buffer(expr));
              : 	if (strcmp(ast_str_buffer(result), "digits/2&dollars&and&digits/40&digits/2&cents") != 0) {
              : 		ast_test_status_update(test, "SAYFILES(2.42,money) test failed ('%s')\n",
              : 				ast_str_buffer(result));
              : 		res = AST_TEST_FAIL;
              : 	}
              : 
              : 	ast_free(expr);
              : 	ast_free(result);
              : 
              : 	return res;
> I thought it would be more helpful to see which ones are failing/succeeding if something goes wrong, […]
I could see either way really depending on the test. It's fine how it is if you want to leave it.


File main/pbx_builtins.c:

https://gerrit.asterisk.org/c/asterisk/+/16226/comment/677c3800_9ab18ada 
PS13, Line 1397: 	if (sscanf(tmp, "%d", &number_val) != 1) {
               : 		ast_log(LOG_WARNING, "argument '%s' to SayOrdinal could not be parsed as a number.\n", tmp);
               : 		return 0;
               : 	}
Looks like this one got missed. Use the ast_str_to_int here too.


File main/say.c:

https://gerrit.asterisk.org/c/asterisk/+/16226/comment/9efeb010_033b69df 
PS12, Line 385: fnrecurse = ast_get_number_str((amt / 100), lang);
> Done
This appears to still be a problem


https://gerrit.asterisk.org/c/asterisk/+/16226/comment/fd4e518c_cdc5a292 
PS12, Line 597: 					fnrecurse = get_number_str_en((num / 1000), lang);
              : 					fnr = ast_str_buffer(fnrecurse);
              : 					ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
              : 					num %= 1000;
              : 					snprintf(fn, sizeof(fn), (num % 1000 == 0) ? "&digits/h-thousand" : "&digits/thousand");
              : 				} else {
              : 					if (num < 1000000000) {	/* 1,000,000,000 */
              : 						fnrecurse = get_number_str_en((num / 1000000), lang);
              : 						fnr = ast_str_buffer(fnrecurse);
              : 						ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
              : 						num %= 1000000;
              : 						ast_copy_string(fn, (num % 1000000 == 0) ? "&digits/h-million" : "&digits/million", sizeof(fn));
              : 					} else {
              : 						if (num < INT_MAX) {
              : 							fnrecurse = get_number_str_en((num / 1000000000), lang);
              : 							fnr = ast_str_buffer(fnrecurse);
              : 							ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
              : 							num %= 1000000000;
              : 							ast_copy_string(fn, (num % 1000000000 == 0) ? "&digits/h-billion" : "&digits/billion", 
> Done
Still need to check if fnrecurse is NULL after retrieving.


https://gerrit.asterisk.org/c/asterisk/+/16226/comment/627cceb1_7b14a69b 
PS12, Line 563: 	while (!res && (num || playh)) {
              : 		if (num < 0) {
              : 			ast_copy_string(fn, "digits/minus", sizeof(fn));
              : 			if ( num > INT_MIN ) {
              : 				num = -num;
              : 			} else {
              : 				num = 0;
              : 			}
              : 		} else if (playh) {
              : 			ast_copy_string(fn, (num % 100 == 0) ? "digits/h-hundred" : "digits/hundred", sizeof(fn));
              : 			playh = 0;
              : 		} else if (num < 20) {
              : 			if (num > 0) {
              : 				snprintf(fn, sizeof(fn), "digits/h-%d", num);
              : 			} else {
              : 				ast_log(LOG_ERROR, "Unsupported ordinal number: %d\n", num);
              : 			}
              : 			num = 0;
              : 		} else if (num < 100) {
              : 			int base = (num / 10) * 10;
              : 			if (base != num) {
              : 				snprintf(fn, sizeof(fn), "digits/%d", base);
              : 			} else {
              : 				snprintf(fn, sizeof(fn), "digits/h-%d", base);
              : 			}
              : 			num %= 10;
              : 		} else {
              : 			if (num < 1000){
              : 				snprintf(fn, sizeof(fn), "digits/%d", (num/100));
              : 				playh++;
              : 				num %= 100;
              : 			} else {
              : 				struct ast_str *fnrecurse;
              : 				if (num < 1000000) { /* 1,000,000 */
              : 					fnrecurse = get_number_str_en((num / 1000), lang);
              : 					fnr = ast_str_buffer(fnrecurse);
              : 					ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
              : 					num %= 1000;
              : 					snprintf(fn, sizeof(fn), (num % 1000 == 0) ? "&digits/h-thousand" : "&digits/thousand");
              : 				} else {
              : 					if (num < 1000000000) {	/* 1,000,000,000 */
              : 						fnrecurse = get_number_str_en((num / 1000000), lang);
              : 						fnr = ast_str_buffer(fnrecurse);
              : 						ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
              : 						num %= 1000000;
              : 						ast_copy_string(fn, (num % 1000000 == 0) ? "&digits/h-million" : "&digits/million", sizeof(fn));
              : 					} else {
              : 						if (num < INT_MAX) {
              : 							fnrecurse = get_number_str_en((num / 1000000000), lang);
              : 							fnr = ast_str_buffer(fnrecurse);
              : 							ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fnr);
              : 							num %= 1000000000;
              : 							ast_copy_string(fn, (num % 1000000000 == 0) ? "&digits/h-billion" : "&digits/billion", sizeof(fn));
              : 						} else {
              : 							ast_log(LOG_WARNING, "Number '%d' is too big for me\n", num);
              : 							res = -1;
              : 						}
              : 					}
              : 				}
              : 				/* we already decided whether or not to add an &, don't add another one immediately */
              : 				loops = 0;
              : 			}
              : 		}
              : 		if (!res) {
              : 			ast_str_append(&filenames, 0, (loops == 0 ? "%s" : "&%s"), fn);
              : 			loops++;
              : 		}
> I tried doing this but ran into crashes and core dumps with memory issues that didn't really make se […]
Ah yeah it's fine then as is if causing a problem.



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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: If9718c89353b8e153d84add3cc4637b79585db19
Gerrit-Change-Number: 16226
Gerrit-PatchSet: 13
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-CC: Joshua Colp <jcolp at sangoma.com>
Gerrit-Attention: N A <mail at interlinked.x10host.com>
Gerrit-Attention: Joshua Colp <jcolp at sangoma.com>
Gerrit-Attention: George Joseph <gjoseph at digium.com>
Gerrit-Comment-Date: Fri, 20 Aug 2021 21:47:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: N A <mail at interlinked.x10host.com>
Comment-In-Reply-To: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: comment
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210820/5ccf6df0/attachment-0001.html>


More information about the asterisk-code-review mailing list