From ab68cd8e7ebeba3410bbdd1e4919ad875025766f Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Tue, 26 May 2009 13:48:42 -0500 Subject: [PATCH] Create ofono_phone_number struct Creates a new structure in driver.h called ofono_phone_number. This is meant to replace const char *number, int number_type arguments everywhere. Fix up all existing code to use this structure instead. --- drivers/atmodem/call-forwarding.c | 23 ++++++---- drivers/atmodem/sim.c | 21 ++++----- drivers/atmodem/voicecall.c | 76 +++++++++++++++---------------- src/call-forwarding.c | 61 ++++++++++++------------- src/common.c | 19 ++++---- src/common.h | 4 +- src/cssn.c | 4 +- src/cssn.h | 4 +- src/driver.h | 42 ++++++++--------- src/sim.c | 22 +++++---- src/voicecall.c | 59 +++++++++++------------- 11 files changed, 161 insertions(+), 174 deletions(-) diff --git a/drivers/atmodem/call-forwarding.c b/drivers/atmodem/call-forwarding.c index cddda569..b152b110 100644 --- a/drivers/atmodem/call-forwarding.c +++ b/drivers/atmodem/call-forwarding.c @@ -50,6 +50,7 @@ static void ccfc_query_cb(gboolean ok, GAtResult *result, gpointer user_data) int num = 0; struct ofono_cf_condition *list = NULL; int i; + int maxlen; dump_response("ccfc_query_cb", ok, result); decode_at_error(&error, g_at_result_final_response(result)); @@ -79,24 +80,26 @@ static void ccfc_query_cb(gboolean ok, GAtResult *result, gpointer user_data) g_at_result_iter_init(&iter, result); + maxlen = OFONO_MAX_PHONE_NUMBER_LENGTH; + for (num = 0; g_at_result_iter_next(&iter, "+CCFC:"); num++) { const char *str; g_at_result_iter_next_number(&iter, &(list[num].status)); g_at_result_iter_next_number(&iter, &(list[num].cls)); - list[num].phone_number[0] = '\0'; - list[num].number_type = 129; + list[num].phone_number.number[0] = '\0'; + list[num].phone_number.type = 129; list[num].time = 20; if (!g_at_result_iter_next_string(&iter, &str)) continue; - strncpy(list[num].phone_number, str, - OFONO_MAX_PHONE_NUMBER_LENGTH); - list[num].phone_number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0'; + strncpy(list[num].phone_number.number, str, maxlen); + list[num].phone_number.number[maxlen] = '\0'; - g_at_result_iter_next_number(&iter, &(list[num].number_type)); + g_at_result_iter_next_number(&iter, + &(list[num].phone_number.type)); if (!g_at_result_iter_skip_next(&iter)) continue; @@ -110,8 +113,8 @@ static void ccfc_query_cb(gboolean ok, GAtResult *result, gpointer user_data) for (i = 0; i < num; i++) ofono_debug("ccfc_cb: %d, %d, %s(%d) - %d sec", list[i].status, list[i].cls, - list[i].phone_number, list[i].number_type, - list[i].time); + list[i].phone_number.number, + list[i].phone_number.type, list[i].time); out: cb(&error, num, list, cbd->data); @@ -227,7 +230,7 @@ static void at_ccfc_activation(struct ofono_modem *modem, int type, int cls, } static void at_ccfc_registration(struct ofono_modem *modem, int type, int cls, - const char *number, int number_type, + const struct ofono_phone_number *ph, int time, ofono_generic_cb_t cb, void *data) { @@ -235,7 +238,7 @@ static void at_ccfc_registration(struct ofono_modem *modem, int type, int cls, int offset; offset = sprintf(buf, "AT+CCFC=%d,3,\"%s\",%d,%d", type, - number, number_type, cls); + ph->number, ph->type, cls); if (type == 2 || type == 4 || type == 5) sprintf(buf+offset, ",,,%d", time); diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c index 20cf5647..f3a204d0 100644 --- a/drivers/atmodem/sim.c +++ b/drivers/atmodem/sim.c @@ -236,8 +236,7 @@ static void at_cnum_cb(gboolean ok, GAtResult *result, gpointer user_data) GAtResultIter iter; ofono_numbers_cb_t cb = cbd->cb; struct ofono_error error; - struct ofono_own_number *numbers; - GSList *l = NULL; + struct ofono_phone_number *numbers; int count; const char *str; @@ -245,7 +244,7 @@ static void at_cnum_cb(gboolean ok, GAtResult *result, gpointer user_data) decode_at_error(&error, g_at_result_final_response(result)); if (!ok) { - cb(&error, NULL, cbd->data); + cb(&error, 0, NULL, cbd->data); return; } @@ -254,10 +253,10 @@ static void at_cnum_cb(gboolean ok, GAtResult *result, gpointer user_data) for (count = 0; g_at_result_iter_next(&iter, "+CNUM:"); count++); ofono_debug("Got %i elements", count); - numbers = g_try_new0(struct ofono_own_number, count); + numbers = g_try_new0(struct ofono_phone_number, count); if (!numbers) { DECLARE_FAILURE(e); - cb(&e, NULL, cbd->data); + cb(&e, 0, NULL, cbd->data); return; } @@ -269,19 +268,15 @@ static void at_cnum_cb(gboolean ok, GAtResult *result, gpointer user_data) if (!g_at_result_iter_next_string(&iter, &str)) continue; - g_strlcpy(numbers[count].phone_number, str, + g_strlcpy(numbers[count].number, str, OFONO_MAX_PHONE_NUMBER_LENGTH); - g_at_result_iter_next_number(&iter, - &numbers[count].number_type); - - l = g_slist_append(l, &numbers[count]); + g_at_result_iter_next_number(&iter, &numbers[count].type); } - cb(&error, l, cbd->data); + cb(&error, count, numbers, cbd->data); g_free(numbers); - g_slist_free(l); } static void at_read_msisdn(struct ofono_modem *modem, ofono_numbers_cb_t cb, @@ -303,7 +298,7 @@ error: { DECLARE_FAILURE(error); - cb(&error, NULL, data); + cb(&error, 0, NULL, data); } } diff --git a/drivers/atmodem/voicecall.c b/drivers/atmodem/voicecall.c index e5c8d49f..2be98313 100644 --- a/drivers/atmodem/voicecall.c +++ b/drivers/atmodem/voicecall.c @@ -168,8 +168,9 @@ static struct ofono_call *create_call(struct voicecall_data *d, int type, call->status = status; if (clip != 2) { - strncpy(call->phone_number, num, OFONO_MAX_PHONE_NUMBER_LENGTH); - call->number_type = num_type; + strncpy(call->phone_number.number, num, + OFONO_MAX_PHONE_NUMBER_LENGTH); + call->phone_number.type = num_type; } call->clip_validity = clip; @@ -229,10 +230,11 @@ static GSList *parse_clcc(GAtResult *result) call->direction = dir; call->status = status; call->type = type; - strncpy(call->phone_number, str, OFONO_MAX_PHONE_NUMBER_LENGTH); - call->number_type = number_type; + strncpy(call->phone_number.number, str, + OFONO_MAX_PHONE_NUMBER_LENGTH); + call->phone_number.type = number_type; - if (strlen(call->phone_number) > 0) + if (strlen(call->phone_number.number) > 0) call->clip_validity = 0; else call->clip_validity = 2; @@ -440,7 +442,8 @@ out: cb(&error, cbd->data); } -static void at_dial(struct ofono_modem *modem, const char *number, int number_type, +static void at_dial(struct ofono_modem *modem, + const struct ofono_phone_number *ph, enum ofono_clir_option clir, enum ofono_cug_option cug, ofono_generic_cb_t cb, void *data) { @@ -451,7 +454,7 @@ static void at_dial(struct ofono_modem *modem, const char *number, int number_ty if (!cbd) goto error; - sprintf(buf, "ATD%s", number); + sprintf(buf, "ATD%s", ph->number); switch (clir) { case OFONO_CLIR_OPTION_INVOCATION: @@ -678,13 +681,14 @@ static void at_transfer(struct ofono_modem *modem, ofono_generic_cb_t cb, at_template("AT+CHLD=4", modem, generic_cb, transfer, cb, data); } -static void at_deflect(struct ofono_modem *modem, const char *number, - int number_type, ofono_generic_cb_t cb, void *data) +static void at_deflect(struct ofono_modem *modem, + const struct ofono_phone_number *ph, + ofono_generic_cb_t cb, void *data) { char buf[128]; unsigned int incoming_or_waiting = (0x1 << 4) | (0x1 << 5); - sprintf(buf, "AT+CTFR=%s,%d", number, number_type); + sprintf(buf, "AT+CTFR=%s,%d", ph->number, ph->type); at_template(buf, modem, generic_cb, incoming_or_waiting, cb, data); } @@ -861,9 +865,10 @@ static void clip_notify(GAtResult *result, gpointer user_data) call = l->data; - strncpy(call->phone_number, num, OFONO_MAX_PHONE_NUMBER_LENGTH); - call->phone_number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0'; - call->number_type = type; + strncpy(call->phone_number.number, num, + OFONO_MAX_PHONE_NUMBER_LENGTH); + call->phone_number.number[OFONO_MAX_PHONE_NUMBER_LENGTH] = '\0'; + call->phone_number.type = type; call->clip_validity = validity; if (call->type == 0) @@ -993,9 +998,13 @@ static void cssu_notify(GAtResult *result, gpointer user_data) { struct ofono_modem *modem = user_data; GAtResultIter iter; - int code2, index, num_type, satype; - const char *num, *subaddr; - char num_buf[OFONO_MAX_PHONE_NUMBER_LENGTH]; + int code2; + int index = -1; + const char *num; + struct ofono_phone_number ph; + + ph.number[0] = '\0'; + ph.type = 129; dump_response("cssu_notify", TRUE, result); @@ -1007,32 +1016,21 @@ static void cssu_notify(GAtResult *result, gpointer user_data) if (!g_at_result_iter_next_number(&iter, &code2)) return; - if (!g_at_result_iter_next_number(&iter, &index)) { - index = 0; - num = NULL; - num_type = 0; - subaddr = NULL; - satype = 0; - } else if (!g_at_result_iter_next_string(&iter, &num)) { - num = NULL; - num_type = 0; - subaddr = NULL; - satype = 0; - } else { - strncpy(num_buf, num, OFONO_MAX_PHONE_NUMBER_LENGTH); - num = num_buf; + /* This field is optional, if we can't read it, try to skip it */ + if (!g_at_result_iter_next_number(&iter, &index) && + !g_at_result_iter_skip_next(&iter)) + goto out; - if (!g_at_result_iter_next_number(&iter, &num_type)) - return; + if (!g_at_result_iter_next_string(&iter, &num)) + goto out; - if (!g_at_result_iter_next_string(&iter, &subaddr)) { - subaddr = NULL; - satype = 0; - } else if (!g_at_result_iter_next_number(&iter, &satype)) - return; - } + strncpy(ph.number, num, OFONO_MAX_PHONE_NUMBER_LENGTH); - ofono_cssu_notify(modem, code2, index, num, num_type); + if (!g_at_result_iter_next_number(&iter, &ph.type)) + return; + +out: + ofono_cssu_notify(modem, code2, index, &ph); } static struct ofono_voicecall_ops ops = { diff --git a/src/call-forwarding.c b/src/call-forwarding.c index 7b940be0..9cb378c7 100644 --- a/src/call-forwarding.c +++ b/src/call-forwarding.c @@ -122,8 +122,8 @@ static void cf_cond_list_print(GSList *list) ofono_debug("CF Condition status: %d, class: %d, number: %s," " number_type: %d, time: %d", - cond->status, cond->cls, cond->phone_number, - cond->number_type, cond->time); + cond->status, cond->cls, cond->phone_number.number, + cond->phone_number.type, cond->time); } } @@ -241,8 +241,7 @@ static void set_new_cond_list(struct ofono_modem *modem, int type, GSList *list) continue; timeout = lc->time; - number = phone_number_to_string(lc->phone_number, - lc->number_type); + number = phone_number_to_string(&lc->phone_number); sprintf(attr, "%s%s", bearer_class_to_string(lc->cls), cf_type_lut[type]); @@ -256,8 +255,9 @@ static void set_new_cond_list(struct ofono_modem *modem, int type, GSList *list) if (o) { /* On the old list, must be active */ oc = o->data; - if (oc->number_type != lc->number_type || - strcmp(oc->phone_number, lc->phone_number)) + if (oc->phone_number.type != lc->phone_number.type || + strcmp(oc->phone_number.number, + lc->phone_number.number)) dbus_gsm_signal_property_changed(conn, modem->path, CALL_FORWARDING_INTERFACE, @@ -276,8 +276,7 @@ static void set_new_cond_list(struct ofono_modem *modem, int type, GSList *list) g_free(o->data); old = g_slist_remove(old, o->data); } else { - number = phone_number_to_string(lc->phone_number, - lc->number_type); + number = phone_number_to_string(&lc->phone_number); dbus_gsm_signal_property_changed(conn, modem->path, CALL_FORWARDING_INTERFACE, @@ -365,8 +364,7 @@ static void property_append_cf_conditions(DBusMessageIter *dict, continue; } - number = phone_number_to_string(cf->phone_number, - cf->number_type); + number = phone_number_to_string(&cf->phone_number); property_append_cf_condition(dict, i, postfix, number, cf->time); @@ -581,26 +579,27 @@ static void set_property_callback(const struct ofono_error *error, void *data) static DBusMessage *set_property_request(struct ofono_modem *modem, DBusMessage *msg, int type, int cls, - const char *number, - int number_type, int timeout) + struct ofono_phone_number *ph, + int timeout) { struct call_forwarding_data *cf = modem->call_forwarding; - if (number[0] != '\0' && cf->ops->registration == NULL) + if (ph->number[0] != '\0' && cf->ops->registration == NULL) return dbus_gsm_not_implemented(msg); - if (number[0] == '\0' && cf->ops->erasure == NULL) + if (ph->number[0] == '\0' && cf->ops->erasure == NULL) return dbus_gsm_not_implemented(msg); cf->pending = dbus_message_ref(msg); cf->query_next = type; cf->query_end = type; - ofono_debug("Farming off request, will be erasure: %d", number[0] == 0); + ofono_debug("Farming off request, will be erasure: %d", + ph->number[0] == '\0'); - if (number[0] != '\0') - cf->ops->registration(modem, type, cls, number, number_type, - timeout, set_property_callback, modem); + if (ph->number[0] != '\0') + cf->ops->registration(modem, type, cls, ph, timeout, + set_property_callback, modem); else cf->ops->erasure(modem, type, cls, set_property_callback, modem); @@ -660,13 +659,15 @@ static DBusMessage *cf_set_property(DBusConnection *conn, DBusMessage *msg, c = l->data; return set_property_request(modem, msg, type, cls, - c->phone_number, - c->number_type, timeout); + &c->phone_number, timeout); } else if (cf_condition_enabled_property(cf, property, &type, &cls)) { + struct ofono_phone_number ph; const char *number; - int number_type; int timeout; + ph.number[0] = '\0'; + ph.type = 129; + if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING) return dbus_gsm_invalid_args(msg); @@ -676,14 +677,12 @@ static DBusMessage *cf_set_property(DBusConnection *conn, DBusMessage *msg, return dbus_gsm_invalid_format(msg); if (number[0] != '\0') - string_to_phone_number(number, &number_type, &number); - else - number_type = 129; + string_to_phone_number(number, &ph); timeout = cf_find_timeout(cf->cf_conditions[type], cls); - return set_property_request(modem, msg, type, cls, number, - number_type, timeout); + return set_property_request(modem, msg, type, cls, &ph, + timeout); } return dbus_gsm_invalid_args(msg); @@ -929,8 +928,7 @@ static gboolean cf_ss_control(struct ofono_modem *modem, int type, const char *s int timeout = DEFAULT_NO_REPLY_TIMEOUT; int cf_type; DBusMessage *reply; - const char *number; - int number_type; + struct ofono_phone_number ph; void *operation; /* Before we do anything, make sure we're actually initialized */ @@ -1083,10 +1081,9 @@ static gboolean cf_ss_control(struct ofono_modem *modem, int type, const char *s switch (cf->ss_req->ss_type) { case SS_CONTROL_TYPE_REGISTRATION: - string_to_phone_number(sia, &number_type, &number); - cf->ops->registration(modem, cf_type, cls, number, number_type, - timeout, cf_ss_control_callback, - modem); + string_to_phone_number(sia, &ph); + cf->ops->registration(modem, cf_type, cls, &ph, timeout, + cf_ss_control_callback, modem); break; case SS_CONTROL_TYPE_ACTIVATION: cf->ops->activation(modem, cf_type, cls, cf_ss_control_callback, diff --git a/src/common.c b/src/common.c index 6fb7c642..86534320 100644 --- a/src/common.c +++ b/src/common.c @@ -362,30 +362,31 @@ int mmi_service_code_to_bearer_class(int code) return cls; } -const char *phone_number_to_string(const char *number, int type) +const char *phone_number_to_string(const struct ofono_phone_number *ph) { static char buffer[64]; - if (type == 145 && (strlen(number) > 0) && number[0] != '+') { + if (ph->type == 145 && (strlen(ph->number) > 0) && + ph->number[0] != '+') { buffer[0] = '+'; - strncpy(buffer + 1, number, 62); + strncpy(buffer + 1, ph->number, 62); buffer[63] = '\0'; } else { - strncpy(buffer, number, 63); + strncpy(buffer, ph->number, 63); buffer[63] = '\0'; } return buffer; } -void string_to_phone_number(const char *str, int *type, const char **number) +void string_to_phone_number(const char *str, struct ofono_phone_number *ph) { if (strlen(str) && str[0] == '+') { - *number = &str[1]; - *type = 145; /* International */ + strcpy(ph->number, str+1); + ph->type = 145; /* International */ } else { - *number = &str[0]; - *type = 129; /* Local */ + strcpy(ph->number, str); + ph->type = 129; /* Local */ } } diff --git a/src/common.h b/src/common.h index 8fceaa26..90e245d9 100644 --- a/src/common.h +++ b/src/common.h @@ -173,8 +173,8 @@ enum ss_cssu { const char *telephony_error_to_str(const struct ofono_error *error); gboolean valid_phone_number_format(const char *number); -const char *phone_number_to_string(const char *number, int type); -void string_to_phone_number(const char *str, int *type, const char **number); +const char *phone_number_to_string(const struct ofono_phone_number *ph); +void string_to_phone_number(const char *str, struct ofono_phone_number *ph); int mmi_service_code_to_bearer_class(int code); diff --git a/src/cssn.c b/src/cssn.c index 9ffcf781..b85e4c86 100644 --- a/src/cssn.c +++ b/src/cssn.c @@ -161,7 +161,7 @@ void ofono_cssi_notify(struct ofono_modem *modem, int code1, int index) } void ofono_cssu_notify(struct ofono_modem *modem, int code2, int index, - const char *number, int number_type) + const struct ofono_phone_number *ph) { struct cssn_data *ss = modem->cssn; struct mt_handler *h; @@ -170,6 +170,6 @@ void ofono_cssu_notify(struct ofono_modem *modem, int code2, int index, for (l = ss->mt_handler_list; l; l = l->next) { h = l->data; if (h->code2 == (enum ss_cssu) code2) - h->cb(index, number, number_type, h->cb_data); + h->cb(index, ph, h->cb_data); } } diff --git a/src/cssn.h b/src/cssn.h index 5fff7bbe..f64da3f3 100644 --- a/src/cssn.h +++ b/src/cssn.h @@ -23,8 +23,8 @@ #define __CSSN_H__ typedef void (*mo_ss_notify_cb)(int index, void *userdata); -typedef void (*mt_ss_notify_cb)(int index, const char *num, int num_type, - void *userdata); +typedef void (*mt_ss_notify_cb)(int index, const struct ofono_phone_number *ph, + void *userdata); void ofono_cssn_init(struct ofono_modem *modem); void ofono_cssn_exit(struct ofono_modem *modem); diff --git a/src/driver.h b/src/driver.h index 3bc36bc7..bed53020 100644 --- a/src/driver.h +++ b/src/driver.h @@ -21,6 +21,12 @@ struct ofono_modem; +#define OFONO_MAX_PHONE_NUMBER_LENGTH 20 +struct ofono_phone_number { + char number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1]; + int type; +}; + /* 27.007 Section 6.2 */ enum ofono_clir_option { OFONO_CLIR_OPTION_DEFAULT = 0, @@ -54,15 +60,12 @@ enum ofono_disconnect_reason { OFONO_DISCONNECT_REASON_ERROR, }; -#define OFONO_MAX_PHONE_NUMBER_LENGTH 20 - struct ofono_call { unsigned id; int type; int direction; int status; - char phone_number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1]; - int number_type; + struct ofono_phone_number phone_number; int clip_validity; }; @@ -83,8 +86,7 @@ struct ofono_network_operator { struct ofono_cf_condition { int status; int cls; - char phone_number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1]; - int number_type; + struct ofono_phone_number phone_number; int time; }; @@ -94,11 +96,6 @@ struct ofono_cw_condition { int cls; }; -struct ofono_own_number { - char phone_number[OFONO_MAX_PHONE_NUMBER_LENGTH + 1]; - int number_type; -}; - /* Notification functions, the integer values here should map to * values obtained from the modem. The enumerations are the same * as the values for the fields found in 3GPP TS 27.007 @@ -168,8 +165,8 @@ typedef void (*ofono_sim_read_cb_t)(const struct ofono_error *error, typedef void (*ofono_imsi_cb_t)(const struct ofono_error *error, const char *imsi, void *data); -typedef void (*ofono_numbers_cb_t)(const struct ofono_error *error, - GSList *numbers, void *data); +typedef void (*ofono_numbers_cb_t)(const struct ofono_error *error, int num, + const struct ofono_phone_number *numbers, void *data); struct ofono_modem_attribute_ops { void (*query_manufacturer)(struct ofono_modem *modem, @@ -226,10 +223,10 @@ void ofono_network_registration_unregister(struct ofono_modem *modem); * not support vendor extensions for call progress indication. */ struct ofono_voicecall_ops { - void (*dial)(struct ofono_modem *modem, const char *number, - int number_type, enum ofono_clir_option clir, - enum ofono_cug_option cug, ofono_generic_cb_t cb, - void *data); + void (*dial)(struct ofono_modem *modem, + const struct ofono_phone_number *number, + enum ofono_clir_option clir, enum ofono_cug_option cug, + ofono_generic_cb_t cb, void *data); void (*answer)(struct ofono_modem *modem, ofono_generic_cb_t cb, void *data); void (*hangup)(struct ofono_modem *modem, @@ -252,8 +249,9 @@ struct ofono_voicecall_ops { ofono_generic_cb_t cb, void *data); void (*transfer)(struct ofono_modem *modem, ofono_generic_cb_t cb, void *data); - void (*deflect)(struct ofono_modem *modem, const char *number, - int number_type, ofono_generic_cb_t cb, void *data); + void (*deflect)(struct ofono_modem *modem, + const struct ofono_phone_number *ph, + ofono_generic_cb_t cb, void *data); void (*swap_without_accept)(struct ofono_modem *modem, ofono_generic_cb_t cb, void *data); void (*send_tones)(struct ofono_modem *modem, const char *tones, @@ -271,14 +269,14 @@ void ofono_voicecall_unregister(struct ofono_modem *modem); /* SSN notifications (CSSI and CSSU). */ void ofono_cssi_notify(struct ofono_modem *modem, int code, int index); void ofono_cssu_notify(struct ofono_modem *modem, int code, int index, - const char *number, int number_type); + const struct ofono_phone_number *number); struct ofono_call_forwarding_ops { void (*activation)(struct ofono_modem *modem, int type, int cls, ofono_generic_cb_t cb, void *data); void (*registration)(struct ofono_modem *modem, int type, int cls, - const char *number, int number_type, int time, - ofono_generic_cb_t cb, void *data); + const struct ofono_phone_number *number, + int time, ofono_generic_cb_t cb, void *data); void (*deactivation)(struct ofono_modem *modem, int type, int cls, ofono_generic_cb_t cb, void *data); void (*erasure)(struct ofono_modem *modem, int type, int cls, diff --git a/src/sim.c b/src/sim.c index 0fa13143..76b1010d 100644 --- a/src/sim.c +++ b/src/sim.c @@ -69,10 +69,12 @@ static void sim_manager_destroy(gpointer userdata) g_free(data->imsi); data->imsi = NULL; } + if (data->numbers) { dbus_gsm_free_string_array(data->numbers); data->numbers = NULL; } + if (data->spn) { g_free(data->spn); data->spn = NULL; @@ -220,26 +222,26 @@ static gboolean sim_retrieve_imsi(void *user_data) return FALSE; } -static void sim_own_number_cb(const struct ofono_error *error, GSList *numbers, - void *data) +static void sim_own_number_cb(const struct ofono_error *error, int num, + const struct ofono_phone_number *phs, void *data) { struct ofono_modem *modem = data; struct sim_manager_data *sim = modem->sim_manager; - GSList *l; - struct ofono_own_number *msisdn; char **number_str; + int i; if (error->type != OFONO_ERROR_TYPE_NO_ERROR) return; - sim->numbers = g_try_new0(char *, g_slist_length(numbers) + 1); + sim->numbers = g_try_new0(char *, num + 1); number_str = sim->numbers; - for (l = numbers; l; l = l->next) { - msisdn = l->data; - *number_str++ = g_strdup(phone_number_to_string( - msisdn->phone_number, - msisdn->number_type)); + for (i = 0; i < num; i++) { + if (phs[i].number[0] == '\0') + continue; + + *number_str = g_strdup(phone_number_to_string(&phs[i])); + number_str++; } } diff --git a/src/voicecall.c b/src/voicecall.c index 6d9ba87e..bbc7bf56 100644 --- a/src/voicecall.c +++ b/src/voicecall.c @@ -119,16 +119,16 @@ static const char *call_status_to_string(int status) } } -static const char *phone_and_clip_to_string(const char *number, int type, +static const char *phone_and_clip_to_string(const struct ofono_phone_number *n, int clip_validity) { - if (clip_validity == CLIP_VALIDITY_WITHHELD && !strlen(number)) + if (clip_validity == CLIP_VALIDITY_WITHHELD && !strlen(n->number)) return "withheld"; if (clip_validity == CLIP_VALIDITY_NOT_AVAILABLE) return ""; - return phone_number_to_string(number, type); + return phone_number_to_string(n); } static const char *time_to_str(const time_t *t) @@ -159,8 +159,7 @@ static DBusMessage *voicecall_get_properties(DBusConnection *conn, return NULL; status = call_status_to_string(call->status); - callerid = phone_number_to_string(call->phone_number, - call->number_type); + callerid = phone_number_to_string(&call->phone_number); dbus_message_iter_init_append(reply, &iter); @@ -221,8 +220,8 @@ static DBusMessage *voicecall_deflect(DBusConnection *conn, struct voicecalls_data *voicecalls = modem->voicecalls; struct ofono_call *call = v->call; + struct ofono_phone_number ph; const char *number; - int number_type; if (call->status != CALL_STATUS_INCOMING && call->status != CALL_STATUS_WAITING) @@ -244,10 +243,9 @@ static DBusMessage *voicecall_deflect(DBusConnection *conn, voicecalls->flags |= VOICECALLS_FLAG_PENDING; voicecalls->pending = dbus_message_ref(msg); - string_to_phone_number(number, &number_type, &number); + string_to_phone_number(number, &ph); - voicecalls->ops->deflect(modem, number, number_type, - generic_callback, voicecalls); + voicecalls->ops->deflect(modem, &ph, generic_callback, voicecalls); return NULL; } @@ -401,7 +399,7 @@ static void voicecall_set_call_status(struct ofono_modem *modem, static void voicecall_set_call_lineid(struct ofono_modem *modem, struct voicecall *v, - const char *number, int number_type, + const struct ofono_phone_number *ph, int clip_validity) { struct ofono_call *call = v->call; @@ -409,8 +407,8 @@ static void voicecall_set_call_lineid(struct ofono_modem *modem, const char *path; const char *lineid_str; - if (!strcmp(call->phone_number, number) && - call->number_type == number_type && + if (!strcmp(call->phone_number.number, ph->number) && + call->phone_number.type == ph->type && call->clip_validity == clip_validity) return; @@ -424,17 +422,16 @@ static void voicecall_set_call_lineid(struct ofono_modem *modem, clip_validity == CLIP_VALIDITY_NOT_AVAILABLE) return; - strcpy(call->phone_number, number); + strcpy(call->phone_number.number, ph->number); call->clip_validity = clip_validity; - call->number_type = number_type; + call->phone_number.type = ph->type; path = voicecall_build_path(modem, call); if (call->direction == CALL_DIRECTION_MOBILE_TERMINATED) - lineid_str = phone_and_clip_to_string(number, number_type, - clip_validity); + lineid_str = phone_and_clip_to_string(ph, clip_validity); else - lineid_str = phone_number_to_string(number, number_type); + lineid_str = phone_number_to_string(ph); dbus_gsm_signal_property_changed(conn, path, VOICECALL_INTERFACE, "LineIdentification", @@ -737,7 +734,7 @@ static DBusMessage *manager_dial(DBusConnection *conn, struct ofono_modem *modem = data; struct voicecalls_data *calls = modem->voicecalls; const char *number; - int number_type; + struct ofono_phone_number ph; const char *clirstr; enum ofono_clir_option clir; @@ -774,10 +771,9 @@ static DBusMessage *manager_dial(DBusConnection *conn, calls->flags |= VOICECALLS_FLAG_PENDING; calls->pending = dbus_message_ref(msg); - string_to_phone_number(number, &number_type, &number); + string_to_phone_number(number, &ph); - calls->ops->dial(modem, number, number_type, clir, - OFONO_CUG_OPTION_DEFAULT, + calls->ops->dial(modem, &ph, clir, OFONO_CUG_OPTION_DEFAULT, dial_callback, modem); return NULL; @@ -1244,7 +1240,7 @@ void ofono_voicecall_notify(struct ofono_modem *modem, const struct ofono_call * struct ofono_call *newcall = NULL; ofono_debug("Got a voicecall event, status: %d, id: %u, number: %s", - call->status, call->id, call->phone_number); + call->status, call->id, call->phone_number.number); l = g_slist_find_custom(calls->call_list, GINT_TO_POINTER(call->id), call_compare_by_id); @@ -1252,8 +1248,8 @@ void ofono_voicecall_notify(struct ofono_modem *modem, const struct ofono_call * if (l) { ofono_debug("Found call with id: %d\n", call->id); voicecall_set_call_status(modem, l->data, call->status); - voicecall_set_call_lineid(modem, l->data, call->phone_number, - call->number_type, call->clip_validity); + voicecall_set_call_lineid(modem, l->data, &call->phone_number, + call->clip_validity); return; } @@ -1358,7 +1354,6 @@ static struct ofono_call *synthesize_outgoing_call(struct ofono_modem *modem, DBusMessage *msg) { const char *number; - int number_type; struct ofono_call *call; call = g_try_new0(struct ofono_call, 1); @@ -1366,12 +1361,6 @@ static struct ofono_call *synthesize_outgoing_call(struct ofono_modem *modem, if (!call) return call; - if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number, - DBUS_TYPE_INVALID) == FALSE) - number = ""; - else - string_to_phone_number(number, &number_type, &number); - call->id = modem_alloc_callid(modem); if (call->id == 0) { @@ -1380,10 +1369,14 @@ static struct ofono_call *synthesize_outgoing_call(struct ofono_modem *modem, return NULL; } + if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &number, + DBUS_TYPE_INVALID) == FALSE) + number = ""; + else + string_to_phone_number(number, &call->phone_number); + call->direction = CALL_DIRECTION_MOBILE_ORIGINATED; call->status = CALL_STATUS_DIALING; - strcpy(call->phone_number, number); - call->number_type = number_type; call->clip_validity = CLIP_VALIDITY_VALID; return call;