summaryrefslogtreecommitdiff
path: root/src/libgsmd/libgsmd_phonebook.c
blob: c569e02c10d99b640ab290d2a5502c950a70affc (plain)
1
2
3
4
5
6
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include <libgsmd/libgsmd.h>
#include <libgsmd/misc.h>
#include <libgsmd/phonebook.h>

#include <gsmd/usock.h>
#include <gsmd/event.h>

#include "lgsm_internals.h"

int lgsm_pb_find_entry(struct lgsm_handle *lh, 
		const struct lgsm_phonebook_find *pb_find)
{
	struct gsmd_msg_hdr *gmh;
	struct gsmd_phonebook_find *gpf;
	int rc;

	gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
			GSMD_PHONEBOOK_FIND, sizeof(*gpf));
	if (!gmh)
		return -ENOMEM;
	gpf = (struct gsmd_phonebook_find *)gmh->data;
	memcpy(gpf->findtext, pb_find->findtext, sizeof(gpf->findtext));
	gpf->findtext[sizeof(gpf->findtext)-1] = '\0';

	rc = lgsm_send(lh, gmh);
	if (rc < gmh->len + sizeof(*gmh)) {
		lgsm_gmh_free(gmh);;
		return -EIO;
	}

	lgsm_gmh_free(gmh);

	return 0;
}

int lgsm_pb_read_entry(struct lgsm_handle *lh, int index)
{
	struct gsmd_msg_hdr *gmh;
	int rc;

	gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
			GSMD_PHONEBOOK_READ, sizeof(int));
	if (!gmh)
		return -ENOMEM;
	*(int *) gmh->data = index;

	rc = lgsm_send(lh, gmh);
	if (rc < gmh->len + sizeof(*gmh)) {
		lgsm_gmh_free(gmh);;
		return -EIO;
	}

	lgsm_gmh_free(gmh);

	return 0;
}

int lgsm_pb_read_entryies(struct lgsm_handle *lh, 
		const struct lgsm_phonebook_readrg *pb_readrg)
{
	struct gsmd_msg_hdr *gmh;
	struct gsmd_phonebook_readrg *gpr;
	int rc;

	gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
			GSMD_PHONEBOOK_READRG, sizeof(*gpr));
	if (!gmh)
		return -ENOMEM;
	gpr = (struct gsmd_phonebook_readrg *) gmh->data;
	gpr->index1 = pb_readrg->index1;
	gpr->index2 = pb_readrg->index2;

	rc = lgsm_send(lh, gmh);
	if (rc < gmh->len + sizeof(*gmh)) {
		lgsm_gmh_free(gmh);;
		return -EIO;
	}

	lgsm_gmh_free(gmh);

	return 0;
}

int lgsmd_pb_del_entry(struct lgsm_handle *lh, int index)
{
	struct gsmd_msg_hdr *gmh;
	int rc;

	gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
			GSMD_PHONEBOOK_DELETE, sizeof(int));
	if (!gmh)
		return -ENOMEM;

	*(int *)(gmh->data) = index;

	rc = lgsm_send(lh, gmh);
	if (rc < gmh->len + sizeof(*gmh)) {
		lgsm_gmh_free(gmh);
		return -EIO;
	}

	lgsm_gmh_free(gmh);

	return 0;
}

int lgsmd_pb_write_entry(struct lgsm_handle *lh, 
		const struct lgsm_phonebook *pb)
{
	/* FIXME: only support alphabet now */
	struct gsmd_msg_hdr *gmh;
	struct gsmd_phonebook *gp;
	int rc;

	gmh = lgsm_gmh_fill(GSMD_MSG_PHONEBOOK,
			GSMD_PHONEBOOK_WRITE, sizeof(*gp));
	if (!gmh)
		return -ENOMEM;
	gp = (struct gsmd_phonebook *) gmh->data;
	gp->index = pb->index;
	memcpy(gp->numb, pb->numb, sizeof(gp->numb));
	gp->numb[sizeof(gp->numb)-1] = '\0';
	gp->type = pb->type;
	memcpy(gp->text, pb->text, sizeof(gp->text));
	gp->text[sizeof(gp->text)-1] = '\0';

	rc = lgsm_send(lh, gmh);
	if (rc < gmh->len + sizeof(*gmh)) {
		lgsm_gmh_free(gmh);;
		return -EIO;
	}

	lgsm_gmh_free(gmh);

	return 0;
}


int lgsm_pb_get_support(struct lgsm_handle *lh)
{
	return lgsm_send_simple(lh, GSMD_MSG_PHONEBOOK, GSMD_PHONEBOOK_GET_SUPPORT);
}
personal git repositories of Harald Welte. Your mileage may vary