blob: e62abf653e4d11fcd5bc370ddab23ff6763b7d04 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/************************************************************************
2* °æÈ¨ËùÓÐ (C)2010, ÉîÛÚÊÐÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
3*
4* ÎļþÃû³Æ£º zte_web_pbm.c
5* Îļþ±êʶ£º
6* ÄÚÈÝÕªÒª£º
7* ÆäËü˵Ã÷£º
8* µ±Ç°°æ±¾£º V0.1
9* ×÷ Õߣº zyt
10* Íê³ÉÈÕÆÚ£º 2010-11-06
11*
12* Ð޸ļǼ1£º
13* ÐÞ¸ÄÄÚÈÝ£º³õʼ°æ±¾
14************************************************************************/
15
16#include "zte_web_interface.h"
17//#include "../../phonebook/phonebook.h"
18#include "zte_web_get_fw_para.h"
19#include "zte_web_pbm.h"
20
21static void zte_web_pbm_feed_back_empty(webs_t wp);
22
23#define IFSTREQUAL(str1, str2) (strcmp((str1), (str2))?0:1)
24
25int zte_web_pbm_check_can_process()
26{
27 char flag[20] = {0};
28
29 (void)zte_web_read(ZTE_PBM_NV, flag);
30 if (0 == strcmp(flag, PBM_OPRATING)) {
31 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_check_can_process flag=%s, not can process.\n", flag);
32 return 0;
33 } else {
34 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_check_can_process flag=%s, can process.\n", flag);
35 return -1;
36 }
37}
38
39static data_safe_result_type_t zte_Safe_noSpecialChar_ucs2(char *str)
40{
41 int i = 0;
42 int len = 0;
43 if (NULL == str || strlen(str) < 4) {
44 return 0;
45 }
46 len = strlen(str);
47 for (i = 0; i < len; i=i+4) {
48 if (str[i] == '0' && str[i+1] == '0') {
49 if(str[i+2] == '2') {//"'/
50 if(str[i+3] == '2' || str[i+3] == '7' || str[i+3] == 'f' || str[i+3] == 'F')
51 return 0;
52 } else if(str[i+2] == '3') {//<>
53 if(str[i+3] == 'c' || str[i+3] == 'C' || str[i+3] == 'e' || str[i+3] == 'E')
54 return 0;
55 } else if(str[i+2] == '5') {//\
56 if(str[i+3] == 'c' || str[i+3] == 'C')
57 return 0;
58 }
59 }
60 }
61 return 1;
62
63}
64
65/**********************************************************************
66* Function: zte_web_pbm_contact_saveto_sim
67* Description:
68* Input: wp:web para;sim_contact_location:save location
69* Output:
70* Return: void
71* Others:
72* Modify Date Version Author Modification
73* -----------------------------------------------
74* 20120926 V1.0 liuyingnan first version
75**********************************************************************/
76static void zte_web_pbm_contact_saveto_sim(webs_t wp, int sim_contact_location)
77{
78 /*contact added type*/
79 zte_pbm_create_ext_record_s_type sim_contact_add;
80 int ret_code = 0;
81 //add by liuyingnan for server safe start
82 char* pbm_name = NULL;
83 char* pbm_mobilephone_num = NULL;
84 //add by liuyingnan for server safe end
85
86 /*LOG*/
87 slog(MISC_PRINT, SLOG_DEBUG, "zte_web_pbm->zte_web_pbm_contact_saveto_sim()."); /*lint !e26*/
88
89 /*check input*/
90 if (NULL == wp) {
91 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_goform_pbm_contact_add_process(): invalid input.."); /*lint !e26*/
92 return;
93 }
94
95 //add by liuyingnan for server safe for xss attack start
96 pbm_name = websGetVar(wp, T("name"), T(""));
97 pbm_mobilephone_num = websGetVar(wp, T("mobilephone_num"), T(""));
98
99 if (PBM_MAX_TEXT_LENGTH < strlen(pbm_name) || PBM_MAX_NUM_LENGTH < strlen(pbm_mobilephone_num)
100 ||DATA_NO_SAFE == zte_Safe_noSpecialChar_ucs2(pbm_name)
101 || DATA_NO_SAFE == zte_Safe_noSpecialChar(pbm_mobilephone_num)
102 ) {
103 slog(MISC_PRINT, SLOG_ERR, "Get Data is no Safe:pbm_name:%s\n", pbm_name); /*lint !e26*/
104 cfg_set("data_safe", "failed");
105 zte_write_result_to_web(wp, FAILURE);
106 return;
107 }
108 //add by liuyingnan for server safe for xss attack end
109
110 /*init contact_add*/
111 memset(&sim_contact_add, 0, sizeof(sim_contact_add));
112 /*set struct value*/
113 sim_contact_add.zte_pbm_del_id = atoi(websGetVar(wp, T("delId"), T("-1")));
114 sim_contact_add.zte_pbm_location = sim_contact_location;
115 sim_contact_add.zte_pbm_id = atoi(websGetVar(wp, T("edit_index"), T("")));
116
117 memcpy(sim_contact_add.zte_pbm_name, websGetVar(wp, T("name"), T("")),
118 sizeof(sim_contact_add.zte_pbm_name));
119 memcpy(sim_contact_add.zte_pbm_number, websGetVar(wp, T("mobilephone_num"), T("")),
120 sizeof(sim_contact_add.zte_pbm_number));
121 memcpy(sim_contact_add.zte_pbm_anr, websGetVar(wp, T("homephone_num"), T("")),
122 sizeof(sim_contact_add.zte_pbm_anr));
123 memcpy(sim_contact_add.zte_pbm_anr1, websGetVar(wp, T("officephone_num"), T("")),
124 sizeof(sim_contact_add.zte_pbm_anr1));
125 memcpy(sim_contact_add.zte_pbm_email, websGetVar(wp, T("email"), T("")),
126 sizeof(sim_contact_add.zte_pbm_email));
127 memcpy(sim_contact_add.zte_pbm_sne, websGetVar(wp, T("nick_name"), T("")),
128 sizeof(sim_contact_add.zte_pbm_sne));
129 if (sim_contact_add.zte_pbm_number[ZTE_WEB_PBM_NUMBER_TYPE_START] ==
130 ZTE_WEB_PBM_NUMBER_TYPE_SPLIT) {
131 sim_contact_add.zte_pbm_type = ZTE_WEB_PBM_NUMBER_TYPE_1;
132 } else {
133 sim_contact_add.zte_pbm_type = ZTE_WEB_PBM_NUMBER_TYPE_2;
134 }
135 slog(MISC_PRINT, SLOG_DEBUG, "zte_web_pbm_contact_saveto_sim:send messsage to mc start"); /*lint !e26*/
136 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.zte_pbm_id:%d", sim_contact_add.zte_pbm_id); /*lint !e26*/
137 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.name:%s", sim_contact_add.zte_pbm_name); /*lint !e26*/
138 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.mobilephone_num:%s", sim_contact_add.zte_pbm_number); /*lint !e26*/
139 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.zte_pbm_type:%d", sim_contact_add.zte_pbm_type); /*lint !e26*/
140
141 /*send msg to mc*/
142 //ret_code = zte_send_message(ZUFI_MODULE_ID_AT_LOCAL,ZTE_PBM_WRITE_REC_MSG, sizeof(sim_contact_add), (char*)&sim_contact_add);
143 (void)zte_web_write(ZTE_PBM_NV, PBM_OPRATING);
144 ret_code = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PB, MSG_CMD_WRITE_PB, sizeof(sim_contact_add), (char*)&sim_contact_add, 0);
145 if (ret_code != 0) {
146 slog(MISC_PRINT, SLOG_ERR, "mc lib relay pbm send create modify record fail"); /*lint !e26*/
147 (void)zte_web_write(ZTE_PBM_NV, "14");
148 zte_write_result_to_web(wp, FAILURE);
149 return;
150 }
151
152 slog(MISC_PRINT, SLOG_NORMAL, "zte_web_pbm_contact_saveto_sim:send messsage to mc end"); /*lint !e26*/
153 /*goto web page*/
154 zte_write_result_to_web(wp, "success");
155 return;
156}
157/**********************************************************************
158* Function: zte_web_pbm_contact_saveto_pc
159* Description: wp:web para;pc_contact_location:save location
160* Input: null
161* Output: null
162* Return: void
163* Others:
164* Modify Date Version Author Modification
165* -----------------------------------------------
166* 20120926 V1.0 liuyingnan first version
167**********************************************************************/
168static void zte_web_pbm_contact_saveto_pc(webs_t wp, int pc_contact_location)
169{
170 /*contact added type*/
171 zte_pbm_create_ext_record_s_type pc_contact_add;
172 int ret_code = 0;
173 //add by liuyingnan for server safe start
174 char* pbm_name = NULL;
175 char* pbm_mobilephone_num = NULL;
176 //add by liuyingnan for server safe end
177 /*LOG*/
178 slog(MISC_PRINT, SLOG_DEBUG, "zte_web_pbm->zte_web_pbm_contact_saveto_pc()."); /*lint !e26*/
179 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_contact_saveto_pc entry\n");
180 /*check input*/
181 if (NULL == wp) {
182 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_contact_saveto_pc(): invalid input.."); /*lint !e26*/
183 return;
184 }
185 //add by liuyingnan for server safe for xss attack start
186 pbm_name = websGetVar(wp, T("name"), T(""));
187 pbm_mobilephone_num = websGetVar(wp, T("mobilephone_num"), T(""));
188 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_contact_saveto_pc entry1\n");
189 if (PBM_MAX_TEXT_LENGTH < strlen(pbm_name) || PBM_MAX_NUM_LENGTH < strlen(pbm_mobilephone_num)
190 ||DATA_NO_SAFE == zte_Safe_noSpecialChar_ucs2(pbm_name)
191 || DATA_NO_SAFE == zte_Safe_noSpecialChar(pbm_mobilephone_num)
192 ) {
193 slog(MISC_PRINT, SLOG_ERR, "Get Data is no Safe:pbm_name:%s\n", pbm_name); /*lint !e26*/
194 cfg_set("data_safe", "failed");
195 zte_write_result_to_web(wp, FAILURE);
196 return;
197 }
198 //add by liuyingnan for server safe for xss attack end
199 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_contact_saveto_pc entry2\n");
200 /*init contact_add*/
201 memset(&pc_contact_add, 0, sizeof(pc_contact_add));
202 /*set struct value*/
203 pc_contact_add.zte_pbm_del_id = atoi(websGetVar(wp, T("delId"), T("-1")));
204 pc_contact_add.zte_pbm_location = pc_contact_location;
205 pc_contact_add.zte_pbm_id = atoi(websGetVar(wp, T("add_index_pc"), T("")));
206 memcpy(pc_contact_add.zte_pbm_name, websGetVar(wp, T("name"), T("")),
207 sizeof(pc_contact_add.zte_pbm_name));
208 memcpy(pc_contact_add.zte_pbm_number, websGetVar(wp, T("mobilephone_num"), T("")),
209 sizeof(pc_contact_add.zte_pbm_number));
210 memcpy(pc_contact_add.zte_pbm_anr, websGetVar(wp, T("homephone_num"), T("")),
211 sizeof(pc_contact_add.zte_pbm_anr));
212 memcpy(pc_contact_add.zte_pbm_anr1, websGetVar(wp, T("officephone_num"), T("")),
213 sizeof(pc_contact_add.zte_pbm_anr1));
214 memcpy(pc_contact_add.zte_pbm_email, websGetVar(wp, T("email"), T("")),
215 sizeof(pc_contact_add.zte_pbm_email));
216 memcpy(pc_contact_add.zte_pbm_sne, websGetVar(wp, T("nick_name"), T("")),
217 sizeof(pc_contact_add.zte_pbm_sne));
218 memcpy(pc_contact_add.zte_pbm_group, websGetVar(wp, T("groupchoose"), T("")),
219 sizeof(pc_contact_add.zte_pbm_group));
220
221 if (pc_contact_add.zte_pbm_number[ZTE_WEB_PBM_NUMBER_TYPE_START] ==
222 ZTE_WEB_PBM_NUMBER_TYPE_SPLIT) {
223 pc_contact_add.zte_pbm_type = ZTE_WEB_PBM_NUMBER_TYPE_1;
224 } else {
225 pc_contact_add.zte_pbm_type = ZTE_WEB_PBM_NUMBER_TYPE_2;
226 }
227 slog(MISC_PRINT, SLOG_DEBUG, "zte_web_pbm_contact_saveto_pc:send messsage to mc start"); /*lint !e26*/
228 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.zte_pbm_id:%d", pc_contact_add.zte_pbm_id); /*lint !e26*/
229 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.name:%s", pc_contact_add.zte_pbm_name); /*lint !e26*/
230 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.mobilephone_num:%s", pc_contact_add.zte_pbm_number); /*lint !e26*/
231 slog(MISC_PRINT, SLOG_DEBUG, "sim_contact_add.zte_pbm_type:%d", pc_contact_add.zte_pbm_type); /*lint !e26*/
232 printf("[PB] zte_web_pbm_contact_saveto_pc entry3\n");
233 /*send msg to mc*/
234 //ret_code = zte_send_message(ZUFI_MODULE_ID_AT_LOCAL,ZTE_PBM_WRITE_REC_MSG, sizeof(pc_contact_add), (char*)&pc_contact_add);
235 (void)zte_web_write(ZTE_PBM_NV, PBM_OPRATING);
236 ret_code = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PB, MSG_CMD_WRITE_PB, sizeof(pc_contact_add), (char*)&pc_contact_add, 0);
237 if (ret_code != 0) {
238 slog(MISC_PRINT, SLOG_ERR, "mc lib relay pbm send create modify record fail"); /*lint !e26*/
239 (void)zte_web_write(ZTE_PBM_NV, "14");
240 zte_write_result_to_web(wp, FAILURE);
241 return;
242 }
243 printf("zte_web_pbm_contact_saveto_pc:%d,%d,%d,%d\n", ret_code, MODULE_ID_WEB_CGI, MODULE_ID_PB, MSG_CMD_WRITE_PB);
244 slog(MISC_PRINT, SLOG_NORMAL, "zte_web_pbm_contact_saveto_pc:send messsage to mc end"); /*lint !e26*/
245 /*goto web page*/
246 zte_write_result_to_web(wp, "success");
247}
248
249/**********************************************************************
250* Function: zte_web_pbm_utils_parseStr
251* Description:
252* Input:
253* Output:
254* Return: void
255* Others:
256* Modify Date Version Author Modification
257* -----------------------------------------------
258* 20120409 V1.0 chenyi first version
259**********************************************************************/
260static int zte_web_pbm_utils_parseStr
261(
262 char *input, char *output, int srcLen, int destLen, char separator
263)
264{
265 /*index*/
266 int input_ind = 0;
267 int dest_ind = 0;
268 int all_ind = 0;
269
270 /*check input*/
271 if (NULL == input || NULL == output || srcLen == 0 || destLen == 0) {
272 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_utils_parseStr():invalid input."); /*lint !e26*/
273 return 0;
274 }
275
276 /*handler*/
277 for (input_ind = 0; input_ind < srcLen; input_ind++) {
278 if ('\0' == input[input_ind]) {
279 *(output + destLen * dest_ind + all_ind) = '\0';
280 return dest_ind + 1;
281 }
282
283 if (separator == input[input_ind]) {
284 *(output + destLen * dest_ind + all_ind) = '\0';
285 if ('\0' != input[input_ind + 1]) {
286 all_ind = 0;
287 dest_ind++;
288 }
289 } else {
290 *(output + destLen * dest_ind + all_ind) = input[input_ind];
291 all_ind++;
292 }
293 }
294
295 /*return value*/
296 return dest_ind;
297}
298
299
300/**********************************************************************
301* Function: zte_web_pbm_contact_del_part
302* Description:
303* Input: web para
304* Output:
305* Return: void
306* Others: reason of error.
307* Others:
308* Modify Date Version Author Modification
309* -----------------------------------------------
310* 20120409 V1.0 chenyi first version
311**********************************************************************/
312static void zte_web_pbm_contact_del_part(webs_t wp)
313{
314 int ret_code = 0;
315 /*deleted index get from page*/
316 char del_index[PBM_WEB_MAX_CHAR_LEN] = {0};
317 /*split deleted index*/
318 char split_index[ZTE_PB_INDEX_MAX][ZTE_WEB_PBM_REC_LEN];
319 /*flag of contact number*/
320 /*index for for circle*/
321 int num_ind = 0;
322 /*data struct */
323 zte_pbm_del_multi_records_s_type sendto_data;
324
325 /*check input*/
326 if (NULL == wp) {
327 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_contact_del_part(): invalid input.."); /*lint !e26*/
328 return;
329 }
330
331 /*init*/
332 memset(del_index, 0, sizeof(del_index));
333 memset(&sendto_data, 0, sizeof(sendto_data));
334 memset(split_index, 0, sizeof(split_index));
335
336 /*set data struct*/
337 //sendto_data.zte_del_pbm_location = atoi(websGetVar(wp,T("savelocation1"), T("")));
338 memcpy(del_index, websGetVar(wp, T("delete_id"), T("")), sizeof(del_index));
339 sendto_data.zte_del_pbm_total = zte_web_pbm_utils_parseStr(del_index, (char *)split_index,
340 (int)ZTE_PB_INDEX_MAX, (int)ZTE_WEB_PBM_REC_LEN, (char)ZTE_WEB_PBM_INDEX_SPLIT_FLAG);
341 slog(MISC_PRINT, SLOG_DEBUG,"liuyingnan sendto_data.zte_del_pbm_total:%d", sendto_data.zte_del_pbm_total); /*lint !e26*/
342
343 /*del one contact*/
344 if (ZTE_WEB_PBM_DEL_MULT_OR_ONE_FLAG == sendto_data.zte_del_pbm_total) {
345 sendto_data.zte_del_pbm_id[ZTE_WEB_PBM_DEL_ONE_IND] = atoi(split_index[ZTE_WEB_PBM_DEL_ONE_IND]);
346
347#if 0
348 if (-1 == zte_mc_relay_pbm_del_one_record(&sendto_data)) {
349 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_contact_del_part():delete one contact failed."); /*lint !e26*/
350 zte_write_result_to_web(wp, FAILURE);
351 return;
352 }
353#endif
354 slog(MISC_PRINT, SLOG_NORMAL, "zte_web_pbm_contact_del_part:send messsage start"); /*lint !e26*/
355 //ret_code = zte_send_message(ZUFI_MODULE_ID_AT_LOCAL,ZTE_PBM_DEL_A_REC_MSG, sizeof(sendto_data), (char*)&sendto_data);
356 ret_code = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PB, MSG_CMD_DEL_A_PB, sizeof(sendto_data), (char*)&sendto_data, 0);
357 slog(MISC_PRINT, SLOG_DEBUG, "zte_web_pbm_contact_del_part:send messsage end"); /*lint !e26*/
358 if (ret_code != 0) {
359 slog(MISC_PRINT, SLOG_ERR, "mc lib relay pbm send DEL A record fail"); /*lint !e26*/
360 zte_write_result_to_web(wp, FAILURE);
361 return;
362 }
363 } else {
364 /*handler*/
365 for (num_ind = 0; num_ind < sendto_data.zte_del_pbm_total; num_ind ++) {
366 sendto_data.zte_del_pbm_id[num_ind] = atoi(split_index[num_ind]);
367 printf("zte_web_pbm->zte_web_pbm_contact_del_part():split_index=[%d]", sendto_data.zte_del_pbm_id[num_ind]); /*lint !e26*/
368 }
369
370 /*handler*/
371#if 0
372 if (-1 == zte_mc_relay_pbm_del_multi_record(&sendto_data)) {
373 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_contact_del_part():delete mult contact failed."); /*lint !e26*/
374 zte_write_result_to_web(wp, FAILURE);
375 return;
376 }
377#endif
378 //ret_code = zte_send_message(ZUFI_MODULE_ID_AT_LOCAL,ZTE_PBM_DEL_MUTI_REC_MSG, sizeof(sendto_data), (char*)&sendto_data);
379 ret_code = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PB, MSG_CMD_DEL_MUTI_PB, sizeof(sendto_data), (char*)&sendto_data, 0);
380 if (ret_code != 0) {
381 slog(MISC_PRINT, SLOG_ERR, "mc lib relay pbm send DEL MUTI record fail"); /*lint !e26*/
382 zte_write_result_to_web(wp, FAILURE);
383 return;
384 }
385 }
386 /*goto differ page*/
387 (void)zte_web_write(ZTE_PBM_NV, PBM_OPRATING);
388 zte_write_result_to_web(wp, "success");
389 //zte_web_pbm_goto_diff_page(wp,sendto_data.zte_del_pbm_location);
390}
391/**********************************************************************
392* Function: zte_web_pbm_contact_del_all
393* Description:
394* Input: web para
395* Output: null
396* Return: void
397* Others: reason of error.
398* Others:
399* Modify Date Version Author Modification
400* -----------------------------------------------
401* 20120409 V1.0 chenyi first version
402**********************************************************************/
403static void zte_web_pbm_contact_del_all(webs_t wp)
404{
405 int ret_code = 0;
406 /*data struct*/
407 zte_pbm_del_multi_records_s_type sendto_data;
408
409 /*check input*/
410 if (NULL == wp) {
411 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_contact_del_all(): invalid input.."); /*lint !e26*/
412 return;
413 }
414
415 /*init*/
416 memset(&sendto_data, 0, sizeof(sendto_data));
417
418 /*set data struct*/
419 sendto_data.zte_del_pbm_location = atoi(websGetVar(wp, T("del_all_location"), T("")));
420 slog(MISC_PRINT, SLOG_DEBUG, "liuyingnan sendto_data.zte_del_pbm_location:%d", sendto_data.zte_del_pbm_location); /*lint !e26*/
421
422 /*handler del all*/
423 //(void)zte_mc_relay_pbm_del_all_record(&sendto_data);
424 slog(MISC_PRINT, SLOG_NORMAL, "zte_web_pbm_contact_del_all:send messsage start"); /*lint !e26*/
425 //ret_code = zte_send_message(ZUFI_MODULE_ID_AT_LOCAL,ZTE_PBM_DEL_ALL_REC_MSG, sizeof(sendto_data), (char*)&sendto_data);
426 ret_code = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PB, MSG_CMD_DEL_ALL_PB, sizeof(sendto_data), (char*)&sendto_data, 0);
427 slog(MISC_PRINT, SLOG_DEBUG, "zte_web_pbm_contact_del_all:send messsage end"); /*lint !e26*/
428 if (ret_code != 0) {
429 slog(MISC_PRINT, SLOG_ERR, "mc lib relay pbm send DEL ALL record fail"); /*lint !e26*/
430 zte_write_result_to_web(wp, FAILURE);
431 return;
432 }
433 /*goto differ page*/
434 (void)zte_web_write(ZTE_PBM_NV, PBM_OPRATING);
435 zte_write_result_to_web(wp, "success");
436 //zte_web_pbm_goto_diff_page(wp,sendto_data.zte_del_pbm_location);
437}
438/**********************************************************************
439* Function: zte_web_pbm_contact_del_by_group
440* Description:
441* Input: web para
442* Output:
443* Return: void
444* Others: reason of error.
445* Others:
446* Modify Date Version Author Modification
447* -----------------------------------------------
448* 20120711 V1.0 chenyi first version
449**********************************************************************/
450static void zte_web_pbm_contact_del_by_group(webs_t wp)
451{
452 int ret_code = 0;
453 zte_pbm_del_multi_records_s_type sendto_data;
454 char *group = NULL;
455
456 /*check input*/
457 if (NULL == wp) {
458 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_contact_del_by_group(): invalid input.."); /*lint !e26*/
459 return;
460 }
461
462 /*init*/
463 memset(&sendto_data, 0, sizeof(zte_pbm_del_multi_records_s_type));
464
465 group = websGetVar(wp, T("del_group"), T(""));
466 slog(MISC_PRINT, SLOG_DEBUG, "liuyingnan group:%s", group); /*lint !e26*/
467 if (0 == strcmp(group, "")) {
468 slog(MISC_PRINT, SLOG_ERR, "pbm:group is empty.\n"); /*lint !e26*/
469 zte_write_result_to_web(wp, FAILURE);
470 return;
471 }
472
473 /*set data struct*/
474 sendto_data.zte_del_pbm_location = atoi(websGetVar(wp, T("del_all_location"), T("0")));
475 slog(MISC_PRINT, SLOG_DEBUG, "liuyingnan sendto_data.zte_del_pbm_location:%d", sendto_data.zte_del_pbm_location); /*lint !e26*/
476
477 if (ZTE_NVIO_DONE != zte_web_write("pbm_group", group)) {
478 slog(MISC_PRINT, SLOG_ERR, "write the nv [pbm_group] failure.\n"); /*lint !e26*/
479 zte_write_result_to_web(wp, FAILURE);
480 return;
481 }
482
483 (void)zte_web_write(ZTE_PBM_NV, PBM_OPRATING);
484
485#if 0
486 if (ZTE_MC_OK_S != zte_mc_relay_pbm_del_all_record(&sendto_data)) {
487 slog(MISC_PRINT, SLOG_ERR, "call zte_mc_relay_pbm_del_all_record fail.\n"); /*lint !e26*/
488 zte_write_result_to_web(wp, FAILURE);
489 } else {
490 zte_write_result_to_web(wp, SUCCESS);
491 }
492#endif
493 slog(MISC_PRINT, SLOG_NORMAL, "zte_web_pbm_contact_del_by_group:send messsage start"); /*lint !e26*/
494 //ret_code = zte_send_message(ZUFI_MODULE_ID_AT_LOCAL,ZTE_PBM_DEL_ALL_REC_MSG, sizeof(sendto_data), (char*)&sendto_data);
495 ret_code = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_PB, MSG_CMD_DEL_ALL_PB, sizeof(sendto_data), (char*)&sendto_data, 0);
496 slog(MISC_PRINT, SLOG_DEBUG, "zte_web_pbm_contact_del_by_group:send messsage end"); /*lint !e26*/
497 if (ret_code != 0) {
498 slog(MISC_PRINT, SLOG_ERR, "mc lib relay pbm send DEL record by group fail"); /*lint !e26*/
499 zte_write_result_to_web(wp, FAILURE);
500 return;
501 }
502
503 zte_write_result_to_web(wp, "success");
504}
505
506
507/**********************************************************************
508* Function: zte_goform_pbm_contact_add_process
509* Description:
510* Input: null
511* Output: null
512* Return: void
513* Others:
514* Modify Date Version Author Modification
515* -----------------------------------------------
516* 20120926 V1.0 liuyingnan first version
517**********************************************************************/
518void zte_goform_pbm_contact_add_process(webs_t wp)
519{
520 /*contact location*/
521 int contact_location = 0;
522
523 /*check input*/
524 if (NULL == wp) {
525 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_goform_pbm_contact_add_process(): invalid input.."); /*lint !e26*/
526 return;
527 }
528
529 if (0 == zte_web_pbm_check_can_process()) {
530 zte_write_result_to_web(wp, FAILURE);
531 return;
532 }
533
534 /*get the saved mem*/
535 contact_location = atoi(websGetVar(wp, T("location"), T("")));
536 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_check_can_process contact_location=%d, can process.\n", contact_location);
537 /*goto different mem handler*/
538 switch (contact_location) {
539 case ZTE_WEB_PBM_CONTACT_SIM: { /*goto sim mem handler*/
540 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_check_can_process sim=%d, can process.\n", ZTE_WEB_PBM_CONTACT_SIM);
541 zte_web_pbm_contact_saveto_sim(wp, ZTE_WEB_PBM_CONTACT_SIM);
542 break;
543 }
544 case ZTE_WEB_PBM_CONTACT_PC: { /*goto pc mem handler*/
545 slog(MISC_PRINT, SLOG_DEBUG,"[PB] zte_web_pbm_check_can_process pc=%d, can process.\n", ZTE_WEB_PBM_CONTACT_PC);
546 zte_web_pbm_contact_saveto_pc(wp, ZTE_WEB_PBM_CONTACT_PC);
547 break;
548 }
549
550 default: { /*unknown mem*/
551 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_goform_pbm_contact_add_process():unknown pbm mem."); /*lint !e26*/
552 zte_write_result_to_web(wp, FAILURE);
553 }
554 }
555}
556
557void zte_goform_pbm_contact_del_process(webs_t wp)
558{
559 /*check input*/
560 if (NULL == wp) {
561 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_web_pbm_contact_del_all(): invalid input.."); /*lint !e26*/
562 return;
563 }
564
565 if (0 == zte_web_pbm_check_can_process()) {
566 zte_write_result_to_web(wp, FAILURE);
567 return;
568 }
569
570 /*del the given index contact in specified mem*/
571 if (0 == strcmp(websGetVar(wp, T("del_option"), T("")), ZTE_WEB_PBM_PAGE_DEL_PART)) {
572 zte_web_pbm_contact_del_part(wp);
573 }
574
575 /*del all the contact in specified mem*/
576 else if (0 == strcmp(websGetVar(wp, T("del_option"), T("")), ZTE_WEB_PBM_PAGE_DEL_ALL)) {
577 zte_web_pbm_contact_del_all(wp);
578 }
579 //delete the pbm data by group
580 else if (0 == strcmp(websGetVar(wp, T("del_option"), T("")), ZTE_WEB_PBM_DEL_BY_GROUP)) {
581 zte_web_pbm_contact_del_by_group(wp);
582 }
583
584 else {
585 slog(MISC_PRINT, SLOG_ERR, "zte_web_pbm->zte_goform_pbm_contact_del_process():unknown pbm del."); /*lint !e26*/
586 zte_write_result_to_web(wp, FAILURE);
587 }
588
589}
590
591
592/**********************************************************************
593* Function: zte_get_pbm_data
594* Description: to get the pbm data info
595* Input: the web para
596* Output:
597* Return:
598* Others:
599* Modify Date Version Author Modification
600* -----------------------------------------------
601* 2012/04/10 V1.0 chenyi first version
602**********************************************************************/
603void zte_get_pbm_data(webs_t wp)
604{
605 zte_pbm_query_req_s_type pbm_query_req;
606 zte_pbm_query_resp_s_type *p_pbm_query_result = NULL;
607 int result = 0;
608 int i = 0;
609 char_t *page = NULL;
610 char_t *data_per_page = NULL;
611 char_t *mem_store = NULL;
612
613 memset(&pbm_query_req, 0, sizeof(zte_pbm_query_req_s_type));
614
615 page = websGetVar(wp, "page", T(""));
616 data_per_page = websGetVar(wp, "data_per_page", T(""));
617 mem_store = websGetVar(wp, "mem_store", T(""));
618
619 if (('\0' == *page) || ('\0' == *data_per_page) || ('\0' == *mem_store)) {
620 slog(MISC_PRINT, SLOG_ERR, "zte_get_pbm_data: invalid web para.\n"); /*lint !e26*/
621 zte_web_pbm_feed_back_empty(wp);
622 return ;
623 }
624 int tmp_page = atoi(page);
625 int tmp_num_per_page = atoi(data_per_page);
626 int location = atoi(mem_store);
627 if((tmp_page < 0 || tmp_page > 255)
628 ||(tmp_num_per_page < 0 || tmp_num_per_page > 255)
629 ||(location < PBM_LOCATION_SIM || location > PBM_LOCATION_MAX)){
630 slog(MISC_PRINT, SLOG_ERR, "zte_get_pbm_data:err[%d,%d,%d]\n", tmp_page,tmp_num_per_page,location); /*lint !e26*/
631 zte_web_pbm_feed_back_empty(wp);
632 return ;
633 }
634 pbm_query_req.page = (uint8)tmp_page;
635 pbm_query_req.num_per_page = (uint8)tmp_num_per_page;
636 pbm_query_req.location = (zte_pbm_location_e_type)location; //0:sim;1:device
637
638 slog(MISC_PRINT, SLOG_DEBUG, "pbm_query_req:[%u,%u,%d].\n", pbm_query_req.page, pbm_query_req.num_per_page, pbm_query_req.location); /*lint !e26*/
639
640 p_pbm_query_result = (zte_pbm_query_resp_s_type*)malloc(4 + sizeof(zte_pbm_create_ext_record_s_type) * (pbm_query_req.num_per_page));
641 if (NULL == p_pbm_query_result) {
642 slog(MISC_PRINT, SLOG_ERR, "malloc pbm result mem fail.\n"); /*lint !e26*/
643 zte_web_pbm_feed_back_empty(wp);
644 return ;/*lint !e429*/
645 }
646
647 memset(p_pbm_query_result, 0, (4 + sizeof(zte_pbm_create_ext_record_s_type) * (pbm_query_req.num_per_page))); /*lint !e668*/
648
649 slog(MISC_PRINT, SLOG_DEBUG, "GET PBM DATA FROM DB START.\n"); /*lint !e26*/
650 result = zte_libpbm_get_rec_data(&pbm_query_req, p_pbm_query_result);
651 slog(MISC_PRINT, SLOG_DEBUG, "GET PBM DATA FROM DB END.\n"); /*lint !e26*/
652
653 if (-1 == result) {
654 slog(MISC_PRINT, SLOG_ERR, "call zte_libpbm_get_rec_data fail.\n"); /*lint !e26*/
655 zte_web_pbm_feed_back_empty(wp);
656 //free
657// if (NULL != p_pbm_query_result) { // kw 3
658 free(p_pbm_query_result);
659 p_pbm_query_result = NULL;
660// }
661 return ;
662 }
663
664 slog(MISC_PRINT, SLOG_DEBUG, "total query count [%u].\n", (*p_pbm_query_result).count); /*lint !e26*/
665
666 if (0 == (*p_pbm_query_result).count) {
667 zte_web_pbm_feed_back_empty(wp);
668 //free
669// if (NULL != p_pbm_query_result) { kw 3
670 free(p_pbm_query_result);
671 p_pbm_query_result = NULL;
672// }
673 return ;
674 }
675
676 //write the pbm data to web
677 for (i = 0; i < (*p_pbm_query_result).count; i++) {
678 if (0 == i) {
679 web_feedback_header(wp);
680 zte_rest_get_pbm_data_head(wp);
681 if (0 == pbm_query_req.location) {
682 zte_rest_get_pbm_data_sim(wp, p_pbm_query_result, i, 0);
683 } else {
684 zte_rest_get_pbm_data_other(wp, p_pbm_query_result, i, 0);
685 }
686 } else {
687 if (0 == pbm_query_req.location) {
688 zte_rest_get_pbm_data_sim(wp, p_pbm_query_result, i, 1);
689 } else {
690 zte_rest_get_pbm_data_other(wp, p_pbm_query_result, i, 1);
691 }
692 }
693 }
694 zte_rest_get_pbm_data_foot(wp);
695 //(void)websWrite(wp, T("]}"));
696
697 //free
698// if (NULL != p_pbm_query_result) { // kw 3
699 free(p_pbm_query_result);
700 p_pbm_query_result = NULL;
701// }
702}
703
704/**********************************************************************
705* Function: zte_get_pbm_data_total
706* Description: to get the total pbm data
707* Input: the web para
708* Output:
709* Return:
710* Others:
711* Modify Date Version Author Modification
712* -----------------------------------------------
713* 2012/04/10 V1.0 chenyi first version
714**********************************************************************/
715void zte_get_pbm_data_total(webs_t wp)
716{
717 zte_pbm_query_req_s_type pbm_query_req;
718 zte_pbm_query_resp_s_type *p_pbm_query_result = NULL;
719 int result = 0;
720 int i = 0;
721 char_t *page = NULL;
722 char_t *data_per_page = NULL;
723 char_t *mem_store = NULL;
724 char *pbm_group = NULL;
725
726 int total_pages = 0;
727 int leave_nums = 0;
728 int curr_page = 0;
729 int total_pbm = 0;
730
731 int idata_per_page = 0;
732
733 memset(&pbm_query_req, 0, sizeof(zte_pbm_query_req_s_type));
734
735 page = websGetVar(wp, "page", T(""));
736 data_per_page = websGetVar(wp, "data_per_page", T(""));
737 mem_store = websGetVar(wp, "mem_store", T(""));
738 pbm_group = websGetVar(wp, "pbm_group", T("")); //not to check whether is empty
739
740 if (('\0' == *page) || ('\0' == *data_per_page) || ('\0' == *mem_store)) {
741 slog(MISC_PRINT, SLOG_ERR, "zte_get_pbm_data: invalid web para.\n"); /*lint !e26*/
742 zte_web_pbm_feed_back_empty(wp);
743 return ;
744 }
745
746
747#if 0
748 //calculate the total pages
749 total_pages = (atoi(data_per_page)) / PBM_PAGE_RECORD_MAX_NUM;
750 leave_nums = (atoi(data_per_page)) % PBM_PAGE_RECORD_MAX_NUM;
751
752 if (0 != leave_nums) {
753 total_pages++;
754 }
755
756#else
757 idata_per_page = atoi(data_per_page);
758 if(idata_per_page < 0 || idata_per_page > INT_MAX-1)
759 {
760 total_pages = 1;
761 leave_nums = 0;
762 }
763 else
764 {
765 //calculate the total pages
766 total_pages = idata_per_page / PBM_PAGE_RECORD_MAX_NUM;
767 leave_nums = idata_per_page % PBM_PAGE_RECORD_MAX_NUM;
768
769 if (0 != leave_nums) {
770 total_pages++;
771 }
772 }
773#endif
774
775 slog(MISC_PRINT, SLOG_DEBUG, "pbm:total_pages,leave_nums:[%d][%d]", total_pages, leave_nums); /*lint !e26*/
776
777 p_pbm_query_result = (zte_pbm_query_resp_s_type*)malloc(4 + sizeof(zte_pbm_create_ext_record_s_type) * PBM_PAGE_RECORD_MAX_NUM);
778 if (NULL == p_pbm_query_result) {
779 slog(MISC_PRINT, SLOG_ERR, "malloc pbm result mem fail.\n"); /*lint !e26*/
780 zte_web_pbm_feed_back_empty(wp);
781 return ;/*lint !e429*/
782 }
783
784 (void)zte_web_write("pbm_group", pbm_group); //only wrtite one time
785
786 for (curr_page = 0; curr_page < total_pages; curr_page++) {
787
788 //reset
789 memset(&pbm_query_req, 0, sizeof(zte_pbm_query_req_s_type));
790
791 pbm_query_req.page = curr_page;
792 pbm_query_req.num_per_page = PBM_PAGE_RECORD_MAX_NUM;
793 /*lint -e64*/
794 pbm_query_req.location = atoi(mem_store); //0:sim;1:device
795
796 slog(MISC_PRINT, SLOG_DEBUG, "pbm_query_req:[%u,%u,%d].\n", pbm_query_req.page, pbm_query_req.num_per_page, pbm_query_req.location); /*lint !e26*/
797
798 //reset
799 memset(p_pbm_query_result, 0, 4 + sizeof(zte_pbm_create_ext_record_s_type)*PBM_PAGE_RECORD_MAX_NUM); /*lint !e668*/
800
801 slog(MISC_PRINT, SLOG_NORMAL, "GET PBM DATA FROM DB START.\n"); /*lint !e26*/
802 result = zte_libpbm_get_rec_data(&pbm_query_req, p_pbm_query_result);
803 slog(MISC_PRINT, SLOG_DEBUG, "GET PBM DATA FROM DB END.\n"); /*lint !e26*/
804
805 if (-1 == result) {
806 slog(MISC_PRINT, SLOG_DEBUG, "read pbm page [%d] fail.\n", curr_page); /*lint !e26*/
807 //free
808// if (NULL != p_pbm_query_result) { // kw 3
809 free(p_pbm_query_result);
810 p_pbm_query_result = NULL;
811// }
812
813 if (0 == curr_page) {
814 zte_web_pbm_feed_back_empty(wp);
815 return ;
816 } else {
817 break;
818 }
819 }
820
821 slog(MISC_PRINT, SLOG_DEBUG, "pbm:total query count [%u].\n", (*p_pbm_query_result).count); /*lint !e26*/
822
823 if (0 == (*p_pbm_query_result).count) {
824 //free
825// if (NULL != p_pbm_query_result) { // kw 3
826 free(p_pbm_query_result);
827 p_pbm_query_result = NULL;
828// }
829
830 if (0 == curr_page) {
831 zte_web_pbm_feed_back_empty(wp);
832 return ;
833 } else {
834 break;
835 }
836 }
837
838 //write the pbm data to web
839 for (i = 0; (i < (*p_pbm_query_result).count) && (total_pbm < atoi(data_per_page)); i++, total_pbm++) {
840 if ((0 == i) && (0 == curr_page)) {
841 web_feedback_header(wp);
842 zte_rest_get_pbm_data_head(wp);
843 if (0 == pbm_query_req.location) {
844 zte_rest_get_pbm_data_sim(wp, p_pbm_query_result, i, 0);
845 } else {
846 zte_rest_get_pbm_data_other(wp, p_pbm_query_result, i, 0);
847 }
848 } else {
849 if (0 == pbm_query_req.location) {
850 zte_rest_get_pbm_data_sim(wp, p_pbm_query_result, i, 1);
851 } else {
852 zte_rest_get_pbm_data_other(wp, p_pbm_query_result, i, 1);
853 }
854 }
855 }
856
857 }
858
859
860 zte_rest_get_pbm_data_foot(wp);
861 //free
862// if (NULL != p_pbm_query_result) { // kw 3
863 free(p_pbm_query_result);
864 p_pbm_query_result = NULL;
865// }
866}
867
868/**********************************************************************
869* Function: zte_get_pbm_parameter_info
870* Description: to get the pbm parameter info
871* Input: the web para
872* Output:
873* Return:
874* Others:
875* Modify Date Version Author Modification
876* -----------------------------------------------
877* 2012/04/10 V1.0 chenyi first version
878**********************************************************************/
879void zte_get_pbm_parameter_info(webs_t wp)
880{
881 zte_pbm_query_req_s_type pbm_para_query_info;
882 zte_pbm_sim_capability_s_type pbm_sim_capability_s;
883 zte_pbm_device_capability_s_type pbm_device_capability_s;
884 char *pbm_location = NULL;
885 int result = 0;
886
887 //initialize
888 memset(&pbm_para_query_info, 0, sizeof(zte_pbm_query_req_s_type));
889 memset(&pbm_sim_capability_s, 0, sizeof(zte_pbm_sim_capability_s_type));
890 memset(&pbm_device_capability_s, 0, sizeof(zte_pbm_device_capability_s_type));
891
892 pbm_location = websGetVar(wp, "pbm_location", T(""));
893
894 if (0 == strcmp(pbm_location, "")) {
895 slog(MISC_PRINT, SLOG_ERR, "pbm_location is empty.\n"); /*lint !e26*/
896 zte_web_pbm_feed_back_empty(wp);
897 return;
898 }
899
900 slog(MISC_PRINT, SLOG_DEBUG, "pbm_location is [%s].\n", pbm_location); /*lint !e26*/
901
902 if (0 == strcmp(pbm_location, PBM_NATIVE)) {
903 pbm_para_query_info.location = PBM_LOCATION_DEVICE;
904 } else if (0 == strcmp(pbm_location, PBM_SIM)) {
905 pbm_para_query_info.location = PBM_LOCATION_SIM;
906 } else {
907 slog(MISC_PRINT, SLOG_ERR, "invalid pbm_location[%s].\n", pbm_location); /*lint !e26*/
908 zte_web_pbm_feed_back_empty(wp);
909 return;
910 }
911 slog(MISC_PRINT, SLOG_NORMAL, "GET PBM DATA FROM DB START.\n"); /*lint !e26*/
912 result = zte_libpbm_get_capability(&pbm_para_query_info, &pbm_sim_capability_s, &pbm_device_capability_s);
913 slog(MISC_PRINT, SLOG_DEBUG, "GET PBM DATA FROM DB END.\n"); /*lint !e26*/
914 if (-1 == result) {
915 slog(MISC_PRINT, SLOG_ERR, "call zte_libpbm_get_capability fail.\n"); /*lint !e26*/
916 zte_web_pbm_feed_back_empty(wp);
917 return ;
918 }
919
920 web_feedback_header(wp);
921 if (0 == strcmp(pbm_location, PBM_NATIVE)) {
922 zte_rest_cmd_write_head(wp);
923 zte_rest_cmd_write_int(wp, PBM_DEV_MAX_RECORD_NUM, pbm_device_capability_s.max_record_number, 1);
924 zte_rest_cmd_write_int(wp, PBM_DEV_USED_RECORD_NUM, pbm_device_capability_s.used_record_number, 0);
925 zte_rest_cmd_write_foot(wp);
926 } else {
927 zte_rest_cmd_write_head(wp);
928 zte_rest_cmd_write_int(wp, PBM_SIM_SIM_TYPE, pbm_sim_capability_s.sim_type, 1);
929 zte_rest_cmd_write_int(wp, PBM_SIM_MAX_RECORD_NUM, pbm_sim_capability_s.max_record_number, 1);
930 zte_rest_cmd_write_int(wp, PBM_SIM_USED_RECORD_NUM, pbm_sim_capability_s.used_record_number, 1);
931 zte_rest_cmd_write_int(wp, PBM_SIM_MAX_NAME_LEN, pbm_sim_capability_s.max_name_len, 1);
932 zte_rest_cmd_write_int(wp, PBM_SIM_MAX_NUMBER_LEN, pbm_sim_capability_s.max_number_len, 0);
933 zte_rest_cmd_write_foot(wp);
934 }
935}
936
937/**********************************************************************
938* Function: zte_web_pbm_feed_back_empty
939* Description: to write empty info to web
940* Input: the web para
941* Output:
942* Return:
943* Others:
944* Modify Date Version Author Modification
945* -----------------------------------------------
946* 2012/04/10 V1.0 chenyi first version
947**********************************************************************/
948
949static void zte_web_pbm_feed_back_empty(webs_t wp)
950{
951 if (NULL == wp) {
952 return;
953 }
954
955 web_feedback_header(wp);
956 if (wp->flags & WEBS_XML_CLIENT_REQUEST) {
957 websWrite(wp, T("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"));
958 websWrite(wp, T("<%s>empty</%s>\n"), PBM_DATA, PBM_DATA);
959 } else {
960 (void)websWrite(wp, T("{\"%s\":[]}"), PBM_DATA);
961 }
962 //(void)websWrite(wp, T("{\"%s\":[]}"),PBM_DATA);
963}
964//added by chenyi for handle the http request end 20111118
965