TT#143150 dsm: ModUtils, fix the work of utils_get_count_files() (CE)

We need to rework the utils_get_count_files(), because it improperly
treats the given list of numbers, especially what relates to zeroes.

Previous approach gets deprecated, and another approach is applied.

Change-Id: I4ec0b5f4e40c96d5b3603f4ee376d210afce21e2
mr10.2.1
Donat Zenichev 5 years ago
parent 2c83274cb4
commit 2d0775b77c

@ -41,3 +41,4 @@ sipwise/db_reg_agent_auth_header.patch
sipwise/skip_outbound_auth_if_credentials_empty.patch
sipwise/add_support_for_peering_outbound_registration.patch
sipwise/cpslimit_detect_emergency_calls_and_let_them_pass.patch
sipwise/dsm_modutils_fix_utils_get_count_files.patch

@ -0,0 +1,54 @@
--- a/apps/dsm/mods/mod_utils/ModUtils.cpp
+++ b/apps/dsm/mods/mod_utils/ModUtils.cpp
@@ -72,20 +72,32 @@ vector<string> utils_get_count_files(DSM
vector<string> res;
+ unsigned int number = cnt;
+ unsigned int n = log10(number) + 1;
+ const int max = 9;
+
+ string full_number = std::to_string(number);
+ string remainder; /* what remains after 9 digits, if remains */
+ bool remainder_exists = false;
+
if (cnt <= 20) {
res.push_back(basedir+int2str(cnt)+suffix);
return res;
}
-
- for (int i=9;i>1;i--) {
- div_t num = div(cnt, (int)pow(10.,i));
- if (num.quot) {
- res.push_back(basedir+int2str(int(num.quot * pow(10.,i)))+suffix);
- }
- cnt = num.rem;
+
+ if (n > max) {
+ remainder_exists = true;
+ remainder = full_number.substr(max);
+ cnt = std::stoi(remainder);
+ }
+
+ for (int i = n; i > 0; i--) {
+ int num = (int)((number % (unsigned int)pow(10, i)) / pow(10, i - 1));
+ if ( (n - i) < max )
+ res.push_back(basedir+int2str(num)+suffix); /* only push until max amount here */
}
- if (!cnt)
+ if (!remainder_exists)
return res;
if ((cnt <= 20) || (!(cnt%10))) {
--- a/apps/dsm/mods/mod_utils/ModUtils.h
+++ b/apps/dsm/mods/mod_utils/ModUtils.h
@@ -31,6 +31,8 @@
#include "AmRingTone.h"
#include "DSMSession.h"
+#include <string>
+
#define MOD_CLS_NAME SCUtilsModule
DECLARE_MODULE(MOD_CLS_NAME);
Loading…
Cancel
Save