mbpi: add support for provisioning the auth method

Use the authentication method from the mobile-broadband-provider-info
database if it is specified and supported (we support CHAP and PAP).
Default to CHAP if the database does not specify a method (i.e.: the
previous behaviour).
This commit is contained in:
Philip Paeps 2014-06-24 11:57:05 +02:00 committed by Denis Kenzior
parent 310915429b
commit 532e8020e5
1 changed files with 35 additions and 0 deletions

View File

@ -128,6 +128,37 @@ static const GMarkupParser text_parser = {
NULL,
};
static void authentication_start(GMarkupParseContext *context,
const gchar **attribute_names,
const gchar **attribute_values,
enum ofono_gprs_auth_method *auth_method,
GError **error)
{
const char *text = NULL;
int i;
for (i = 0; attribute_names[i]; i++)
if (g_str_equal(attribute_names[i], "method") == TRUE)
text = attribute_values[i];
if (text == NULL) {
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
"Missing attribute: method");
return;
}
if (strcmp(text, "chap") == 0)
*auth_method = OFONO_GPRS_AUTH_METHOD_CHAP;
else if (strcmp(text, "pap") == 0)
*auth_method = OFONO_GPRS_AUTH_METHOD_PAP;
else
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
"Unknown authentication method: %s",
text);
}
static void usage_start(GMarkupParseContext *context,
const gchar **attribute_names,
const gchar **attribute_values,
@ -174,6 +205,9 @@ static void apn_start(GMarkupParseContext *context, const gchar *element_name,
else if (g_str_equal(element_name, "password"))
g_markup_parse_context_push(context, &text_parser,
&apn->password);
else if (g_str_equal(element_name, "authentication"))
authentication_start(context, attribute_names,
attribute_values, &apn->auth_method, error);
else if (g_str_equal(element_name, "mmsc"))
g_markup_parse_context_push(context, &text_parser,
&apn->message_center);
@ -291,6 +325,7 @@ static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm,
ap->apn = g_strdup(apn);
ap->type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
ap->proto = OFONO_GPRS_PROTO_IP;
ap->auth_method = OFONO_GPRS_AUTH_METHOD_CHAP;
g_markup_parse_context_push(context, &apn_parser, ap);
}