static void toplevel_apndb_start(GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer userdata, GError **error) { struct apndb_data *apndb = userdata; struct apndb_provision_data *ap = NULL; int i; const gchar *carrier = NULL; const gchar *mcc = NULL; const gchar *mnc = NULL; const gchar *apn = NULL; const gchar *username = NULL; const gchar *password = NULL; const gchar *types = NULL; const gchar *protocol = NULL; const gchar *mmsproxy = NULL; const gchar *mmsport = NULL; const gchar *mmscenter = NULL; const gchar *mvnomatch = NULL; const gchar *mvnotype = NULL; enum ofono_gprs_proto proto = OFONO_GPRS_PROTO_IP; enum ofono_gprs_context_type type; if (!g_str_equal(element_name, "apn")) return; for (i = 0; attribute_names[i]; i++) { if (g_str_equal(attribute_names[i], "carrier")) carrier = attribute_values[i]; else if (g_str_equal(attribute_names[i], "mcc")) mcc = attribute_values[i]; else if (g_str_equal(attribute_names[i], "mnc")) mnc = attribute_values[i]; } if (mcc == NULL) { android_apndb_g_set_error(context, error, G_MARKUP_ERROR, G_MARKUP_ERROR_MISSING_ATTRIBUTE, "Missing attribute: mcc"); return; } if (mnc == NULL) { android_apndb_g_set_error(context, error, G_MARKUP_ERROR, G_MARKUP_ERROR_MISSING_ATTRIBUTE, "Missing attribute: mnc"); return; } if (g_str_equal(mcc, apndb->match_mcc) == FALSE || g_str_equal(mnc, apndb->match_mnc) == FALSE) return; for (i = 0; attribute_names[i]; i++) { if (g_str_equal(attribute_names[i], "apn")) apn = attribute_values[i]; else if (g_str_equal(attribute_names[i], "user")) username = attribute_values[i]; else if (g_str_equal(attribute_names[i], "password")) password = attribute_values[i]; else if (g_str_equal(attribute_names[i], "type")) types = attribute_values[i]; else if (g_str_equal(attribute_names[i], "protocol")) protocol = attribute_values[i]; else if (g_str_equal(attribute_names[i], "mmsc")) mmscenter = attribute_values[i]; else if (g_str_equal(attribute_names[i], "mmsproxy")) mmsproxy = attribute_values[i]; else if (g_str_equal(attribute_names[i], "mmsport")) mmsport = attribute_values[i]; else if (g_str_equal(attribute_names[i], "mvno_match_data")) mvnomatch = attribute_values[i]; else if (g_str_equal(attribute_names[i], "mvno_type")) mvnotype = attribute_values[i]; } if (apn == NULL) { android_apndb_g_set_error(context, error, G_MARKUP_ERROR, G_MARKUP_ERROR_MISSING_ATTRIBUTE, "APN attribute missing"); return; } if (types == NULL) { ofono_error("%s: apn for %s missing type attribute", __func__, carrier); return; } if (protocol != NULL) { if (g_str_equal(protocol, "IP")) { proto = OFONO_GPRS_PROTO_IP; } else if (g_str_equal(protocol, "IPV6")) { proto = OFONO_GPRS_PROTO_IPV6; } else if (g_str_equal(protocol, "IPV4V6")) { proto = OFONO_GPRS_PROTO_IPV4V6; } else { ofono_error("%s: APN %s has invalid protocol=%s" "attribute", __func__, carrier, protocol); return; } } if (mvnotype != NULL && mvnomatch != NULL) { if (g_str_equal(mvnotype, "imsi")) { DBG("APN %s is mvno_type 'imsi'", carrier); if (imsi_match(apndb->match_imsi, mvnomatch) == FALSE) { DBG("Skipping MVNO 'imsi' APN %s with" " match_data: %s", carrier, mvnomatch); return; } } else if (g_str_equal(mvnotype, "spn")) { DBG("APN %s is mvno_type 'spn'", carrier); if (g_str_equal(mvnomatch, apndb->match_spn) == FALSE) { DBG("Skipping mvno 'spn' APN %s with" " match_data: %s", carrier, mvnomatch); return; } } else if (g_str_equal(mvnotype, "gid")) { ofono_warn("%s: APN %s is unsupported mvno_type 'gid'", __func__, carrier); return; } } type = determine_apn_type(types); if (type == OFONO_GPRS_CONTEXT_TYPE_ANY || (type == OFONO_GPRS_CONTEXT_TYPE_MMS && mmsproxy == NULL)) { DBG("Skipping %s context; types: %s", apn, types); return; } ap = g_try_new0(struct apndb_provision_data, 1); if (ap == NULL) { ofono_error("%s: out-of-memory trying to provision APN - %s", __func__, carrier); return; } ap->gprs_data.type = type; if (carrier != NULL) ap->gprs_data.name = g_strdup(carrier); if (apn != NULL) ap->gprs_data.apn = g_strdup(apn); if (username != NULL) ap->gprs_data.username = g_strdup(username); if (password != NULL) ap->gprs_data.password = g_strdup(password); if (mmscenter != NULL && strlen(mmscenter) > 0) ap->gprs_data.message_center = g_strdup(mmscenter); if (mmsproxy != NULL && strlen(mmsproxy) > 0) { char *tmp = android_apndb_sanitize_ipv4_address(mmsproxy); if (tmp != NULL) mmsproxy = tmp; if (mmsport != NULL) ap->gprs_data.message_proxy = g_strdup_printf("%s:%s", mmsproxy, mmsport); else ap->gprs_data.message_proxy = g_strdup(mmsproxy); g_free(tmp); } ap->gprs_data.proto = proto; if (mvnotype != NULL) { ap->mvno = TRUE; apndb->mvno_found = TRUE; } apndb->apns = g_slist_append(apndb->apns, ap); }
static void toplevel_apndb_start(GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer userdata, GError **error) { struct apndb_data *apndb = userdata; struct apndb_provision_data *ap = NULL; int i; const gchar *carrier = NULL; const gchar *mcc = NULL; const gchar *mnc = NULL; const gchar *apn = NULL; const gchar *username = NULL; const gchar *password = NULL; const gchar *types = NULL; const gchar *protocol = NULL; const gchar *mmsproxy = NULL; const gchar *mmsport = NULL; const gchar *mmscenter = NULL; const gchar *mvnomatch = NULL; const gchar *mvnotype = NULL; enum ofono_gprs_proto proto = OFONO_GPRS_PROTO_IP; enum ofono_gprs_context_type type; if (g_strcmp0(element_name, "apn") != 0) return; for (i = 0; attribute_names[i]; i++) { if (g_strcmp0(attribute_names[i], "carrier") == 0) carrier = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "mcc") == 0) mcc = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "mnc") == 0) mnc = attribute_values[i]; } if (mcc == NULL) { ofono_error("%s: apn for %s missing 'mcc' attribute", __func__, carrier); return; } if (mnc == NULL) { ofono_error("%s: apn for %s missing 'mnc' attribute", __func__, carrier); return; } if (g_strcmp0(mcc, apndb->match_mcc) != 0 || g_strcmp0(mnc, apndb->match_mnc) != 0) return; for (i = 0; attribute_names[i]; i++) { if (g_strcmp0(attribute_names[i], "apn") == 0) apn = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "user") == 0) username = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "password") == 0) password = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "type") == 0) types = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "protocol") == 0) protocol = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "mmsc") == 0) mmscenter = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "mmsproxy") == 0) mmsproxy = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "mmsport") == 0) mmsport = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "mvno_match_data") == 0) mvnomatch = attribute_values[i]; else if (g_strcmp0(attribute_names[i], "mvno_type") == 0) mvnotype = attribute_values[i]; } if (apn == NULL) { ofono_error("%s: apn for %s missing 'apn' attribute", __func__, carrier); return; } if (types == NULL) { ofono_error("%s: apn for %s missing type attribute", __func__, carrier); return; } if (protocol != NULL) { if (g_strcmp0(protocol, "IP") == 0) { proto = OFONO_GPRS_PROTO_IP; } else if (g_strcmp0(protocol, "IPV6") == 0) { proto = OFONO_GPRS_PROTO_IPV6; } else if (g_strcmp0(protocol, "IPV4V6") == 0) { proto = OFONO_GPRS_PROTO_IPV4V6; } else { ofono_error("%s: APN %s has invalid protocol=%s" "attribute", __func__, carrier, protocol); return; } } if (mvnotype != NULL && mvnomatch != NULL) { if (g_strcmp0(mvnotype, "imsi") == 0) { DBG("APN %s is mvno_type 'imsi'", carrier); if (apndb->match_imsi == NULL || imsi_match(apndb->match_imsi, mvnomatch) == FALSE) { DBG("Skipping MVNO 'imsi' APN %s with" " match_data: %s", carrier, mvnomatch); return; } } else if (g_strcmp0(mvnotype, "spn") == 0) { DBG("APN %s is mvno_type 'spn'", carrier); if (g_strcmp0(mvnomatch, apndb->match_spn) != 0) { DBG("Skipping mvno 'spn' APN %s with" " match_data: %s", carrier, mvnomatch); return; } } else if (g_strcmp0(mvnotype, "gid") == 0) { int match_len = strlen(mvnomatch); DBG("APN %s is mvno_type 'gid'", carrier); /* Check initial part of GID1 against match data */ if (apndb->match_gid1 == NULL || g_ascii_strncasecmp(mvnomatch, apndb->match_gid1, match_len) != 0) { DBG("Skipping mvno 'gid' APN %s with" " match_data: %s", carrier, mvnomatch); return; } } } type = determine_apn_type(types); if (type == OFONO_GPRS_CONTEXT_TYPE_ANY || (type == OFONO_GPRS_CONTEXT_TYPE_MMS && mmscenter == NULL)) { DBG("Skipping %s context; types: %s", apn, types); return; } ap = g_try_new0(struct apndb_provision_data, 1); if (ap == NULL) { ofono_error("%s: out-of-memory trying to provision APN - %s", __func__, carrier); return; } ap->gprs_data.type = type; if (carrier != NULL) ap->gprs_data.name = g_strdup(carrier); if (apn != NULL) ap->gprs_data.apn = g_strdup(apn); if (username != NULL) ap->gprs_data.username = g_strdup(username); if (password != NULL) ap->gprs_data.password = g_strdup(password); if (mmscenter != NULL && strlen(mmscenter) > 0) ap->gprs_data.message_center = g_strdup(mmscenter); if (mmsproxy != NULL && strlen(mmsproxy) > 0) { char *tmp = ubuntu_apndb_sanitize_ipv4_address(mmsproxy); if (tmp != NULL) mmsproxy = tmp; if (mmsport != NULL) ap->gprs_data.message_proxy = g_strdup_printf("%s:%s", mmsproxy, mmsport); else ap->gprs_data.message_proxy = g_strdup(mmsproxy); g_free(tmp); } ap->gprs_data.proto = proto; if (mvnotype != NULL) { ap->mvno = TRUE; apndb->mvno_found = TRUE; } apndb->apns = g_slist_append(apndb->apns, ap); }