xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 1 | /**************************************************************************
|
| 2 | *
|
| 3 | * Copyright (c) 2013 ZTE Corporation.
|
| 4 | *
|
| 5 | ***************************************************************************
|
| 6 | * Ä£ ¿é Ãû : Atserver-PB
|
| 7 | * ÎÄ ¼þ Ãû : pb_db.c
|
| 8 | * Ïà¹ØÎļþ :
|
| 9 | * ʵÏÖ¹¦ÄÜ : Pb Êý¾Ý¿â²Ù×÷½Ó¿Úº¯ÊýʵÏÖ
|
| 10 | * ×÷ Õß : syx
|
| 11 | * °æ ±¾ : V1.0
|
| 12 | * Íê³ÉÈÕÆÚ : 2013-05-16
|
| 13 | * ÆäËü˵Ã÷ :
|
| 14 | **************************************************************************/
|
| 15 |
|
| 16 | /**************************************************************************
|
| 17 | * Ð޸ļǼ :
|
| 18 | ***************************************************************************/
|
| 19 | /**************************************************************************
|
| 20 | * Ð޸ıàºÅ :
|
| 21 | * ÐÞ ¸Ä ÈË :
|
| 22 | * ÐÞ¸ÄÈÕÆÚ :
|
| 23 | * ÐÞ¸ÄÄÚÈÝ :
|
| 24 | **************************************************************************/
|
| 25 |
|
| 26 | /**************************************************************************
|
| 27 | * #includeÇø
|
| 28 | **************************************************************************/
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 29 | #include "pb_com.h"
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 30 |
|
| 31 | /**************************************************************************
|
| 32 | * ³£Á¿¶¨ÒåÇø
|
| 33 | **************************************************************************/
|
| 34 |
|
| 35 | /**************************************************************************
|
| 36 | * Êý¾Ý½á¹¹¶¨ÒåÇø
|
| 37 | **************************************************************************/
|
| 38 | /**************************************************************************
|
| 39 | * staticº¯ÊýÉùÃ÷Çø
|
| 40 | **************************************************************************/
|
| 41 |
|
| 42 | /**************************************************************************
|
| 43 | * È«¾Ö±äÁ¿¶¨ÒåÇø
|
| 44 | **************************************************************************/
|
| 45 |
|
| 46 | /**************************************************************************
|
| 47 | * º¯ÊýʵÏÖÇø
|
| 48 | **************************************************************************/
|
| 49 | T_zPb_DbResult atPb_CreatDb()
|
| 50 | {
|
| 51 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 52 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 53 | UINT32 count = 0;
|
| 54 |
|
| 55 | result = atPb_ExecDbSql(ZPB_CREATE_PBM_TABLE,NULL,NULL);
|
| 56 | if(ZPB_DB_OK != result)
|
| 57 | {
|
| 58 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm table result is %d\n", result);
|
| 59 | return result;
|
| 60 | }
|
| 61 | /*create pbm_sim_capability table*/
|
| 62 | result = atPb_ExecDbSql(ZPB_CREATE_PBM_SIM_CAPABILITY_TABLE,NULL,NULL);
|
| 63 | if(ZPB_DB_OK != result)
|
| 64 | {
|
| 65 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm_sim_capability table result is %d\n", result);
|
| 66 | return result;
|
| 67 | }
|
| 68 | /*create pbm_device_capability table*/
|
| 69 | result = atPb_ExecDbSql(ZPB_CREATE_PBM_DEVICE_CAPABILITY_TABLE,NULL,NULL);
|
| 70 | if(ZPB_DB_OK != result)
|
| 71 | {
|
| 72 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm_device_capability table result is %d\n", result);
|
| 73 | return result;
|
| 74 | }
|
| 75 | /*ɾ³ýpbm±íÖÐλÖÃΪsim¿¨µÄµç»°±¾¼Ç¼*/
|
| 76 | snprintf(sql,sizeof(sql),"delete from %s where Location=%d",ZPB_DB_PBM_TABLE, ZPB_LOCATION_USIM);
|
| 77 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 78 | if(ZPB_DB_OK != result)
|
| 79 | {
|
| 80 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm_device_capability table result is %d\n", result);
|
| 81 | return result;
|
| 82 | }
|
| 83 |
|
| 84 | memset(sql, 0, sizeof(sql));
|
| 85 | snprintf(sql,sizeof(sql)-1,"select count(*) from %s",ZPB_DB_SIM_CAPABILITY_TABLE);
|
| 86 | (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);
|
| 87 | if(0 < count)
|
| 88 | {
|
| 89 | memset(sql, 0, sizeof(sql));
|
| 90 | snprintf(sql,sizeof(sql)-1,"delete from %s where Sim_type>=0",ZPB_DB_SIM_CAPABILITY_TABLE);
|
| 91 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 92 | if(ZPB_DB_OK != result)
|
| 93 | {
|
| 94 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetSimCapacityTable:fail!\n");
|
| 95 | return result;
|
| 96 | }
|
| 97 | }
|
| 98 | return ZPB_DB_OK;
|
| 99 | }
|
| 100 |
|
| 101 | T_zPb_DbResult atPb_DropDb()
|
| 102 | {
|
| 103 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 104 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 105 |
|
| 106 |
|
| 107 | result = atPb_ExecDbSql(ZTE_DROP_PBM_SQL,NULL,NULL);
|
| 108 | if(ZPB_DB_OK != result)
|
| 109 | {
|
| 110 | slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm table result is %d\n", result);
|
| 111 | return result;
|
| 112 | }
|
| 113 |
|
| 114 | result = atPb_ExecDbSql(ZTE_DROP_PBM_DEVICE_SQL,NULL,NULL);
|
| 115 | if(ZPB_DB_OK != result)
|
| 116 | {
|
| 117 | slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_device table result is %d\n", result);
|
| 118 | return result;
|
| 119 | }
|
| 120 |
|
| 121 | result = atPb_ExecDbSql(ZTE_DROP_PBM_SIM_SQL,NULL,NULL);
|
| 122 | if(ZPB_DB_OK != result)
|
| 123 | {
|
| 124 | slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_sim table result is %d\n", result);
|
| 125 | return result;
|
| 126 | }
|
| 127 |
|
| 128 | result = atPb_ExecDbSql(ZTE_DROP_PBM_SIM_CAPABILITY_SQL,NULL,NULL);
|
| 129 | if(ZPB_DB_OK != result)
|
| 130 | {
|
| 131 | slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_sim_capability table result is %d\n", result);
|
| 132 | return result;
|
| 133 | }
|
| 134 |
|
| 135 | result = atPb_ExecDbSql(ZTE_DROP_PBM_DEVICE_CAPABILITY_SQL,NULL,NULL);
|
| 136 | if(ZPB_DB_OK != result)
|
| 137 | {
|
| 138 | slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_device_capability table result is %d\n", result);
|
| 139 | return result;
|
| 140 | }
|
| 141 |
|
| 142 | return ZPB_DB_OK;
|
| 143 | }
|
| 144 |
|
| 145 | T_zPb_DbResult atPb_DbOpen(sqlite3**pDb)
|
| 146 | {
|
| 147 | sqlite3* pTmpDb = NULL;
|
| 148 |
|
| 149 | if(NULL == pDb)
|
| 150 | {
|
| 151 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:invalide inputs.");/*lint !e26*/
|
| 152 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 153 | }
|
| 154 | slog(PB_PRINT,SLOG_DEBUG,"pb:sqlite3_open call");/*lint !e26*/
|
| 155 |
|
| 156 | #if 0
|
| 157 | if(!fopen(ZPB_DB_PATH, "r"))
|
| 158 | {
|
| 159 | file = fopen(ZPB_DB_PATH, "w");
|
| 160 | if(!file)
|
| 161 | {
|
| 162 | printf("unable to open file etc_rw/pbm.db\n");/*lint !e26*/
|
| 163 |
|
| 164 | }
|
| 165 | else
|
| 166 | {
|
| 167 | printf(" open file etc_rw/pbm.db file=%d\n", file);
|
| 168 | fclose(file);
|
| 169 | }
|
| 170 | }
|
| 171 | #endif
|
| 172 | if(sqlite3_open(ZPB_DB_PATH, &pTmpDb))
|
| 173 | {
|
| 174 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:can not open db,sqlite3_errmsg:%s.",sqlite3_errmsg(pTmpDb));
|
| 175 | (VOID) sqlite3_close(pTmpDb);
|
| 176 | return ZPB_DB_ERROR_NOTOPENDB;
|
| 177 | }
|
| 178 | *pDb = pTmpDb;
|
| 179 | return ZPB_DB_OK;
|
| 180 | }
|
| 181 | T_zPb_DbResult atPb_DbClose (sqlite3*pDb)
|
| 182 | {
|
| 183 | if (NULL == pDb)
|
| 184 | {
|
| 185 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:invalide inputs.");/*lint !e26*/
|
| 186 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 187 | }
|
| 188 | if(sqlite3_close(pDb))
|
| 189 | {
|
| 190 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:can not close db");/*lint !e26*/
|
| 191 | return ZPB_DB_ERROR;
|
| 192 | }
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 193 | #ifdef WEBS_SECURITY
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 194 | if(access(ZPB_TMP_PATH, F_OK) == 0)
|
| 195 | {
|
| 196 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:tmp db stay");/*lint !e26*/
|
| 197 | if(remove(ZPB_TMP_PATH) != 0)
|
| 198 | {
|
| 199 | slog(PB_PRINT,SLOG_ERR,"remove ZPB_TMP_PATH fail");
|
| 200 | }
|
| 201 | }
|
| 202 | if(rename(ZPB_SEC_PATH, ZPB_TMP_PATH) != 0)
|
| 203 | {
|
| 204 | slog(PB_PRINT,SLOG_ERR,"rename ZPB_SEC_PATH fail");
|
| 205 | }
|
| 206 | {
|
| 207 | char rnum_buf[24] = {0};
|
| 208 | char cmd[128] = {0};
|
| 209 |
|
| 210 | sc_cfg_get("rnum_at", rnum_buf, sizeof(rnum_buf));
|
| 211 | snprintf(cmd, sizeof(cmd), "/bin/openssl enc -e -aes256 -salt -in %s -out %s -pass pass:%s", ZPB_DB_PATH, ZPB_SEC_PATH, rnum_buf);
|
| 212 | zxic_system(cmd);
|
| 213 | if(access(ZPB_SEC_PATH, F_OK) == 0)
|
| 214 | {
|
| 215 | if(remove(ZPB_TMP_PATH) != 0)
|
| 216 | {
|
| 217 | slog(PB_PRINT,SLOG_ERR,"remove ZPB_TMP_PATH1 fail");
|
| 218 | }
|
| 219 | }
|
| 220 | }
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 221 | #endif
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 222 | return ZPB_DB_OK;
|
| 223 | }
|
| 224 |
|
| 225 | static check_sql_cmd(const char *pSql)
|
| 226 | {
|
| 227 | if(pSql != NULL)
|
| 228 | {
|
| 229 | if(strstr(pSql, ";") || strstr(pSql, "--"))
|
| 230 | {
|
| 231 | return 0;
|
| 232 | }
|
| 233 | return 1;
|
| 234 | }
|
| 235 | return 0;
|
| 236 | }
|
| 237 |
|
| 238 | T_zPb_DbResult atPb_ExecDbSql(const char *pSql, sqlite3_callback callback,VOID *pFvarg)
|
| 239 | {
|
| 240 | sqlite3 *pDb = NULL;
|
| 241 | CHAR dbErrMsg[128] = {0};
|
| 242 | if(NULL == pSql)
|
| 243 | {
|
| 244 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 245 | }
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 246 | #ifdef WEBS_SECURITY
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 247 | if(check_sql_cmd(pSql) == 0)
|
| 248 | {
|
| 249 | slog(PB_PRINT,SLOG_ERR,"!!atPb_ExecDbSql:xss %s\n",pSql);
|
| 250 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 251 | }
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 252 | #endif
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 253 | if(ZPB_DB_OK != atPb_DbOpen(&pDb))
|
| 254 | {
|
| 255 | slog(PB_PRINT,SLOG_ERR,"pb:open pbm.db failed.");/*lint !e26*/
|
| 256 | return ZPB_DB_ERROR_NOTOPENDB;
|
| 257 | }
|
| 258 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_ExecDbSql:%s\n",pSql);
|
| 259 |
|
| 260 | if(sqlite3_exec(pDb,pSql,callback,pFvarg,NULL))
|
| 261 | {
|
| 262 | strncpy(dbErrMsg,sqlite3_errmsg(pDb),sizeof(dbErrMsg)-1);
|
| 263 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:can not exec sql,sqlite3_errmsg:%s.",dbErrMsg);
|
| 264 | (VOID)sqlite3_close(pDb);
|
| 265 | return ZPB_DB_ERROR;
|
| 266 | }
|
| 267 | (VOID)atPb_DbClose(pDb);
|
| 268 | return ZPB_DB_OK;
|
| 269 | }
|
| 270 |
|
| 271 | SINT32 atPb_InitApIndexCb(VOID *fvarg,int line,char **zresult,char **lname)
|
| 272 | {
|
| 273 | SINT32 index = 0;
|
| 274 |
|
| 275 | if(1 > line)
|
| 276 | {
|
| 277 | slog(PB_PRINT,SLOG_ERR,"pb:atPb_InitApIndexCb:record no data.\n");/*lint !e26*/
|
| 278 | return -1;
|
| 279 | }
|
| 280 |
|
| 281 | index = atoi(zresult[0]);
|
| 282 | if (index > ZPB_AP_MAX_RECORD) {
|
| 283 | slog(PB_PRINT,SLOG_ERR,"pb:atPb_InitApIndexCb:index overflow.\n");
|
| 284 | return -1;
|
| 285 | }
|
| 286 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_InitApIndexCb:pbm_index=%d\n",index);
|
| 287 | g_zPb_ApIndex[index] = PBM_SUCCESS;
|
| 288 |
|
| 289 | return 0;
|
| 290 | }
|
| 291 |
|
| 292 | T_zPb_DbResult atPb_InitApIndex()
|
| 293 | {
|
| 294 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 295 | SINT32 i = 1;
|
| 296 |
|
| 297 | g_zPb_ApIndex[0] = ZPB_AP_MAX_RECORD;
|
| 298 |
|
| 299 | for(i=1; i<=g_zPb_ApIndex[0]; i++)
|
| 300 | {
|
| 301 | g_zPb_ApIndex[i] = PBM_ERROR_NOT_FOUND;
|
| 302 | }
|
| 303 | snprintf(sql,sizeof(sql),"select Pbm_index from %s where Location=%d",ZPB_DB_PBM_TABLE, ZPB_LOCATION_AP);
|
| 304 | return atPb_ExecDbSql(sql,atPb_InitApIndexCb,ZUFI_NULL);
|
| 305 | }
|
| 306 |
|
| 307 | /*check whether the web pbm dir exist or not*/
|
| 308 | INT zte_pbm_check_and_creat_dir(char *path)
|
| 309 | {
|
| 310 | if (-1==access(path,/*F_OK*/0))
|
| 311 | {
|
| 312 | slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:%s does not exist,socreate it.\n",ZPB_DB_DIR);
|
| 313 | if (-1 == mkdir(path, 0777))
|
| 314 | {
|
| 315 | slog(PB_PRINT,SLOG_ERR,"pb::failed to create db dir.\n");
|
| 316 | return -1;
|
| 317 | }
|
| 318 | }
|
| 319 | return 0;
|
| 320 | }
|
| 321 |
|
| 322 | UINT8 zte_pbm_check_web_pbm_dir(VOID)
|
| 323 | {
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 324 | #ifdef _MBB_OS_UCLINUX
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 325 | (VOID)zte_pbm_check_and_creat_dir("/mnt/jffs2/etc_rw");
|
| 326 | (VOID)zte_pbm_check_and_creat_dir("/mnt/jffs2/etc_rw/config");
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 327 | #else
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 328 | (VOID)zte_pbm_check_and_creat_dir("/etc_rw");
|
| 329 | (VOID)zte_pbm_check_and_creat_dir("/etc_rw/config");
|
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 330 | #endif
|
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 331 | return ZUFI_SUCC;
|
| 332 | }
|
| 333 |
|
| 334 | T_zPb_DbResult atPb_DelSimRecFromPbTable(SINT32 index)
|
| 335 | {
|
| 336 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 337 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 338 |
|
| 339 | snprintf(sql,sizeof(sql),"delete from %s where location=%d and Pbm_index=%d",ZPB_DB_PBM_TABLE, ZPB_LOCATION_USIM,index);
|
| 340 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 341 |
|
| 342 | if(ZPB_DB_OK == result)
|
| 343 | {
|
| 344 | g_zPb_SimIndex[index] = PBM_ERROR_NOT_FOUND;
|
| 345 | }
|
| 346 | return result;
|
| 347 | }
|
| 348 |
|
| 349 | T_zPb_DbResult atPb_LoadARecToPbmTable(T_zPb_WebContact *pbPara)
|
| 350 | {
|
| 351 | T_zPb_DbResult result = ZPB_DB_ERROR;
|
| 352 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 353 | if(NULL == pbPara)
|
| 354 | {
|
| 355 | slog(PB_PRINT,SLOG_ERR,"pb:atPb_LoadARecToPbmTable:invalid input");/*lint !e26*/
|
| 356 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 357 | }
|
| 358 | snprintf(sql,sizeof(sql),"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne) \
|
| 359 | values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",
|
| 360 | ZPB_DB_PBM_TABLE,
|
| 361 | pbPara->pbIndex,
|
| 362 | pbPara->pbLocation,
|
| 363 | pbPara->mobilNumber,
|
| 364 | pbPara->pbType,
|
| 365 | pbPara->name,
|
| 366 | pbPara->homeNumber,
|
| 367 | pbPara->officeNumber,
|
| 368 | pbPara->email,
|
| 369 | pbPara->sne);
|
| 370 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 371 | if(ZPB_DB_OK==result)
|
| 372 | {
|
| 373 | CHAR pbMax[50]={0};
|
| 374 | sc_cfg_get(ZPB_NV_USIMINDEXMAX,pbMax,sizeof(pbMax));
|
| 375 | if((pbPara->pbIndex>=1)&&(pbPara->pbIndex <= atoi(pbMax)))/*Comment: Èç¹ûµç»°±¾ÔÚË÷ÒýÄÚ,ZhaoYong,2008/12/23 10:49 */
|
| 376 | {
|
| 377 | g_zPb_SimIndex[pbPara->pbIndex] = PBM_SUCCESS;
|
| 378 | }
|
| 379 | (VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG, ZPB_OPERATE_SUC);
|
| 380 | }
|
| 381 | else
|
| 382 | {
|
| 383 | (VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG, ZPB_NEW_ERROR);
|
| 384 | }
|
| 385 | slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:exec table %s result %d\n", ZPB_DB_PBM_TABLE,result);
|
| 386 | return result;
|
| 387 | }
|
| 388 |
|
| 389 | VOID atPb_SqlModifyOneRec(T_zPb_WebContact *pbmPara,char *sql,int len)
|
| 390 | {
|
| 391 | printf("pb:atPb_SqlModifyOneRec enter");/*lint !e26*/
|
| 392 |
|
| 393 | if(ZPB_LOCATION_USIM == pbmPara->pbLocation)
|
| 394 | {
|
| 395 | snprintf(sql,len,"update %s set Pbm_index=\'%d\',Location=\'%d\',Number=\'%s\',Type=\'%d\',Name=\'%s\',Anr=\'%s\', \
|
| 396 | Anr1=\'%s\',Email=\'%s\',Sne=\'%s\' where id=%d",
|
| 397 | ZPB_DB_PBM_TABLE,
|
| 398 | pbmPara->pbIndex,
|
| 399 | pbmPara->pbLocation,
|
| 400 | pbmPara->mobilNumber,
|
| 401 | pbmPara->pbType,
|
| 402 | pbmPara->name,
|
| 403 | pbmPara->homeNumber,
|
| 404 | pbmPara->officeNumber,
|
| 405 | pbmPara->email,
|
| 406 | pbmPara->sne,
|
| 407 | pbmPara->pbId);
|
| 408 | }
|
| 409 | else if(ZPB_LOCATION_AP == pbmPara->pbLocation)
|
| 410 | {
|
| 411 | snprintf(sql,len,"update %s set Pbm_index=\'%d\',Location=\'%d\',Number=\'%s\',Type=\'%d\',Name=\'%s\',Anr=\'%s\', \
|
| 412 | Anr1=\'%s\',Email=\'%s\',Sne=\'%s\',Pbm_group=\'%s\' where id=%d",
|
| 413 | ZPB_DB_PBM_TABLE,
|
| 414 | pbmPara->pbIndex,
|
| 415 | pbmPara->pbLocation,
|
| 416 | pbmPara->mobilNumber,
|
| 417 | pbmPara->pbType,
|
| 418 | pbmPara->name,
|
| 419 | pbmPara->homeNumber,
|
| 420 | pbmPara->officeNumber,
|
| 421 | pbmPara->email,
|
| 422 | pbmPara->sne,
|
| 423 | pbmPara->group,
|
| 424 | pbmPara->pbId);
|
| 425 | }
|
| 426 | }
|
| 427 |
|
| 428 | T_zPb_DbResult atPb_DbGetParamCb(VOID *fvarg,int line,char **zresult,char **lname)
|
| 429 | {
|
| 430 | T_zPb_Header para = {0};
|
| 431 |
|
| 432 | if(1 > line)
|
| 433 | {
|
| 434 | slog(PB_PRINT,SLOG_ERR,"pb:atPb_DbGetParamCb:record no data.");/*lint !e26*/
|
| 435 | return ZPB_DB_ERROR;
|
| 436 | }
|
| 437 |
|
| 438 | para.pbIndex = atoi(zresult[0]);
|
| 439 | para.pbLocation = atoi(zresult[1]);
|
| 440 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DbGetParamCb: index=%d,location=%d", para.pbIndex, para.pbLocation);
|
| 441 | memcpy(fvarg,¶,sizeof(para));
|
| 442 | return ZPB_DB_OK;
|
| 443 | }
|
| 444 | T_zPb_DbResult atPb_GetIndexLocationById(T_zPb_Header *pbPara)
|
| 445 | {
|
| 446 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 447 |
|
| 448 | snprintf(sql,sizeof(sql)-1,"select Pbm_index,Location from %s where id=%d",
|
| 449 | ZPB_DB_PBM_TABLE,
|
| 450 | pbPara->pbId);
|
| 451 |
|
| 452 | memset(pbPara, 0,sizeof(T_zPb_Header));
|
| 453 | return atPb_ExecDbSql(sql,atPb_DbGetParamCb, pbPara);
|
| 454 | }
|
| 455 |
|
| 456 | VOID atPb_SqlNewOneRec(T_zPb_WebContact *pbmPara,CHAR *sql,int len)
|
| 457 | {
|
| 458 | if(ZPB_LOCATION_USIM == pbmPara->pbLocation)
|
| 459 | {
|
| 460 | snprintf(sql,len,"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne)\
|
| 461 | values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",
|
| 462 | ZPB_DB_PBM_TABLE,
|
| 463 | pbmPara->pbIndex,
|
| 464 | pbmPara->pbLocation,
|
| 465 | pbmPara->mobilNumber,
|
| 466 | pbmPara->pbType,
|
| 467 | pbmPara->name,
|
| 468 | pbmPara->homeNumber,
|
| 469 | pbmPara->officeNumber,
|
| 470 | pbmPara->email,
|
| 471 | pbmPara->sne);
|
| 472 |
|
| 473 | }
|
| 474 | else if(ZPB_LOCATION_AP == pbmPara->pbLocation)
|
| 475 | {
|
| 476 | snprintf(sql,len,"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne,Pbm_group)\
|
| 477 | values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",
|
| 478 | ZPB_DB_PBM_TABLE,
|
| 479 | pbmPara->pbIndex,
|
| 480 | pbmPara->pbLocation,
|
| 481 | pbmPara->mobilNumber,
|
| 482 | pbmPara->pbType,
|
| 483 | pbmPara->name,
|
| 484 | pbmPara->homeNumber,
|
| 485 | pbmPara->officeNumber,
|
| 486 | pbmPara->email,
|
| 487 | pbmPara->sne,
|
| 488 | pbmPara->group);
|
| 489 | }
|
| 490 | }
|
| 491 |
|
| 492 |
|
| 493 | T_zPb_DbResult atPb_WriteContactToPbmTable(T_zPb_WebContact *pPbRecord, BOOL pbNewFlag)
|
| 494 | {
|
| 495 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 496 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 497 | //UINT8 ascName[ZPB_TEXT_SIZE_BYTES]={0};
|
| 498 |
|
| 499 | if(NULL == pPbRecord)
|
| 500 | {
|
| 501 | slog(PB_PRINT,SLOG_ERR,"pb:atPb_WriteContactToPbmTable:invalid input");/*lint !e26*/
|
| 502 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 503 | }
|
| 504 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_WriteContactToPbmTable:input index is %d,location=%d\n",pPbRecord->pbIndex,pPbRecord->pbLocation);
|
| 505 |
|
| 506 | //atPb_EncodeNameToAscii(pbRecord->name,ascName);
|
| 507 | if(TRUE == pbNewFlag)
|
| 508 | {
|
| 509 | atPb_SqlNewOneRec(pPbRecord,sql,sizeof(sql));
|
| 510 | }
|
| 511 | else
|
| 512 | {
|
| 513 | atPb_SqlModifyOneRec(pPbRecord,sql,sizeof(sql));
|
| 514 | }
|
| 515 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 516 |
|
| 517 | if(ZPB_DB_OK == result)
|
| 518 | {
|
| 519 | if(ZPB_LOCATION_USIM == pPbRecord->pbLocation)
|
| 520 | {
|
| 521 | g_zPb_SimIndex[(pPbRecord->pbIndex)] = PBM_SUCCESS;
|
| 522 | }
|
| 523 | else if(ZPB_LOCATION_AP == pPbRecord->pbLocation)
|
| 524 | {
|
| 525 | g_zPb_ApIndex[(pPbRecord->pbIndex)] = PBM_SUCCESS;
|
| 526 | }
|
| 527 | //(VOID)system("adb push /etc_rw/config/pbm.db /usr/zte/zte_conf/config");
|
| 528 | }
|
| 529 | return result;
|
| 530 | }
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 | SINT32 atPb_DbCountTableLineCb(VOID *fvarg,int line,char **zresult,char **lname)
|
| 535 | {
|
| 536 | if(1 > line)
|
| 537 | {
|
| 538 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:record no data.");/*lint !e26*/
|
| 539 | return -1;
|
| 540 | }
|
| 541 | *(int*)fvarg = atoi(zresult[0]);
|
| 542 |
|
| 543 | return 0;
|
| 544 | }
|
| 545 |
|
| 546 | T_zPb_DbResult atPb_SetSimCapacityTable(T_zPb_UsimCapacity pbPara)
|
| 547 | {
|
| 548 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 549 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 550 | UINT32 count = 0;
|
| 551 |
|
| 552 | snprintf(sql,sizeof(sql)-1,"select count(*) from %s",ZPB_DB_SIM_CAPABILITY_TABLE);
|
| 553 | (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);
|
| 554 | if(0 < count)
|
| 555 | {
|
| 556 | memset(sql, 0, sizeof(sql));
|
| 557 | snprintf(sql,sizeof(sql)-1,"delete from %s where Sim_type>=0",ZPB_DB_SIM_CAPABILITY_TABLE);
|
| 558 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 559 | if(ZPB_DB_OK != result)
|
| 560 | {
|
| 561 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetSimCapacityTable:fail!\n");
|
| 562 | return result;
|
| 563 | }
|
| 564 | }
|
| 565 |
|
| 566 | memset(sql, 0, sizeof(sql));
|
| 567 | snprintf(sql,sizeof(sql)-1,"insert into %s (Sim_type,Max_record_number,Used_record_number,Max_number_len,Max_name_len,Max_anr_len,Max_anr1_len, \
|
| 568 | Max_email_len,Max_sne_len) values(\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')",
|
| 569 | ZPB_DB_SIM_CAPABILITY_TABLE,
|
| 570 | pbPara.simType,
|
| 571 | pbPara.maxRecordNum,
|
| 572 | pbPara.usedRecordNum,
|
| 573 | pbPara.maxNumberLen,
|
| 574 | pbPara.maxNameLen,
|
| 575 | pbPara.maxAnrLen,
|
| 576 | pbPara.maxAnr1Len,
|
| 577 | pbPara.maxEmailLen,
|
| 578 | pbPara.maxSneLen);
|
| 579 |
|
| 580 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetSimCapacityTable:ok!\n");
|
| 581 | return atPb_ExecDbSql(sql,NULL,NULL);
|
| 582 | }
|
| 583 |
|
| 584 | T_zPb_DbResult atPb_SetApCapacityTable()
|
| 585 | {
|
| 586 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 587 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 588 | SINT32 count = 0;
|
| 589 | T_zPb_ApCapacity pbPara = {0};
|
| 590 | snprintf(sql,sizeof(sql)-1,"select count(*) from %s",ZPB_DB_DEVICE_CAPABILITY_TABLE);
|
| 591 | (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);
|
| 592 | if(0 < count)
|
| 593 | {
|
| 594 | memset(sql, 0, sizeof(sql));
|
| 595 | snprintf(sql,sizeof(sql)-1,"delete from %s",ZPB_DB_DEVICE_CAPABILITY_TABLE);
|
| 596 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 597 | if(ZPB_DB_OK != result)
|
| 598 | {
|
| 599 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetApCapacityTable:fail!\n");
|
| 600 | return result;
|
| 601 | }
|
| 602 | }
|
| 603 | memset(sql, 0, sizeof(sql));
|
| 604 | snprintf(sql,sizeof(sql)-1,"select count(*) from %s where Location=%d",ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP);
|
| 605 | result = atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);
|
| 606 | if(ZPB_DB_OK == result)
|
| 607 | {
|
| 608 | pbPara.usedRecordNum = count;
|
| 609 | pbPara.maxRecordNum = ZPB_AP_MAX_RECORD;
|
| 610 | }
|
| 611 | slog(PB_PRINT,SLOG_DEBUG,"pb:max_rec_num=%d,used=%d",pbPara.maxRecordNum,pbPara.usedRecordNum);
|
| 612 |
|
| 613 | memset(sql, 0, sizeof(sql));
|
| 614 | snprintf(sql,sizeof(sql)-1,"insert into %s (Max_record_number,Used_record_number) values(\'%d\',\'%d\')",
|
| 615 | ZPB_DB_DEVICE_CAPABILITY_TABLE,
|
| 616 | pbPara.maxRecordNum,
|
| 617 | pbPara.usedRecordNum);
|
| 618 | return atPb_ExecDbSql(sql,NULL,NULL);
|
| 619 | }
|
| 620 |
|
| 621 | T_zPb_DbResult atPb_DbGetIndexByGroupCb(VOID *fvarg,int line,char **zresult,char **lname)
|
| 622 | {
|
| 623 | T_zPb_ApIndex *pbIndex = NULL;
|
| 624 | int i = 0;
|
| 625 |
|
| 626 | if(1 > line)
|
| 627 | {
|
| 628 | return ZPB_DB_ERROR;
|
| 629 | }
|
| 630 |
|
| 631 | pbIndex = (T_zPb_ApIndex*)fvarg;
|
| 632 | i = pbIndex->count;
|
| 633 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DbGetIndexByGroupCb enter,i=%d\n",i);
|
| 634 |
|
| 635 | pbIndex->apIndex[i+1]= atoi(zresult[0]);
|
| 636 | slog(PB_PRINT,SLOG_DEBUG,"pb:get_index_by_group_cb:pbm_index=%d",pbIndex->apIndex[i+1]);
|
| 637 |
|
| 638 | pbIndex->count = i + 1;
|
| 639 | slog(PB_PRINT,SLOG_DEBUG,"pb:get_index_by_group_cb:pbm count is %d",pbIndex->count);
|
| 640 | return ZPB_DB_OK;
|
| 641 | }
|
| 642 |
|
| 643 | T_zPb_DbResult atPb_DelRecFromPbmTableByGroup(T_zPb_ApIndex *index)
|
| 644 | {
|
| 645 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 646 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 647 | SINT32 countByGroup = 0;
|
| 648 | CHAR pbGroup[ZPB_PARAM_SIZE20] = {0};
|
| 649 |
|
| 650 | sc_cfg_get(ZPB_NV_GROUP,pbGroup,sizeof(pbGroup));
|
| 651 | snprintf(sql,sizeof(sql)-1,"select count(*) from %s where Location=%d and (Pbm_group=\"%s\")",
|
| 652 | ZPB_DB_PBM_TABLE, ZPB_LOCATION_AP, pbGroup);
|
| 653 | (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&countByGroup);
|
| 654 |
|
| 655 | memset(sql,0,sizeof(sql));
|
| 656 | snprintf(sql,sizeof(sql)-1,"select Pbm_index from %s where Location=%d and (Pbm_group=\"%s\")",ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP,pbGroup);
|
| 657 | result = atPb_ExecDbSql(sql,atPb_DbGetIndexByGroupCb, index); /*lint !e64*/
|
| 658 |
|
| 659 | if(countByGroup == index->count)
|
| 660 | {
|
| 661 | memset(sql,0,sizeof(sql));
|
| 662 | snprintf(sql,sizeof(sql)-1,"delete from %s where Location=%d and (Pbm_group=\"%s\")",
|
| 663 | ZPB_DB_PBM_TABLE,
|
| 664 | ZPB_LOCATION_AP,
|
| 665 | pbGroup);
|
| 666 |
|
| 667 | if(ZPB_DB_OK == atPb_ExecDbSql(sql,NULL,NULL))
|
| 668 | {
|
| 669 | (VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG, ZPB_OPERATE_SUC);
|
| 670 | }
|
| 671 | slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:exec table %s result %d\n", ZPB_DB_PBM_TABLE,result);
|
| 672 | }
|
| 673 | else
|
| 674 | {
|
| 675 | return ZPB_DB_ERROR;
|
| 676 | }
|
| 677 | /*write group nvconfig ""*/
|
| 678 | (VOID)sc_cfg_set(ZPB_NV_GROUP, "");
|
| 679 | return result;
|
| 680 | }
|
| 681 |
|
| 682 | VOID atPb_GetLocationIndexForDel(T_zPb_DelInfo *recData,SINT32 delTime)
|
| 683 | {
|
| 684 | T_zPb_Header pbHeader = {0};
|
| 685 |
|
| 686 | if(NULL == recData)
|
| 687 | {
|
| 688 | slog(PB_PRINT,SLOG_ERR,"pb:atPb_GetLocationIndexForDel--invalid input\n");
|
| 689 | return;
|
| 690 | }
|
| 691 |
|
| 692 | pbHeader.pbId = recData->delId[delTime];
|
| 693 |
|
| 694 | if(ZPB_DB_OK != atPb_GetIndexLocationById(&pbHeader))
|
| 695 | {
|
| 696 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:find index and location failed");
|
| 697 | return;
|
| 698 | }
|
| 699 | recData->delIndex[delTime] = pbHeader.pbIndex;
|
| 700 | recData->delLocation = pbHeader.pbLocation;
|
| 701 | slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:del index=%d,location=%d,del_pbm_time=%d",
|
| 702 | recData->delIndex[delTime],recData->delLocation,delTime);
|
| 703 | }
|
| 704 |
|
| 705 | /* ¶ÌÐÅת´æ»òÐ޸쬏ÄΪÏÈ·¢atÃüÁÔÙ´æÊý¾Ý¿â£¬¹Ê´æ´¢³É¹¦¶øatÃüÁî·¢ËÍʧ°Üɾ³ý֮ǰ´æ´¢µÄ¶ÌÐÅÕâÖÖ³¡¾°²»´æÔÚ
|
| 706 | T_zPb_DbResult atPb_DelRecordFromDBWhenAddErr()
|
| 707 | {
|
| 708 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 709 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 710 |
|
| 711 | sprintf(sql,"delete from %s where Pbm_index=%ld",ZPB_DB_PBM_TABLE,g_zPb_pbIndex);
|
| 712 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 713 |
|
| 714 | if(ZPB_DB_OK == result)
|
| 715 | {
|
| 716 | g_zPb_SimIndex[g_zPb_pbIndex] = PBM_ERROR_NOT_FOUND;
|
| 717 | }
|
| 718 |
|
| 719 | printf("[PB] atPb_DelRecordFromDBWhenAddErr result=%d,g_zPb_pbIndex=%d\n", result,g_zPb_pbIndex);
|
| 720 | g_zPb_pbIndex = 0;
|
| 721 | return result;
|
| 722 | }*/
|
| 723 |
|
| 724 |
|
| 725 | T_zPb_DbResult atPb_DelARecFromPbmTable(T_zPb_DelInfo *pbPara, SINT32 delTime)
|
| 726 | {
|
| 727 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 728 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 729 |
|
| 730 | if(NULL == pbPara)
|
| 731 | {
|
| 732 | slog(PB_PRINT,SLOG_ERR,"pb:pbm:invalid input");
|
| 733 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 734 | }
|
| 735 | atPb_GetLocationIndexForDel(pbPara, delTime);//del_pbm_time);
|
| 736 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DelARecFromPbmTable enter,delTime=%d,id=%d\n",delTime,pbPara->delId[delTime]);
|
| 737 |
|
| 738 | snprintf(sql,sizeof(sql)-1,"delete from %s where id=%d",ZPB_DB_PBM_TABLE,pbPara->delId[delTime]);//del_pbm_time]);// ÔÝʱÏȶ¨Îª0
|
| 739 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 740 |
|
| 741 | if(ZPB_DB_OK == result)
|
| 742 | {
|
| 743 | if(ZPB_LOCATION_AP == pbPara->delLocation)
|
| 744 | {
|
| 745 | g_zPb_ApIndex[(pbPara->delIndex[delTime])] = PBM_ERROR_NOT_FOUND;
|
| 746 | }
|
| 747 | else if(ZPB_LOCATION_USIM == pbPara->delLocation)
|
| 748 | {
|
| 749 | g_zPb_SimIndex[(pbPara->delIndex[delTime])] = PBM_ERROR_NOT_FOUND;
|
| 750 | }
|
| 751 | }
|
| 752 | return result;
|
| 753 | }
|
| 754 | VOID atPb_ClearSimPbmIndexArray(VOID)
|
| 755 | {
|
| 756 | SINT32 i = 1;
|
| 757 |
|
| 758 | for(i = 1; (i <= g_zPb_SimIndex[0]) && (i < (ZPB_SIM_MAX_RECORD+1)); i++)
|
| 759 | {
|
| 760 | g_zPb_SimIndex[i] = PBM_ERROR_NOT_FOUND;
|
| 761 | }
|
| 762 | }
|
| 763 |
|
| 764 | VOID atPb_ClearApPbmIndexArray(VOID)
|
| 765 | {
|
| 766 | SINT32 i = 1;
|
| 767 |
|
| 768 | for(i = 1 ; (i <= g_zPb_ApIndex[0]) && (i < (ZPB_AP_MAX_RECORD+1)); i++)
|
| 769 | {
|
| 770 | g_zPb_ApIndex[i] = PBM_ERROR_NOT_FOUND;
|
| 771 | }
|
| 772 | }
|
| 773 |
|
| 774 | T_zPb_DbResult atPb_DelAllRecsFromPbmTable(T_zPb_DelInfo *pbPara)
|
| 775 | {
|
| 776 | T_zPb_DbResult result = ZPB_DB_OK;
|
| 777 | CHAR sql[ZPB_MAX_BYTES_DB] = {0};
|
| 778 |
|
| 779 | if(NULL == pbPara)
|
| 780 | {
|
| 781 | slog(PB_PRINT,SLOG_ERR,"pb:atPb_DelAllRecsFromPbmTable:invalid input\n");/*lint !e26*/
|
| 782 | return ZPB_DB_ERROR_INVALIDPTR;
|
| 783 | }
|
| 784 | snprintf(sql,sizeof(sql)-1,"delete from %s where Location=%d",ZPB_DB_PBM_TABLE, pbPara->delLocation);
|
| 785 | result = atPb_ExecDbSql(sql,NULL,NULL);
|
| 786 | slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DelAllRecsFromPbmTable:exec table %s result %d", ZPB_DB_PBM_TABLE,result);
|
| 787 |
|
| 788 | if(ZPB_LOCATION_USIM == pbPara->delLocation)
|
| 789 | {
|
| 790 | atPb_ClearSimPbmIndexArray();
|
| 791 | }
|
| 792 | else if(ZPB_LOCATION_AP == pbPara->delLocation)
|
| 793 | {
|
| 794 | atPb_ClearApPbmIndexArray();
|
| 795 | }
|
| 796 | else if(ZPB_LOCATION_ALL == pbPara->delLocation)
|
| 797 | {
|
| 798 | atPb_ClearSimPbmIndexArray();
|
| 799 | atPb_ClearApPbmIndexArray();
|
| 800 | }
|
| 801 | return result;
|
| 802 | }
|
| 803 |
|
| 804 |
|