/
mbpi.c
772 lines (655 loc) · 19.2 KB
1
2
3
4
5
/*
*
* oFono - Open Source Telephony
*
* Copyright (C) 2008-2011 Intel Corporation. All rights reserved.
6
* Copyright (C) 2015-2020 Jolla Ltd.
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <glib.h>
#define OFONO_API_SUBJECT_TO_CHANGE
#include <ofono/modem.h>
#include <ofono/gprs-provision.h>
#ifndef MBPI_DATABASE
42
43
44
45
46
47
48
# ifdef PROVIDER_DATABASE
/* This one is pulled from mobile-broadband-provider-info.pc
* by the configure script, we should trust it. */
# define MBPI_DATABASE PROVIDER_DATABASE
# else
/* The default one */
# define MBPI_DATABASE "/usr/share/mobile-broadband-provider-info/" \
49
"serviceproviders.xml"
50
# endif
51
52
53
54
#endif
#include "mbpi.h"
55
const char *mbpi_database = MBPI_DATABASE;
56
57
58
59
60
61
/*
* Use IPv4 for MMS contexts because gprs.c assumes that MMS proxy
* address is IPv4.
*/
enum ofono_gprs_proto mbpi_default_internet_proto = OFONO_GPRS_PROTO_IPV4V6;
62
enum ofono_gprs_proto mbpi_default_mms_proto = OFONO_GPRS_PROTO_IP;
63
enum ofono_gprs_proto mbpi_default_ims_proto = OFONO_GPRS_PROTO_IPV4V6;
64
enum ofono_gprs_proto mbpi_default_proto = OFONO_GPRS_PROTO_IP;
65
66
67
enum ofono_gprs_auth_method mbpi_default_auth_method = OFONO_GPRS_AUTH_METHOD_ANY;
#define OFONO_GPRS_AUTH_METHOD_UNSPECIFIED ((enum ofono_gprs_auth_method)(-1))
68
69
70
#define _(x) case x: return (#x)
71
72
73
74
75
76
77
enum MBPI_ERROR {
MBPI_ERROR_DUPLICATE,
};
struct gsm_data {
const char *match_mcc;
const char *match_mnc;
78
char *provider_name;
79
gboolean provider_primary;
80
81
82
83
84
GSList *apns;
gboolean match_found;
gboolean allow_duplicates;
};
85
86
87
88
89
90
struct cdma_data {
const char *match_sid;
char *provider_name;
gboolean match_found;
};
91
92
93
94
95
96
97
98
99
100
101
102
103
const char *mbpi_ap_type(enum ofono_gprs_context_type type)
{
switch (type) {
_(OFONO_GPRS_CONTEXT_TYPE_ANY);
_(OFONO_GPRS_CONTEXT_TYPE_INTERNET);
_(OFONO_GPRS_CONTEXT_TYPE_MMS);
_(OFONO_GPRS_CONTEXT_TYPE_WAP);
_(OFONO_GPRS_CONTEXT_TYPE_IMS);
}
return "OFONO_GPRS_CONTEXT_TYPE_<UNKNOWN>";
}
104
105
106
107
108
static GQuark mbpi_error_quark(void)
{
return g_quark_from_static_string("ofono-mbpi-error-quark");
}
109
void mbpi_ap_free(struct ofono_gprs_provision_data *ap)
110
{
111
g_free(ap->provider_name);
112
113
114
115
116
117
118
119
g_free(ap->name);
g_free(ap->apn);
g_free(ap->username);
g_free(ap->password);
g_free(ap->message_proxy);
g_free(ap->message_center);
g_free(ap);
120
121
}
122
123
124
125
126
127
128
129
130
131
132
133
134
135
static void mbpi_g_set_error(GMarkupParseContext *context, GError **error,
GQuark domain, gint code, const gchar *fmt, ...)
{
va_list ap;
gint line_number, char_number;
g_markup_parse_context_get_position(context, &line_number,
&char_number);
va_start(ap, fmt);
*error = g_error_new_valist(domain, code, fmt, ap);
va_end(ap);
136
g_prefix_error(error, "%s:%d ", mbpi_database, line_number);
137
138
}
139
140
141
142
143
144
static void text_handler(GMarkupParseContext *context,
const gchar *text, gsize text_len,
gpointer userdata, GError **error)
{
char **string = userdata;
145
g_free(*string);
146
147
148
149
150
151
152
153
154
155
156
*string = g_strndup(text, text_len);
}
static const GMarkupParser text_parser = {
NULL,
NULL,
text_handler,
NULL,
NULL,
};
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
static void protocol_start(GMarkupParseContext *context,
const gchar **attribute_names,
const gchar **attribute_values,
enum ofono_gprs_proto *proto,
GError **error)
{
const char *text = NULL;
int i;
for (i = 0; attribute_names[i]; i++)
if (g_str_equal(attribute_names[i], "type") == TRUE)
text = attribute_values[i];
if (text == NULL) {
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
"Missing attribute: type");
return;
}
if (strcmp(text, "ip") == 0)
*proto = OFONO_GPRS_PROTO_IP;
else if (strcmp(text, "ipv6") == 0)
*proto = OFONO_GPRS_PROTO_IPV6;
else if (strcmp(text, "ipv4v6") == 0)
*proto = OFONO_GPRS_PROTO_IPV4V6;
else
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
"Unknown authentication method: %s",
text);
}
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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;
214
215
216
217
else if (strcmp(text, "any") == 0)
*auth_method = OFONO_GPRS_AUTH_METHOD_ANY;
else if (strcmp(text, "none") == 0)
*auth_method = OFONO_GPRS_AUTH_METHOD_NONE;
218
219
220
221
222
223
224
else
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
"Unknown authentication method: %s",
text);
}
225
226
static void usage_start(GMarkupParseContext *context,
const gchar **attribute_names,
227
const gchar **attribute_values,
228
struct ofono_gprs_provision_data *apn, GError **error)
229
{
230
231
232
233
234
235
236
237
const char *text = NULL;
int i;
for (i = 0; attribute_names[i]; i++)
if (g_str_equal(attribute_names[i], "type") == TRUE)
text = attribute_values[i];
if (text == NULL) {
238
239
240
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
"Missing attribute: type");
241
242
return;
}
243
244
245
246
247
248
249
if (strcmp(text, "internet") == 0) {
apn->type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
apn->proto = mbpi_default_internet_proto;
} else if (strcmp(text, "mms") == 0) {
apn->type = OFONO_GPRS_CONTEXT_TYPE_MMS;
apn->proto = mbpi_default_mms_proto;
250
251
252
} else if (strcmp(text, "ims") == 0) {
apn->type = OFONO_GPRS_CONTEXT_TYPE_IMS;
apn->proto = mbpi_default_ims_proto;
253
254
} else if (strcmp(text, "wap") == 0)
apn->type = OFONO_GPRS_CONTEXT_TYPE_WAP;
255
else
256
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
257
G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
258
"Unknown usage attribute: %s", text);
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
}
static void apn_start(GMarkupParseContext *context, const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer userdata, GError **error)
{
struct ofono_gprs_provision_data *apn = userdata;
if (g_str_equal(element_name, "name"))
g_markup_parse_context_push(context, &text_parser, &apn->name);
else if (g_str_equal(element_name, "username"))
g_markup_parse_context_push(context, &text_parser,
&apn->username);
else if (g_str_equal(element_name, "password"))
g_markup_parse_context_push(context, &text_parser,
&apn->password);
276
277
278
else if (g_str_equal(element_name, "protocol"))
protocol_start(context, attribute_names,
attribute_values, &apn->proto, error);
279
280
281
else if (g_str_equal(element_name, "authentication"))
authentication_start(context, attribute_names,
attribute_values, &apn->auth_method, error);
282
283
284
285
286
287
else if (g_str_equal(element_name, "mmsc"))
g_markup_parse_context_push(context, &text_parser,
&apn->message_center);
else if (g_str_equal(element_name, "mmsproxy"))
g_markup_parse_context_push(context, &text_parser,
&apn->message_proxy);
288
else if (g_str_equal(element_name, "usage"))
289
usage_start(context, attribute_names, attribute_values,
290
apn, error);
291
292
293
294
295
296
297
}
static void apn_end(GMarkupParseContext *context, const gchar *element_name,
gpointer userdata, GError **error)
{
if (g_str_equal(element_name, "name") ||
g_str_equal(element_name, "username") ||
298
299
300
g_str_equal(element_name, "password") ||
g_str_equal(element_name, "mmsc") ||
g_str_equal(element_name, "mmsproxy"))
301
302
303
304
305
306
307
308
309
310
311
g_markup_parse_context_pop(context);
}
static void apn_error(GMarkupParseContext *context, GError *error,
gpointer userdata)
{
/*
* Note that even if the error happened in a subparser, this will
* be called. So we always perform cleanup of the allocated
* provision data
*/
312
mbpi_ap_free(userdata);
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
}
static const GMarkupParser apn_parser = {
apn_start,
apn_end,
NULL,
NULL,
apn_error,
};
static const GMarkupParser skip_parser = {
NULL,
NULL,
NULL,
NULL,
NULL,
};
331
332
static void network_id_handler(GMarkupParseContext *context,
struct gsm_data *gsm,
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
const gchar **attribute_names,
const gchar **attribute_values,
GError **error)
{
const char *mcc = NULL, *mnc = NULL;
int i;
for (i = 0; attribute_names[i]; i++) {
if (g_str_equal(attribute_names[i], "mcc") == TRUE)
mcc = attribute_values[i];
if (g_str_equal(attribute_names[i], "mnc") == TRUE)
mnc = attribute_values[i];
}
if (mcc == NULL) {
348
349
350
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
"Missing attribute: mcc");
351
352
353
354
return;
}
if (mnc == NULL) {
355
356
357
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
"Missing attribute: mnc");
358
359
360
361
362
363
364
365
366
367
368
369
370
return;
}
if (g_str_equal(mcc, gsm->match_mcc) &&
g_str_equal(mnc, gsm->match_mnc))
gsm->match_found = TRUE;
}
static void apn_handler(GMarkupParseContext *context, struct gsm_data *gsm,
const gchar **attribute_names,
const gchar **attribute_values,
GError **error)
{
371
struct ofono_gprs_provision_data *ap;
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
const char *apn;
int i;
if (gsm->match_found == FALSE) {
g_markup_parse_context_push(context, &skip_parser, NULL);
return;
}
for (i = 0, apn = NULL; attribute_names[i]; i++) {
if (g_str_equal(attribute_names[i], "value") == FALSE)
continue;
apn = attribute_values[i];
break;
}
if (apn == NULL) {
389
390
391
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
"APN attribute missing");
392
393
394
return;
}
395
ap = g_new0(struct ofono_gprs_provision_data, 1);
396
ap->provider_name = g_strdup(gsm->provider_name);
397
398
ap->provider_primary = gsm->provider_primary;
399
400
ap->apn = g_strdup(apn);
ap->type = OFONO_GPRS_CONTEXT_TYPE_INTERNET;
401
ap->proto = mbpi_default_proto;
402
ap->auth_method = OFONO_GPRS_AUTH_METHOD_UNSPECIFIED;
403
404
g_markup_parse_context_push(context, &apn_parser, ap);
405
406
}
407
408
409
410
411
412
413
414
415
static void sid_handler(GMarkupParseContext *context,
struct cdma_data *cdma,
const gchar **attribute_names,
const gchar **attribute_values,
GError **error)
{
const char *sid = NULL;
int i;
416
417
418
419
420
421
422
for (i = 0; attribute_names[i]; i++) {
if (g_str_equal(attribute_names[i], "value") == FALSE)
continue;
sid = attribute_values[i];
break;
}
423
424
425
426
427
428
429
430
431
432
433
434
if (sid == NULL) {
mbpi_g_set_error(context, error, G_MARKUP_ERROR,
G_MARKUP_ERROR_MISSING_ATTRIBUTE,
"Missing attribute: sid");
return;
}
if (g_str_equal(sid, cdma->match_sid))
cdma->match_found = TRUE;
}
435
436
437
438
439
440
static void gsm_start(GMarkupParseContext *context, const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer userdata, GError **error)
{
if (g_str_equal(element_name, "network-id")) {
441
struct gsm_data *gsm = userdata;
442
443
444
445
446
447
448
449
/*
* For entries with multiple network-id elements, don't bother
* searching if we already have a match
*/
if (gsm->match_found == TRUE)
return;
450
451
network_id_handler(context, userdata, attribute_names,
attribute_values, error);
452
453
454
} else if (g_str_equal(element_name, "apn"))
apn_handler(context, userdata, attribute_names,
attribute_values, error);
455
456
457
458
459
}
static void gsm_end(GMarkupParseContext *context, const gchar *element_name,
gpointer userdata, GError **error)
{
460
struct gsm_data *gsm;
461
struct ofono_gprs_provision_data *ap;
462
463
464
if (!g_str_equal(element_name, "apn"))
return;
465
466
gsm = userdata;
467
468
469
ap = g_markup_parse_context_pop(context);
if (ap == NULL)
470
return;
471
472
473
474
475
476
477
478
479
480
481
482
/* Fix the authentication method if none was specified */
if (ap->auth_method == OFONO_GPRS_AUTH_METHOD_UNSPECIFIED) {
if ((!ap->username || !ap->username[0]) &&
(!ap->password || !ap->password[0])) {
/* No username or password => no authentication */
ap->auth_method = OFONO_GPRS_AUTH_METHOD_NONE;
} else {
ap->auth_method = mbpi_default_auth_method;
}
}
483
484
if (gsm->allow_duplicates == FALSE) {
GSList *l;
485
486
487
for (l = gsm->apns; l; l = l->next) {
struct ofono_gprs_provision_data *pd = l->data;
488
489
if (pd->type != ap->type)
490
continue;
491
492
493
494
mbpi_g_set_error(context, error, mbpi_error_quark(),
MBPI_ERROR_DUPLICATE,
"Duplicate context detected");
495
496
mbpi_ap_free(ap);
497
return;
498
499
}
}
500
501
gsm->apns = g_slist_append(gsm->apns, ap);
502
503
504
505
506
507
508
509
510
511
}
static const GMarkupParser gsm_parser = {
gsm_start,
gsm_end,
NULL,
NULL,
NULL,
};
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
static void cdma_start(GMarkupParseContext *context, const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer userdata, GError **error)
{
if (g_str_equal(element_name, "sid")) {
struct cdma_data *cdma = userdata;
/*
* For entries with multiple sid elements, don't bother
* searching if we already have a match
*/
if (cdma->match_found == TRUE)
return;
sid_handler(context, cdma, attribute_names, attribute_values,
error);
}
}
static const GMarkupParser cdma_parser = {
cdma_start,
NULL,
NULL,
NULL,
NULL,
};
static void provider_start(GMarkupParseContext *context,
const gchar *element_name,
const gchar **attribute_names,
const gchar **attribute_values,
gpointer userdata, GError **error)
{
if (g_str_equal(element_name, "name")) {
struct cdma_data *cdma = userdata;
g_free(cdma->provider_name);
cdma->provider_name = NULL;
g_markup_parse_context_push(context, &text_parser,
&cdma->provider_name);
} else if (g_str_equal(element_name, "gsm"))
g_markup_parse_context_push(context, &skip_parser, NULL);
else if (g_str_equal(element_name, "cdma"))
g_markup_parse_context_push(context, &cdma_parser, userdata);
}
static void provider_end(GMarkupParseContext *context,
const gchar *element_name,
gpointer userdata, GError **error)
{
if (g_str_equal(element_name, "name") ||
g_str_equal(element_name, "gsm") ||
g_str_equal(element_name, "cdma"))
g_markup_parse_context_pop(context);
}
static const GMarkupParser provider_parser = {
provider_start,
provider_end,
NULL,
NULL,
NULL,
};
577
static void gsm_provider_start(GMarkupParseContext *context,
578
const gchar *element_name,
579
const gchar **attribute_names,
580
581
582
583
584
const gchar **attribute_values,
gpointer userdata, GError **error)
{
struct gsm_data *gsm = userdata;
585
586
587
588
589
590
if (g_str_equal(element_name, "name")) {
g_free(gsm->provider_name);
gsm->provider_name = NULL;
g_markup_parse_context_push(context, &text_parser,
&gsm->provider_name);
} else if (g_str_equal(element_name, "gsm")) {
591
592
593
594
595
596
gsm->match_found = FALSE;
g_markup_parse_context_push(context, &gsm_parser, gsm);
} else if (g_str_equal(element_name, "cdma"))
g_markup_parse_context_push(context, &skip_parser, NULL);
}
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
static void gsm_provider_end(GMarkupParseContext *context,
const gchar *element_name,
gpointer userdata, GError **error)
{
if (g_str_equal(element_name, "name") ||
g_str_equal(element_name, "gsm") ||
g_str_equal(element_name, "cdma"))
g_markup_parse_context_pop(context);
}
static const GMarkupParser gsm_provider_parser = {
gsm_provider_start,
gsm_provider_end,
NULL,
NULL,
NULL,
};
static void toplevel_gsm_start(GMarkupParseContext *context,
const gchar *element_name,
617
const gchar **attribute_names,
618
619
620
621
622
const gchar **attribute_values,
gpointer userdata, GError **error)
{
struct gsm_data *gsm = userdata;
623
624
625
626
627
628
629
if (g_str_equal(element_name, "provider")) {
g_markup_collect_attributes(element_name, attribute_names,
attribute_values, error,
G_MARKUP_COLLECT_BOOLEAN | G_MARKUP_COLLECT_OPTIONAL,
"primary", &gsm->provider_primary,
G_MARKUP_COLLECT_INVALID);
630
g_markup_parse_context_push(context, &gsm_provider_parser, gsm);
631
}
632
633
}
634
static void toplevel_gsm_end(GMarkupParseContext *context,
635
636
637
const gchar *element_name,
gpointer userdata, GError **error)
{
638
if (g_str_equal(element_name, "provider"))
639
640
641
g_markup_parse_context_pop(context);
}
642
643
644
static const GMarkupParser toplevel_gsm_parser = {
toplevel_gsm_start,
toplevel_gsm_end,
645
646
647
648
649
NULL,
NULL,
NULL,
};
650
651
static void toplevel_cdma_start(GMarkupParseContext *context,
const gchar *element_name,
652
const gchar **attribute_names,
653
654
655
656
657
const gchar **attribute_values,
gpointer userdata, GError **error)
{
struct cdma_data *cdma = userdata;
658
659
660
661
662
663
664
if (g_str_equal(element_name, "provider") == FALSE)
return;
if (cdma->match_found == TRUE)
g_markup_parse_context_push(context, &skip_parser, NULL);
else
g_markup_parse_context_push(context, &provider_parser, cdma);
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
}
static void toplevel_cdma_end(GMarkupParseContext *context,
const gchar *element_name,
gpointer userdata, GError **error)
{
if (g_str_equal(element_name, "provider"))
g_markup_parse_context_pop(context);
}
static const GMarkupParser toplevel_cdma_parser = {
toplevel_cdma_start,
toplevel_cdma_end,
NULL,
NULL,
NULL,
};
683
684
static gboolean mbpi_parse(const GMarkupParser *parser, gpointer userdata,
GError **error)
685
686
687
688
{
struct stat st;
char *db;
int fd;
689
690
GMarkupParseContext *context;
gboolean ret;
691
692
fd = open(mbpi_database, O_RDONLY);
693
694
695
if (fd < 0) {
g_set_error(error, G_FILE_ERROR,
g_file_error_from_errno(errno),
696
"open(%s) failed: %s", mbpi_database,
697
g_strerror(errno));
698
return FALSE;
699
700
701
702
703
704
}
if (fstat(fd, &st) < 0) {
close(fd);
g_set_error(error, G_FILE_ERROR,
g_file_error_from_errno(errno),
705
"fstat(%s) failed: %s", mbpi_database,
706
g_strerror(errno));
707
return FALSE;
708
709
710
711
712
713
714
}
db = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (db == MAP_FAILED) {
close(fd);
g_set_error(error, G_FILE_ERROR,
g_file_error_from_errno(errno),
715
"mmap(%s) failed: %s", mbpi_database,
716
g_strerror(errno));
717
return FALSE;
718
719
}
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
context = g_markup_parse_context_new(parser,
G_MARKUP_TREAT_CDATA_AS_TEXT,
userdata, NULL);
ret = g_markup_parse_context_parse(context, db, st.st_size, error);
if (ret == TRUE)
g_markup_parse_context_end_parse(context, error);
munmap(db, st.st_size);
close(fd);
g_markup_parse_context_free(context);
return ret;
}
GSList *mbpi_lookup_apn(const char *mcc, const char *mnc,
gboolean allow_duplicates, GError **error)
{
struct gsm_data gsm;
GSList *l;
742
743
744
745
746
memset(&gsm, 0, sizeof(gsm));
gsm.match_mcc = mcc;
gsm.match_mnc = mnc;
gsm.allow_duplicates = allow_duplicates;
747
if (mbpi_parse(&toplevel_gsm_parser, &gsm, error) == FALSE) {
748
for (l = gsm.apns; l; l = l->next)
749
mbpi_ap_free(l->data);
750
751
752
753
754
g_slist_free(gsm.apns);
gsm.apns = NULL;
}
755
g_free(gsm.provider_name);
756
757
return gsm.apns;
}
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
char *mbpi_lookup_cdma_provider_name(const char *sid, GError **error)
{
struct cdma_data cdma;
memset(&cdma, 0, sizeof(cdma));
cdma.match_sid = sid;
if (mbpi_parse(&toplevel_cdma_parser, &cdma, error) == FALSE) {
g_free(cdma.provider_name);
cdma.provider_name = NULL;
}
return cdma.provider_name;
}