diff options
author | Denis Kenzior <denkenz@gmail.com> | 2009-06-12 19:33:55 -0500 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2009-06-12 19:33:55 -0500 |
commit | 3c27dae5e85ce3e5bf617d2f1bbc33f2addcd236 (patch) | |
tree | 26f3ee54d68d30ab46fe855c75164e89bc161456 /src | |
parent | ba8828c095d72fb628fa418b1aa082a765d5d0a3 (diff) | |
download | ofono-3c27dae5e85ce3e5bf617d2f1bbc33f2addcd236.tar.bz2 |
Fixup style issues with previous MCC/MNC patch
- Breakup MCC/MNC LENGTH constant
- Don't hardcode numbers
- Fix >80 column length
- Fix test case to expect strings instead of shorts
Diffstat (limited to 'src')
-rw-r--r-- | src/driver.h | 7 | ||||
-rw-r--r-- | src/network.c | 23 |
2 files changed, 18 insertions, 12 deletions
diff --git a/src/driver.h b/src/driver.h index f753c7f5..c9281795 100644 --- a/src/driver.h +++ b/src/driver.h @@ -75,12 +75,13 @@ struct ofono_call { #define OFONO_MAX_OPERATOR_NAME_LENGTH 63 /* MCC is always three digits. MNC is either two or three digits */ -#define OFONO_MAX_MNC_MCC_LENGTH 3 +#define OFONO_MAX_MCC_LENGTH 3 +#define OFONO_MAX_MNC_LENGTH 3 struct ofono_network_operator { char name[OFONO_MAX_OPERATOR_NAME_LENGTH + 1]; - char mcc[OFONO_MAX_MNC_MCC_LENGTH + 1]; - char mnc[OFONO_MAX_MNC_MCC_LENGTH + 1]; + char mcc[OFONO_MAX_MCC_LENGTH + 1]; + char mnc[OFONO_MAX_MNC_LENGTH + 1]; int status; int tech; }; diff --git a/src/network.c b/src/network.c index aa13077f..a437f0dd 100644 --- a/src/network.c +++ b/src/network.c @@ -177,14 +177,15 @@ static void network_operator_populate_registered(struct ofono_modem *modem, DBusConnection *conn = dbus_gsm_connection(); char **children; int i; - int modem_len; + int prefix_len; int num_children; GSList *l; char path[MAX_DBUS_PATH_LEN]; - char mnc[4]; - char mcc[4]; + char mnc[OFONO_MAX_MNC_LENGTH + 1]; + char mcc[OFONO_MAX_MCC_LENGTH + 1]; + int op_path_len; - modem_len = snprintf(path, MAX_DBUS_PATH_LEN, "%s/operator", + prefix_len = snprintf(path, MAX_DBUS_PATH_LEN, "%s/operator", modem->path); if (!dbus_connection_list_registered(conn, path, &children)) { @@ -199,6 +200,10 @@ static void network_operator_populate_registered(struct ofono_modem *modem, num_children = i; *network_operators = g_try_new0(char *, num_children + 1); + + /* Enough to store '/' + MCC + MNC + null */ + op_path_len = prefix_len; + op_path_len += OFONO_MAX_MCC_LENGTH + OFONO_MAX_MNC_LENGTH + 2; /* Quoting 27.007: "The list of operators shall be in order: home * network, networks referenced in SIM or active application in the @@ -215,11 +220,11 @@ static void network_operator_populate_registered(struct ofono_modem *modem, for (j = 0; children[j]; j++) { sscanf(children[j], "%3[0-9]%[0-9]", mcc, mnc); - if (strcmp(op->mcc, mcc) == 0 && strcmp(op->mnc, mnc) == 0) { - /* Enough to store '/' + MCC + '_' + MNC + null */ - (*network_operators)[i] = g_try_new(char, modem_len + 9); - snprintf((*network_operators)[i], modem_len + 9, "%s/%s", - path, children[j]); + if (!strcmp(op->mcc, mcc) && !strcmp(op->mnc, mnc)) { + (*network_operators)[i] = + g_try_new(char, op_path_len); + snprintf((*network_operators)[i], op_path_len, + "%s/%s", path, children[j]); ++i; } } |