10 static struct uci_context
*ctx
;
11 static struct uci_package
*pkg
;
12 static struct list_head contact_list
;
13 static struct list_head account_list
;
15 static int contact_init(struct uci_map
*map
, void *section
,
16 struct uci_section
*s
)
18 struct contact
*p
= section
;
19 p
->name
= strdup(s
->e
.name
);
23 static int contact_add(struct uci_map
*map
, void *section
)
25 struct contact
*c
= section
;
26 printf("add contact: %s\n", c
->name
);
27 list_add_tail(&c
->head
, &contact_list
);
31 static struct uci_optmap contact_uci_map
[] = {
33 UCIMAP_OPTION(struct contact
, identifier
),
34 .type
= UCIMAP_STRING
,
38 UCIMAP_OPTION(struct contact
, number
),
39 .type
= UCIMAP_STRING
,
44 static struct uci_sectionmap contact_sectionmap
= {
45 UCIMAP_SECTION(struct contact
, map
),
49 .options
= contact_uci_map
,
50 .n_options
= ARRAY_SIZE(contact_uci_map
),
51 .options_size
= sizeof(struct uci_optmap
),
54 static int account_init(struct uci_map
*map
, void *section
,
55 struct uci_section
*s
)
57 struct account
*a
= section
;
58 a
->name
= strdup(s
->e
.name
);
62 static int account_add(struct uci_map
*map
, void *section
)
64 struct account
*a
= section
;
65 list_add_tail(&a
->head
, &account_list
);
69 static struct uci_optmap account_uci_map
[] = {
71 UCIMAP_OPTION(struct account
, realm
),
72 .type
= UCIMAP_STRING
,
76 UCIMAP_OPTION(struct account
, username
),
77 .type
= UCIMAP_STRING
,
81 UCIMAP_OPTION(struct account
, sip_port
),
86 UCIMAP_OPTION(struct account
, password
),
87 .type
= UCIMAP_STRING
,
91 UCIMAP_OPTION(struct account
, stun_host
),
92 .type
= UCIMAP_STRING
,
96 UCIMAP_OPTION(struct account
, stun_port
),
102 static struct uci_sectionmap account_sectionmap
= {
103 UCIMAP_SECTION(struct account
, map
),
105 .init
= account_init
,
107 .options
= account_uci_map
,
108 .n_options
= ARRAY_SIZE(account_uci_map
),
109 .options_size
= sizeof(struct uci_optmap
),
112 static struct uci_sectionmap
*network_smap
[] = {
117 static struct uci_map contact_map
= {
118 .sections
= network_smap
,
119 .n_sections
= ARRAY_SIZE(network_smap
),
122 int contacts_init(void)
126 INIT_LIST_HEAD(&contact_list
);
127 INIT_LIST_HEAD(&account_list
);
128 ctx
= uci_alloc_context();
130 ucimap_init(&contact_map
);
131 ret
= uci_load(ctx
, "telephony", &pkg
);
135 ucimap_parse(&contact_map
, pkg
);
140 void contacts_free(void)
144 struct contact
*contact_get(const char *number
)
146 struct contact
*contact
;
147 list_for_each_entry(contact
, &contact_list
, head
)
149 if (strcmp(contact
->number
, number
) == 0)
156 struct account
*get_account(void)
158 if (list_empty(&account_list
))
161 return list_first_entry(&account_list
, struct account
, head
);