summaryrefslogtreecommitdiff
path: root/packages/gsm/files/028_shell-phonebook-find-and-read-range-support.patch
blob: db07a5df358778aa58cbfe79baf08c1fd51fa664 (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
147
148
149
150
151
152
153
154
155
156
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
From: Sean Chiang <sean_chiang@openmoko.com>
Subject: [PATCH] improvement for find and read phonebooks in shell

This patch improves the functions to find and read phonebooks in shell.

Besides prr and pf, I add two new commands pRr and pRf to retrieve the
phonebook.

Signed-off-by: Jim Huang <jserv@openmoko.org>

Index: gsm/src/util/shell.c
===================================================================
--- gsm.orig/src/util/shell.c	2007-09-17 23:57:51.000000000 +0800
+++ gsm/src/util/shell.c	2007-09-17 23:59:04.000000000 +0800
@@ -34,8 +34,6 @@
 #include <gsmd/usock.h>
 #include <gsmd/ts0705.h>
 
-#include <common/linux_list.h>
-
 #ifndef __GSMD__
 #define __GSMD__
 #include <gsmd/talloc.h>
@@ -43,9 +41,8 @@
 #endif
 
 #define STDIN_BUF_SIZE	1024
-
-static LLIST_HEAD(storage_list);
-static LLIST_HEAD(phonebook_list);
+static int nFIND = 0;
+static int nREADRG = 0;
 
 /* this is the handler for receiving passthrough responses */
 static int pt_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
@@ -62,46 +59,23 @@
 	struct gsmd_phonebook_storage *gpst;
 	char *payload;
 	char *fcomma, *lcomma, *ptr = NULL;
+	int *num;
 	char buf[128];
+	int i;
 
 	switch (gmh->msg_subtype) {
-#if 0
 	case GSMD_PHONEBOOK_FIND:		
+		num = (int *) ((char *)gmh + sizeof(*gmh));
+		printf("Records:%d\n", *num);
+
+		nFIND = *num;
+		break;
 	case GSMD_PHONEBOOK_READRG:
-		payload = (char *)gmh + sizeof(*gmh);
+		num = (int *) ((char *)gmh + sizeof(*gmh));
+		printf("Records:%d\n", *num);
 
-		if (!strncmp(payload, "+CPBR", 5) ||
-				!strncmp(payload, "+CPBF", 5)) {
-			gp = (struct gsmd_phonebook *) malloc(sizeof(struct gsmd_phonebook));
-			ptr = strchr(payload, ' ');
-	                gp->index = atoi(ptr+1);
-
-	                fcomma = strchr(payload, '"');
-	                lcomma = strchr(fcomma+1, '"');
-	                strncpy(gp->numb, fcomma + 1, (lcomma-fcomma-1));
-	                gp->numb[(lcomma - fcomma) - 1] = '\0';
-
-	                gp->type = atoi(lcomma + 2);
-
-	                ptr = strrchr(payload, ',');
-	                fcomma = ptr + 1;
-	                lcomma = strchr(fcomma + 1, '"');
-	                strncpy(gp->text, fcomma + 1, (lcomma - fcomma - 1));
-	                gp->text[(lcomma - fcomma) - 1] = '\0';
-
-			llist_add_tail(&gp->list, &phonebook_list);
-
-#if 0
-			llist_for_each_entry(gp, &phonebook_list, list) {
-				printf("%d, %s, %d, %s\n", gp->index, gp->numb, gp->type, gp->text);
-			}
-#endif
-			printf("%d, %s, %d, %s\n", gp->index, gp->numb, gp->type, gp->text);
-		}
-		else
-			printf("%s\n", payload);
+		nREADRG = *num;
 		break;
-#endif
 	case GSMD_PHONEBOOK_READ:
 		gp = (struct gsmd_phonebook *) ((char *)gmh + sizeof(*gmh));
 		if (gp->index)
@@ -115,48 +89,18 @@
 		gps = (struct gsmd_phonebook_support *) ((char *)gmh + sizeof(*gmh));
 		printf("(1-%d), %d, %d\n", gps->index, gps->nlength, gps->tlength);
 		break;
-#if 0
-	case GSMD_PHONEBOOK_LIST_STORAGE:
-		payload = (char *)gmh + sizeof(*gmh);
 
-		if (!strncmp(payload, "+CPBS", 5)) {
-			char* delim = "(,";
-			struct gsmd_phonebook_storage *cur, *cur2;
-
-			/* Remove previous record */
-			if (!llist_empty(&storage_list)) {
-				llist_for_each_entry_safe(cur, cur2,
-						&storage_list, list) {
-					llist_del(&cur->list);
-					talloc_free(cur);
-				}
-			}
-
-			ptr = strpbrk(payload, delim);
-
-			while ( ptr ) {
-				gpst = (struct gsmd_phonebook_storage *) malloc(sizeof(struct gsmd_phonebook_storage));
-				strncpy(gpst->storage, ptr+2, 2);
-				gpst->storage[2] = '\0';
-
-				ptr = strpbrk(ptr+2, delim);
-
-				llist_add_tail(&gpst->list, &storage_list);
-			}
+	case GSMD_PHONEBOOK_LIST_STORAGE:
+		gpst = (struct gsmd_phonebook_storage *)((char *)gmh + sizeof(*gmh));
 
-			if (llist_empty(&storage_list))
-				return 0;
+		for (i = 0; i < gpst->num; i++) {
+			printf("%s, ", gpst->mem[i].type);
+		}
 
-			llist_for_each_entry(cur, &storage_list, list) {
-				printf("\n%s",cur->storage);
-			}
+		printf("\n");
 
-			printf("\n");
-		}
-		else
-			printf("%s\n", payload);
 		break;
-#endif
+
 	case GSMD_PHONEBOOK_WRITE:
 	case GSMD_PHONEBOOK_DELETE:
 	case GSMD_PHONEBOOK_SET_STORAGE:
@@ -164,6 +108,26 @@
 		payload = (char *)gmh + sizeof(*gmh);
 		printf("%s\n", payload);
 		break;
+	case GSMD_PHONEBOOK_RETRIEVE_READRG:
+		gp = (struct gsmd_phonebook *) ((char *)gmh + sizeof(*gmh));
+
+		for (i=0; i<nREADRG; i++) {
+			printf("%d,%s,%d,%s\n", gp->index, gp->numb, gp->type, gp->text);
+			gp++;
+		}
+
+		nREADRG = 0;
+		break;
+	case GSMD_PHONEBOOK_RETRIEVE_FIND:
+		gp = (struct gsmd_phonebook *) ((char *)gmh + sizeof(*gmh));
+
+		for (i = 0; i < nFIND; i++) {
+			printf("%d,%s,%d,%s\n", gp->index, gp->numb, gp->type, gp->text);
+			gp++;
+		}
+
+		nFIND = 0;
+		break;
 	default:
 		return -EINVAL;
 	}	
@@ -381,11 +345,13 @@
 		"\tpd\tPB Delete (pb=index)\n"
 		"\tpr\tPB Read (pr=index)\n"
 		"\tprr\tPB Read Range (prr=index1,index2)\n"
-		"\tpf\tPB Find (pff=indtext)\n"
+		"\tpf\tPB Find (pf=indtext)\n"
 		"\tpw\tPB Write (pw=index,number,text)\n"
 		"\tps\tPB Support\n"
 		"\tpm\tPB Memory\n"
 		"\tpp\tPB Set Memory (pp=storage)\n"
+		"\tpRr\tRetrieve Readrg Records\n"
+		"\tpRf\tRetrieve Find Records\n"
 		"\tsd\tSMS Delete (sd=index,delflg)\n"
 		"\tsl\tSMS List (sl=stat)\n"
 		"\tsr\tSMS Read (sr=index)\n"
@@ -509,48 +475,21 @@
 				printf("Delete Phonebook Entry\n");				
 				ptr = strchr(buf, '=');
 				lgsm_pb_del_entry(lgsmh, atoi(ptr+1));
-#if 0
 			} else if ( !strncmp(buf, "prr", 3)) {	
 				printf("Read Phonebook Entries\n");
 				struct lgsm_phonebook_readrg pb_readrg;
-				struct gsmd_phonebook *gp_cur, *gp_cur2;
-
-				/* Remove records */
-				if (!llist_empty(&phonebook_list)) {
-					llist_for_each_entry_safe(gp_cur,
-							gp_cur2,
-							&phonebook_list,
-							list) {
-						llist_del(&gp_cur->list);
-						talloc_free(gp_cur);
-					}
-				}
 
 				ptr = strchr(buf, '=');
 				pb_readrg.index1 = atoi(ptr+1);				
 				ptr = strchr(buf, ',');
 				pb_readrg.index2 = atoi(ptr+1);
 				lgsm_pb_read_entries(lgsmh, &pb_readrg);
-#endif
 			} else if ( !strncmp(buf, "pr", 2)) {
 				ptr = strchr(buf, '=');
 				lgsm_pb_read_entry(lgsmh, atoi(ptr+1));
-#if 0
 			} else if ( !strncmp(buf, "pf", 2)) {
 				printf("Find Phonebook Entry\n");
 				struct lgsm_phonebook_find pb_find;
-				struct gsmd_phonebook *gp_cur, *gp_cur2;
-
-				/* Remove records */
-				if (!llist_empty(&phonebook_list)) {
-					llist_for_each_entry_safe(gp_cur,
-							gp_cur2,
-							&phonebook_list,
-							list) {
-						llist_del(&gp_cur->list);
-						talloc_free(gp_cur);
-					}
-				}
 
 				ptr = strchr(buf, '=');
 				strncpy(pb_find.findtext,
@@ -559,7 +498,6 @@
 				pb_find.findtext[strlen(ptr+1)] = '\0';	
 			
 				lgsm_pb_find_entry(lgsmh, &pb_find);
-#endif
 			} else if ( !strncmp(buf, "pw", 2)) {
 				printf("Write Phonebook Entry\n");
 				struct lgsm_phonebook pb;
@@ -591,6 +529,16 @@
 			} else if ( !strncmp(buf, "ps", 2)) {	
 				printf("Get Phonebook Support\n");
 				lgsm_pb_get_support(lgsmh);
+			} else if( !strncmp(buf, "pRr", 3) ) {
+				printf("Retrieve Readrg Records\n");
+
+				if ( nREADRG )
+					lgsm_pb_retrieve_readrg(lgsmh, nREADRG);
+			} else if( !strncmp(buf, "pRf", 3) ) {
+				printf("Retrieve Find Records\n");
+
+				if ( nFIND )
+					lgsm_pb_retrieve_find(lgsmh, nFIND);
 			} else if ( !strncmp(buf, "sd", 2)) {		
 				printf("Delete SMS\n");			
 				struct lgsm_sms_delete sms_del;