[Feature][task-view-998]merge P56U10 version, ZXW code

Only Configure: No
Affected branch: master
Affected module: unknow
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: No
Doc Update: No

Change-Id: I466f2ab935c5ede0be1803c75518b2cc4f939c15
diff --git a/ap/app/zte_comm/phonebook/src/pb_db.c b/ap/app/zte_comm/phonebook/src/pb_db.c
index 7e3ac3f..ea0eb1d 100755
--- a/ap/app/zte_comm/phonebook/src/pb_db.c
+++ b/ap/app/zte_comm/phonebook/src/pb_db.c
@@ -1,327 +1,804 @@
-
+/**************************************************************************

+*

+*                  Copyright (c) 2013 ZTE Corporation.

+*

+***************************************************************************

+* Ä£ ¿é Ãû : Atserver-PB

+* ÎÄ ¼þ Ãû : pb_db.c

+* Ïà¹ØÎļþ :

+* ʵÏÖ¹¦ÄÜ : Pb Êý¾Ý¿â²Ù×÷½Ó¿Úº¯ÊýʵÏÖ

+* ×÷    Õß : syx

+* °æ    ±¾ : V1.0

+* Íê³ÉÈÕÆÚ : 2013-05-16

+* ÆäËü˵Ã÷ :

+**************************************************************************/

+

+/**************************************************************************

+* Ð޸ļǼ :

+***************************************************************************/

+/**************************************************************************

+* Ð޸ıàºÅ :

+* ÐÞ ¸Ä ÈË :

+* ÐÞ¸ÄÈÕÆÚ :

+* ÐÞ¸ÄÄÚÈÝ :

+**************************************************************************/

+

+/**************************************************************************

+* #includeÇø

+**************************************************************************/

 #include "pb_com.h"

-T_zPb_DbResult atPb_CreatDb(){T_zPb_DbResult result=ZPB_DB_OK;CHAR sql[
-ZPB_MAX_BYTES_DB]={(0x17bf+3885-0x26ec)};UINT32 count=(0x677+5507-0x1bfa);result
-=atPb_ExecDbSql(ZPB_CREATE_PBM_TABLE,NULL,NULL);if(ZPB_DB_OK!=result){slog(
-PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x63\x72\x65\x61\x74\x65\x20\x70\x62\x6d\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}result=atPb_ExecDbSql(
-ZPB_CREATE_PBM_SIM_CAPABILITY_TABLE,NULL,NULL);if(ZPB_DB_OK!=result){slog(
-PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x63\x72\x65\x61\x74\x65\x20\x70\x62\x6d\x5f\x73\x69\x6d\x5f\x63\x61\x70\x61\x62\x69\x6c\x69\x74\x79\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}result=atPb_ExecDbSql(
-ZPB_CREATE_PBM_DEVICE_CAPABILITY_TABLE,NULL,NULL);if(ZPB_DB_OK!=result){slog(
-PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x63\x72\x65\x61\x74\x65\x20\x70\x62\x6d\x5f\x64\x65\x76\x69\x63\x65\x5f\x63\x61\x70\x61\x62\x69\x6c\x69\x74\x79\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}snprintf(sql,sizeof(sql),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64"
-,ZPB_DB_PBM_TABLE,ZPB_LOCATION_USIM);result=atPb_ExecDbSql(sql,NULL,NULL);if(
-ZPB_DB_OK!=result){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x63\x72\x65\x61\x74\x65\x20\x70\x62\x6d\x5f\x64\x65\x76\x69\x63\x65\x5f\x63\x61\x70\x61\x62\x69\x6c\x69\x74\x79\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}memset(sql,(0x7c5+1762-0xea7),sizeof(sql));snprintf(sql,
-sizeof(sql)-(0x29f+1571-0x8c1),
-"\x73\x65\x6c\x65\x63\x74\x20\x63\x6f\x75\x6e\x74\x28\x2a\x29\x20\x66\x72\x6f\x6d\x20\x25\x73"
-,ZPB_DB_SIM_CAPABILITY_TABLE);(VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&
-count);if((0x373+2622-0xdb1)<count){memset(sql,(0x4d8+6944-0x1ff8),sizeof(sql));
-snprintf(sql,sizeof(sql)-(0x674+7098-0x222d),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x53\x69\x6d\x5f\x74\x79\x70\x65\x3e\x3d\x30"
-,ZPB_DB_SIM_CAPABILITY_TABLE);result=atPb_ExecDbSql(sql,NULL,NULL);if(ZPB_DB_OK
-!=result){slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x53\x65\x74\x53\x69\x6d\x43\x61\x70\x61\x63\x69\x74\x79\x54\x61\x62\x6c\x65\x3a\x66\x61\x69\x6c\x21" "\n"
-);return result;}}return ZPB_DB_OK;}T_zPb_DbResult atPb_DropDb(){T_zPb_DbResult 
-result=ZPB_DB_OK;CHAR sql[ZPB_MAX_BYTES_DB]={(0x1015+4461-0x2182)};result=
-atPb_ExecDbSql(ZTE_DROP_PBM_SQL,NULL,NULL);if(ZPB_DB_OK!=result){slog(PB_PRINT,
-SLOG_ERR,
-"\x61\x74\x50\x62\x5f\x44\x72\x6f\x70\x44\x62\x3a\x64\x65\x6c\x20\x70\x62\x6d\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}result=atPb_ExecDbSql(ZTE_DROP_PBM_DEVICE_SQL,NULL,NULL)
-;if(ZPB_DB_OK!=result){slog(PB_PRINT,SLOG_ERR,
-"\x61\x74\x50\x62\x5f\x44\x72\x6f\x70\x44\x62\x3a\x64\x65\x6c\x20\x70\x62\x6d\x5f\x64\x65\x76\x69\x63\x65\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}result=atPb_ExecDbSql(ZTE_DROP_PBM_SIM_SQL,NULL,NULL);if
-(ZPB_DB_OK!=result){slog(PB_PRINT,SLOG_ERR,
-"\x61\x74\x50\x62\x5f\x44\x72\x6f\x70\x44\x62\x3a\x64\x65\x6c\x20\x70\x62\x6d\x5f\x73\x69\x6d\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}result=atPb_ExecDbSql(ZTE_DROP_PBM_SIM_CAPABILITY_SQL,
-NULL,NULL);if(ZPB_DB_OK!=result){slog(PB_PRINT,SLOG_ERR,
-"\x61\x74\x50\x62\x5f\x44\x72\x6f\x70\x44\x62\x3a\x64\x65\x6c\x20\x70\x62\x6d\x5f\x73\x69\x6d\x5f\x63\x61\x70\x61\x62\x69\x6c\x69\x74\x79\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}result=atPb_ExecDbSql(ZTE_DROP_PBM_DEVICE_CAPABILITY_SQL
-,NULL,NULL);if(ZPB_DB_OK!=result){slog(PB_PRINT,SLOG_ERR,
-"\x61\x74\x50\x62\x5f\x44\x72\x6f\x70\x44\x62\x3a\x64\x65\x6c\x20\x70\x62\x6d\x5f\x64\x65\x76\x69\x63\x65\x5f\x63\x61\x70\x61\x62\x69\x6c\x69\x74\x79\x20\x74\x61\x62\x6c\x65\x20\x72\x65\x73\x75\x6c\x74\x20\x69\x73\x20\x25\x64" "\n"
-,result);return result;}return ZPB_DB_OK;}T_zPb_DbResult atPb_DbOpen(sqlite3**
-pDb){sqlite3*pTmpDb=NULL;if(NULL==pDb){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x69\x6e\x76\x61\x6c\x69\x64\x65\x20\x69\x6e\x70\x75\x74\x73\x2e"
-);return ZPB_DB_ERROR_INVALIDPTR;}slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x73\x71\x6c\x69\x74\x65\x33\x5f\x6f\x70\x65\x6e\x20\x63\x61\x6c\x6c"
-);
-#if (0x2197+446-0x2355)

-if(!fopen(ZPB_DB_PATH,"\x72")){file=fopen(ZPB_DB_PATH,"\x77");if(!file){printf(
-"\x75\x6e\x61\x62\x6c\x65\x20\x74\x6f\x20\x6f\x70\x65\x6e\x20\x20\x66\x69\x6c\x65\x20\x65\x74\x63\x5f\x72\x77\x2f\x70\x62\x6d\x2e\x64\x62" "\n"
-);}else{printf(
-"\x20\x6f\x70\x65\x6e\x20\x20\x66\x69\x6c\x65\x20\x65\x74\x63\x5f\x72\x77\x2f\x70\x62\x6d\x2e\x64\x62\x20\x66\x69\x6c\x65\x3d\x25\x64" "\n"
-,file);fclose(file);}}
-#endif

-if(sqlite3_open(ZPB_DB_PATH,&pTmpDb)){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x63\x61\x6e\x20\x6e\x6f\x74\x20\x6f\x70\x65\x6e\x20\x64\x62\x2c\x73\x71\x6c\x69\x74\x65\x33\x5f\x65\x72\x72\x6d\x73\x67\x3a\x25\x73\x2e"
-,sqlite3_errmsg(pTmpDb));(VOID)sqlite3_close(pTmpDb);return 
-ZPB_DB_ERROR_NOTOPENDB;}*pDb=pTmpDb;return ZPB_DB_OK;}T_zPb_DbResult 
-atPb_DbClose(sqlite3*pDb){if(NULL==pDb){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x69\x6e\x76\x61\x6c\x69\x64\x65\x20\x69\x6e\x70\x75\x74\x73\x2e"
-);return ZPB_DB_ERROR_INVALIDPTR;}if(sqlite3_close(pDb)){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x63\x61\x6e\x20\x6e\x6f\x74\x20\x63\x6c\x6f\x73\x65\x20\x64\x62"
-);return ZPB_DB_ERROR;}
+

+/**************************************************************************

+* ³£Á¿¶¨ÒåÇø

+**************************************************************************/

+

+/**************************************************************************

+* Êý¾Ý½á¹¹¶¨ÒåÇø

+**************************************************************************/

+/**************************************************************************

+* staticº¯ÊýÉùÃ÷Çø

+**************************************************************************/

+

+/**************************************************************************

+* È«¾Ö±äÁ¿¶¨ÒåÇø

+**************************************************************************/

+

+/**************************************************************************

+* º¯ÊýʵÏÖÇø

+**************************************************************************/

+T_zPb_DbResult atPb_CreatDb()

+{

+    T_zPb_DbResult  result                = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB] = {0};

+    UINT32          count                   = 0;

+    

+    result = atPb_ExecDbSql(ZPB_CREATE_PBM_TABLE,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm table result is %d\n", result);

+        return result;

+    }

+    /*create pbm_sim_capability table*/

+    result = atPb_ExecDbSql(ZPB_CREATE_PBM_SIM_CAPABILITY_TABLE,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm_sim_capability table result is %d\n", result);

+        return result;

+    }

+    /*create pbm_device_capability table*/

+    result = atPb_ExecDbSql(ZPB_CREATE_PBM_DEVICE_CAPABILITY_TABLE,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm_device_capability table result is %d\n", result);

+        return result;

+    }

+    /*ɾ³ýpbm±íÖÐλÖÃΪsim¿¨µÄµç»°±¾¼Ç¼*/

+    snprintf(sql,sizeof(sql),"delete from %s where Location=%d",ZPB_DB_PBM_TABLE, ZPB_LOCATION_USIM);

+    result = atPb_ExecDbSql(sql,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:create pbm_device_capability table result is %d\n", result);

+        return result;

+    }

+

+    memset(sql, 0, sizeof(sql));

+    snprintf(sql,sizeof(sql)-1,"select count(*) from %s",ZPB_DB_SIM_CAPABILITY_TABLE);

+    (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);

+    if(0 < count)

+    {

+        memset(sql, 0, sizeof(sql));

+        snprintf(sql,sizeof(sql)-1,"delete from %s where Sim_type>=0",ZPB_DB_SIM_CAPABILITY_TABLE);

+        result = atPb_ExecDbSql(sql,NULL,NULL);

+        if(ZPB_DB_OK != result)

+        {

+            slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetSimCapacityTable:fail!\n");

+            return result;

+        }

+    }

+    return ZPB_DB_OK;

+}

+

+T_zPb_DbResult atPb_DropDb()

+{

+	T_zPb_DbResult  result                = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB] = {0};

+

+	

+	result = atPb_ExecDbSql(ZTE_DROP_PBM_SQL,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm table result is %d\n", result);

+        return result;

+    }

+

+	result = atPb_ExecDbSql(ZTE_DROP_PBM_DEVICE_SQL,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_device table result is %d\n", result);

+        return result;

+    }

+

+	result = atPb_ExecDbSql(ZTE_DROP_PBM_SIM_SQL,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_sim table result is %d\n", result);

+        return result;

+    }

+

+	result = atPb_ExecDbSql(ZTE_DROP_PBM_SIM_CAPABILITY_SQL,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_sim_capability table result is %d\n", result);

+        return result;

+    }

+

+	result = atPb_ExecDbSql(ZTE_DROP_PBM_DEVICE_CAPABILITY_SQL,NULL,NULL);

+    if(ZPB_DB_OK != result)

+    {

+        slog(PB_PRINT,SLOG_ERR,"atPb_DropDb:del pbm_device_capability table result is %d\n", result);

+        return result;

+    }

+	

+	return ZPB_DB_OK;

+}

+

+T_zPb_DbResult atPb_DbOpen(sqlite3**pDb)

+{

+    sqlite3* pTmpDb = NULL;

+

+    if(NULL == pDb)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:invalide inputs.");/*lint  !e26*/

+        return ZPB_DB_ERROR_INVALIDPTR;

+    }

+    slog(PB_PRINT,SLOG_DEBUG,"pb:sqlite3_open call");/*lint  !e26*/

+

+#if 0

+	if(!fopen(ZPB_DB_PATH, "r"))

+	{

+		file = fopen(ZPB_DB_PATH, "w");

+		if(!file)

+		{

+	        printf("unable to open  file etc_rw/pbm.db\n");/*lint !e26*/

+

+		}

+		else

+		{

+			printf(" open  file etc_rw/pbm.db file=%d\n", file);

+			fclose(file);

+		}

+	}

+	#endif

+	if(sqlite3_open(ZPB_DB_PATH, &pTmpDb))

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:can not open db,sqlite3_errmsg:%s.",sqlite3_errmsg(pTmpDb));

+        (VOID) sqlite3_close(pTmpDb);

+        return ZPB_DB_ERROR_NOTOPENDB;

+    }

+    *pDb = pTmpDb;

+    return ZPB_DB_OK;

+}

+T_zPb_DbResult atPb_DbClose (sqlite3*pDb)

+{

+    if (NULL == pDb)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:invalide inputs.");/*lint  !e26*/

+        return ZPB_DB_ERROR_INVALIDPTR;

+    }

+    if(sqlite3_close(pDb))

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:can not close db");/*lint  !e26*/

+        return ZPB_DB_ERROR;

+    }

 #ifdef WEBS_SECURITY

-if(access(ZPB_TMP_PATH,F_OK)==(0x7ed+181-0x8a2)){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x74\x6d\x70\x20\x64\x62\x20\x73\x74\x61\x79");if(
-remove(ZPB_TMP_PATH)!=(0xb37+5205-0x1f8c)){slog(PB_PRINT,SLOG_ERR,
-"\x72\x65\x6d\x6f\x76\x65\x20\x5a\x50\x42\x5f\x54\x4d\x50\x5f\x50\x41\x54\x48\x20\x66\x61\x69\x6c"
-);}}if(rename(ZPB_SEC_PATH,ZPB_TMP_PATH)!=(0x1030+5248-0x24b0)){slog(PB_PRINT,
-SLOG_ERR,
-"\x72\x65\x6e\x61\x6d\x65\x20\x5a\x50\x42\x5f\x53\x45\x43\x5f\x50\x41\x54\x48\x20\x66\x61\x69\x6c"
-);}{char rnum_buf[(0x1565+3485-0x22ea)]={(0xd7b+4880-0x208b)};char cmd[
-(0x14f3+1868-0x1bbf)]={(0xe43+2558-0x1841)};sc_cfg_get(
-"\x72\x6e\x75\x6d\x5f\x61\x74",rnum_buf,sizeof(rnum_buf));snprintf(cmd,sizeof(
-cmd),
-"\x2f\x62\x69\x6e\x2f\x6f\x70\x65\x6e\x73\x73\x6c\x20\x65\x6e\x63\x20\x2d\x65\x20\x2d\x61\x65\x73\x32\x35\x36\x20\x2d\x73\x61\x6c\x74\x20\x2d\x69\x6e\x20\x25\x73\x20\x2d\x6f\x75\x74\x20\x25\x73\x20\x2d\x70\x61\x73\x73\x20\x70\x61\x73\x73\x3a\x25\x73"
-,ZPB_DB_PATH,ZPB_SEC_PATH,rnum_buf);zxic_system(cmd);if(access(ZPB_SEC_PATH,F_OK
-)==(0x1637+944-0x19e7)){if(remove(ZPB_TMP_PATH)!=(0x9eb+4596-0x1bdf)){slog(
-PB_PRINT,SLOG_ERR,
-"\x72\x65\x6d\x6f\x76\x65\x20\x5a\x50\x42\x5f\x54\x4d\x50\x5f\x50\x41\x54\x48\x31\x20\x66\x61\x69\x6c"
-);}}}
+	if(access(ZPB_TMP_PATH, F_OK) == 0)

+	{

+		slog(PB_PRINT,SLOG_ERR,"pb:pbm:tmp db stay");/*lint  !e26*/

+		if(remove(ZPB_TMP_PATH) != 0)

+		{

+			slog(PB_PRINT,SLOG_ERR,"remove ZPB_TMP_PATH fail");

+		}

+	}

+	if(rename(ZPB_SEC_PATH, ZPB_TMP_PATH) != 0)

+	{

+		slog(PB_PRINT,SLOG_ERR,"rename ZPB_SEC_PATH fail");

+	}

+	{

+		char rnum_buf[24] = {0};

+		char cmd[128] = {0};

+		

+		sc_cfg_get("rnum_at", rnum_buf, sizeof(rnum_buf));

+		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);

+		zxic_system(cmd);

+		if(access(ZPB_SEC_PATH, F_OK) == 0)

+		{

+			if(remove(ZPB_TMP_PATH) != 0)

+			{

+				slog(PB_PRINT,SLOG_ERR,"remove ZPB_TMP_PATH1 fail");

+			}

+		}

+	}

 #endif	

-return ZPB_DB_OK;}static check_sql_cmd(const char*pSql){if(pSql!=NULL){if(strstr
-(pSql,"\x3b")||strstr(pSql,"\x2d\x2d")){return(0x149d+3953-0x240e);}return
-(0x28b+6211-0x1acd);}return(0x6b7+2456-0x104f);}T_zPb_DbResult atPb_ExecDbSql(
-const char*pSql,sqlite3_callback callback,VOID*pFvarg){sqlite3*pDb=NULL;CHAR 
-dbErrMsg[(0x11eb+3354-0x1e85)]={(0x22b+5720-0x1883)};if(NULL==pSql){return 
-ZPB_DB_ERROR_INVALIDPTR;}
+    return ZPB_DB_OK;

+}

+

+static check_sql_cmd(const char *pSql)

+{

+	if(pSql != NULL)

+	{

+		if(strstr(pSql, ";") || strstr(pSql, "--"))

+		{

+			return 0;

+		}

+		return 1;

+	}

+	return 0;

+}

+

+T_zPb_DbResult atPb_ExecDbSql(const char *pSql, sqlite3_callback callback,VOID *pFvarg)

+{

+    sqlite3     *pDb           = NULL;

+    CHAR         dbErrMsg[128] = {0};

+    if(NULL == pSql)

+    {

+        return ZPB_DB_ERROR_INVALIDPTR;

+    }

 #ifdef WEBS_SECURITY

-if(check_sql_cmd(pSql)==(0xa76+5764-0x20fa)){slog(PB_PRINT,SLOG_ERR,
-"\x21\x21\x61\x74\x50\x62\x5f\x45\x78\x65\x63\x44\x62\x53\x71\x6c\x3a\x78\x73\x73\x20\x25\x73" "\n"
-,pSql);return ZPB_DB_ERROR_INVALIDPTR;}
+	if(check_sql_cmd(pSql) == 0)

+	{

+        slog(PB_PRINT,SLOG_ERR,"!!atPb_ExecDbSql:xss %s\n",pSql);

+        return ZPB_DB_ERROR_INVALIDPTR;

+	}

 #endif	

-if(ZPB_DB_OK!=atPb_DbOpen(&pDb)){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x6f\x70\x65\x6e\x20\x70\x62\x6d\x2e\x64\x62\x20\x66\x61\x69\x6c\x65\x64\x2e"
-);return ZPB_DB_ERROR_NOTOPENDB;}slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x45\x78\x65\x63\x44\x62\x53\x71\x6c\x3a\x25\x73" "\n"
-,pSql);if(sqlite3_exec(pDb,pSql,callback,pFvarg,NULL)){strncpy(dbErrMsg,
-sqlite3_errmsg(pDb),sizeof(dbErrMsg)-(0x3d8+123-0x452));slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x63\x61\x6e\x20\x6e\x6f\x74\x20\x65\x78\x65\x63\x20\x73\x71\x6c\x2c\x73\x71\x6c\x69\x74\x65\x33\x5f\x65\x72\x72\x6d\x73\x67\x3a\x25\x73\x2e"
-,dbErrMsg);(VOID)sqlite3_close(pDb);return ZPB_DB_ERROR;}(VOID)atPb_DbClose(pDb)
-;return ZPB_DB_OK;}SINT32 atPb_InitApIndexCb(VOID*fvarg,int line,char**zresult,
-char**lname){SINT32 index=(0x1ab8+2955-0x2643);if((0x698+5816-0x1d4f)>line){slog
-(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x49\x6e\x69\x74\x41\x70\x49\x6e\x64\x65\x78\x43\x62\x3a\x72\x65\x63\x6f\x72\x64\x20\x6e\x6f\x20\x64\x61\x74\x61\x2e" "\n"
-);return-(0xaec+2311-0x13f2);}index=atoi(zresult[(0xb28+6501-0x248d)]);if(index>
-ZPB_AP_MAX_RECORD){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x49\x6e\x69\x74\x41\x70\x49\x6e\x64\x65\x78\x43\x62\x3a\x69\x6e\x64\x65\x78\x20\x6f\x76\x65\x72\x66\x6c\x6f\x77\x2e" "\n"
-);return-(0x120f+3797-0x20e3);}slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x49\x6e\x69\x74\x41\x70\x49\x6e\x64\x65\x78\x43\x62\x3a\x70\x62\x6d\x5f\x69\x6e\x64\x65\x78\x3d\x25\x64" "\n"
-,index);g_zPb_ApIndex[index]=PBM_SUCCESS;return(0x1207+2834-0x1d19);}
-T_zPb_DbResult atPb_InitApIndex(){CHAR sql[ZPB_MAX_BYTES_DB]={
-(0x2160+1016-0x2558)};SINT32 i=(0xec8+3074-0x1ac9);g_zPb_ApIndex[
-(0x7e0+2610-0x1212)]=ZPB_AP_MAX_RECORD;for(i=(0x4a0+2443-0xe2a);i<=g_zPb_ApIndex
-[(0x11a1+2820-0x1ca5)];i++){g_zPb_ApIndex[i]=PBM_ERROR_NOT_FOUND;}snprintf(sql,
-sizeof(sql),
-"\x73\x65\x6c\x65\x63\x74\x20\x50\x62\x6d\x5f\x69\x6e\x64\x65\x78\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64"
-,ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP);return atPb_ExecDbSql(sql,atPb_InitApIndexCb,
-ZUFI_NULL);}INT zte_pbm_check_and_creat_dir(char*path){if(-(0xe16+5704-0x245d)==
-access(path,(0x5ac+8376-0x2664))){slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x25\x73\x20\x64\x6f\x65\x73\x20\x6e\x6f\x74\x20\x65\x78\x69\x73\x74\x2c\x73\x6f\x63\x72\x65\x61\x74\x65\x20\x69\x74\x2e" "\n"
-,ZPB_DB_DIR);if(-(0x1c30+1852-0x236b)==mkdir(path,(0x656+3578-0x1251))){slog(
-PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x3a\x66\x61\x69\x6c\x65\x64\x20\x74\x6f\x20\x63\x72\x65\x61\x74\x65\x20\x64\x62\x20\x64\x69\x72\x2e" "\n"
-);return-(0xc46+633-0xebe);}}return(0xcca+563-0xefd);}UINT8 
-zte_pbm_check_web_pbm_dir(VOID){
+    if(ZPB_DB_OK != atPb_DbOpen(&pDb))

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:open pbm.db failed.");/*lint  !e26*/

+        return ZPB_DB_ERROR_NOTOPENDB;

+    }

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_ExecDbSql:%s\n",pSql);

+

+    if(sqlite3_exec(pDb,pSql,callback,pFvarg,NULL))

+    {

+        strncpy(dbErrMsg,sqlite3_errmsg(pDb),sizeof(dbErrMsg)-1);

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:can not exec sql,sqlite3_errmsg:%s.",dbErrMsg);

+        (VOID)sqlite3_close(pDb);

+        return ZPB_DB_ERROR;

+    }

+    (VOID)atPb_DbClose(pDb);

+    return ZPB_DB_OK;

+}

+

+SINT32 atPb_InitApIndexCb(VOID *fvarg,int line,char **zresult,char **lname)

+{

+	SINT32  index = 0;

+	

+    if(1 > line)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:atPb_InitApIndexCb:record no data.\n");/*lint  !e26*/

+        return -1;

+    }

+

+    index = atoi(zresult[0]);

+	if (index > ZPB_AP_MAX_RECORD) {

+        slog(PB_PRINT,SLOG_ERR,"pb:atPb_InitApIndexCb:index overflow.\n");

+        return -1;

+    }

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_InitApIndexCb:pbm_index=%d\n",index);

+    g_zPb_ApIndex[index] = PBM_SUCCESS;

+

+    return 0;

+}

+

+T_zPb_DbResult atPb_InitApIndex()

+{

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+    SINT32          i                       = 1;

+

+    g_zPb_ApIndex[0] = ZPB_AP_MAX_RECORD;

+

+    for(i=1; i<=g_zPb_ApIndex[0]; i++)

+    {

+        g_zPb_ApIndex[i] = PBM_ERROR_NOT_FOUND;

+    }

+    snprintf(sql,sizeof(sql),"select Pbm_index from %s where Location=%d",ZPB_DB_PBM_TABLE, ZPB_LOCATION_AP);

+    return atPb_ExecDbSql(sql,atPb_InitApIndexCb,ZUFI_NULL);

+}

+

+/*check whether the web pbm dir exist or not*/

+INT zte_pbm_check_and_creat_dir(char *path)

+{

+    if (-1==access(path,/*F_OK*/0))

+    {

+        slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:%s does not exist,socreate it.\n",ZPB_DB_DIR);

+        if (-1 == mkdir(path, 0777))

+        {

+            slog(PB_PRINT,SLOG_ERR,"pb::failed to create db dir.\n");

+            return -1;

+        }

+    }

+    return 0;

+}

+

+UINT8 zte_pbm_check_web_pbm_dir(VOID)

+{

 #ifdef _MBB_OS_UCLINUX

-(VOID)zte_pbm_check_and_creat_dir(
-"\x2f\x6d\x6e\x74\x2f\x6a\x66\x66\x73\x32\x2f\x65\x74\x63\x5f\x72\x77");(VOID)
-zte_pbm_check_and_creat_dir(
-"\x2f\x6d\x6e\x74\x2f\x6a\x66\x66\x73\x32\x2f\x65\x74\x63\x5f\x72\x77\x2f\x63\x6f\x6e\x66\x69\x67"
-);
+	(VOID)zte_pbm_check_and_creat_dir("/mnt/jffs2/etc_rw");

+    (VOID)zte_pbm_check_and_creat_dir("/mnt/jffs2/etc_rw/config");

 #else

-(VOID)zte_pbm_check_and_creat_dir("\x2f\x65\x74\x63\x5f\x72\x77");(VOID)
-zte_pbm_check_and_creat_dir(
-"\x2f\x65\x74\x63\x5f\x72\x77\x2f\x63\x6f\x6e\x66\x69\x67");
+(VOID)zte_pbm_check_and_creat_dir("/etc_rw");

+(VOID)zte_pbm_check_and_creat_dir("/etc_rw/config");

 #endif

-return ZUFI_SUCC;}T_zPb_DbResult atPb_DelSimRecFromPbTable(SINT32 index){
-T_zPb_DbResult result=ZPB_DB_OK;CHAR sql[ZPB_MAX_BYTES_DB]={(0x197f+3239-0x2626)
-};snprintf(sql,sizeof(sql),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x6c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64\x20\x61\x6e\x64\x20\x50\x62\x6d\x5f\x69\x6e\x64\x65\x78\x3d\x25\x64"
-,ZPB_DB_PBM_TABLE,ZPB_LOCATION_USIM,index);result=atPb_ExecDbSql(sql,NULL,NULL);
-if(ZPB_DB_OK==result){g_zPb_SimIndex[index]=PBM_ERROR_NOT_FOUND;}return result;}
-T_zPb_DbResult atPb_LoadARecToPbmTable(T_zPb_WebContact*pbPara){T_zPb_DbResult 
-result=ZPB_DB_ERROR;CHAR sql[ZPB_MAX_BYTES_DB]={(0x1627+4219-0x26a2)};if(NULL==
-pbPara){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x4c\x6f\x61\x64\x41\x52\x65\x63\x54\x6f\x50\x62\x6d\x54\x61\x62\x6c\x65\x3a\x69\x6e\x76\x61\x6c\x69\x64\x20\x69\x6e\x70\x75\x74"
-);return ZPB_DB_ERROR_INVALIDPTR;}snprintf(sql,sizeof(sql),"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne) \

-			values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",ZPB_DB_PBM_TABLE,pbPara->pbIndex,pbPara->pbLocation,pbPara->mobilNumber,pbPara
-->pbType,pbPara->name,pbPara->homeNumber,pbPara->officeNumber,pbPara->email,
-pbPara->sne);result=atPb_ExecDbSql(sql,NULL,NULL);if(ZPB_DB_OK==result){CHAR 
-pbMax[(0x43f+803-0x730)]={(0x94b+5655-0x1f62)};sc_cfg_get(ZPB_NV_USIMINDEXMAX,
-pbMax,sizeof(pbMax));if((pbPara->pbIndex>=(0x598+2686-0x1015))&&(pbPara->pbIndex
-<=atoi(pbMax))){g_zPb_SimIndex[pbPara->pbIndex]=PBM_SUCCESS;}(VOID)sc_cfg_set(
-ZPB_NV_WRITE_FLAG,ZPB_OPERATE_SUC);}else{(VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG,
-ZPB_NEW_ERROR);}slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x65\x78\x65\x63\x20\x74\x61\x62\x6c\x65\x20\x25\x73\x20\x72\x65\x73\x75\x6c\x74\x20\x25\x64" "\n"
-,ZPB_DB_PBM_TABLE,result);return result;}VOID atPb_SqlModifyOneRec(
-T_zPb_WebContact*pbmPara,char*sql,int len){printf(
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x53\x71\x6c\x4d\x6f\x64\x69\x66\x79\x4f\x6e\x65\x52\x65\x63\x20\x65\x6e\x74\x65\x72"
-);if(ZPB_LOCATION_USIM==pbmPara->pbLocation){snprintf(sql,len,"update %s set Pbm_index=\'%d\',Location=\'%d\',Number=\'%s\',Type=\'%d\',Name=\'%s\',Anr=\'%s\', \

-        		Anr1=\'%s\',Email=\'%s\',Sne=\'%s\' where id=%d",ZPB_DB_PBM_TABLE,pbmPara->pbIndex,pbmPara->pbLocation,pbmPara->mobilNumber,
-pbmPara->pbType,pbmPara->name,pbmPara->homeNumber,pbmPara->officeNumber,pbmPara
-->email,pbmPara->sne,pbmPara->pbId);}else if(ZPB_LOCATION_AP==pbmPara->
-pbLocation){snprintf(sql,len,"update %s set Pbm_index=\'%d\',Location=\'%d\',Number=\'%s\',Type=\'%d\',Name=\'%s\',Anr=\'%s\', \

-					Anr1=\'%s\',Email=\'%s\',Sne=\'%s\',Pbm_group=\'%s\' where id=%d",ZPB_DB_PBM_TABLE,pbmPara->pbIndex,pbmPara->pbLocation,pbmPara->mobilNumber,
-pbmPara->pbType,pbmPara->name,pbmPara->homeNumber,pbmPara->officeNumber,pbmPara
-->email,pbmPara->sne,pbmPara->group,pbmPara->pbId);}}T_zPb_DbResult 
-atPb_DbGetParamCb(VOID*fvarg,int line,char**zresult,char**lname){T_zPb_Header 
-para={(0x904+4519-0x1aab)};if((0x1479+2419-0x1deb)>line){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x44\x62\x47\x65\x74\x50\x61\x72\x61\x6d\x43\x62\x3a\x72\x65\x63\x6f\x72\x64\x20\x6e\x6f\x20\x64\x61\x74\x61\x2e"
-);return ZPB_DB_ERROR;}para.pbIndex=atoi(zresult[(0x11cb+4266-0x2275)]);para.
-pbLocation=atoi(zresult[(0xddb+3424-0x1b3a)]);slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x44\x62\x47\x65\x74\x50\x61\x72\x61\x6d\x43\x62\x3a\x20\x69\x6e\x64\x65\x78\x3d\x25\x64\x2c\x6c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64"
-,para.pbIndex,para.pbLocation);memcpy(fvarg,&para,sizeof(para));return ZPB_DB_OK
-;}T_zPb_DbResult atPb_GetIndexLocationById(T_zPb_Header*pbPara){CHAR sql[
-ZPB_MAX_BYTES_DB]={(0x2013+801-0x2334)};snprintf(sql,sizeof(sql)-
-(0x1944+3076-0x2547),
-"\x73\x65\x6c\x65\x63\x74\x20\x50\x62\x6d\x5f\x69\x6e\x64\x65\x78\x2c\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x69\x64\x3d\x25\x64"
-,ZPB_DB_PBM_TABLE,pbPara->pbId);memset(pbPara,(0x250+7824-0x20e0),sizeof(
-T_zPb_Header));return atPb_ExecDbSql(sql,atPb_DbGetParamCb,pbPara);}VOID 
-atPb_SqlNewOneRec(T_zPb_WebContact*pbmPara,CHAR*sql,int len){if(
-ZPB_LOCATION_USIM==pbmPara->pbLocation){snprintf(sql,len,"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne)\

-    			values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",ZPB_DB_PBM_TABLE,pbmPara->pbIndex,pbmPara->pbLocation,pbmPara->mobilNumber,
-pbmPara->pbType,pbmPara->name,pbmPara->homeNumber,pbmPara->officeNumber,pbmPara
-->email,pbmPara->sne);}else if(ZPB_LOCATION_AP==pbmPara->pbLocation){snprintf(
-sql,len,"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne,Pbm_group)\

-				values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",ZPB_DB_PBM_TABLE,pbmPara->pbIndex,pbmPara->pbLocation,pbmPara->mobilNumber,
-pbmPara->pbType,pbmPara->name,pbmPara->homeNumber,pbmPara->officeNumber,pbmPara
-->email,pbmPara->sne,pbmPara->group);}}T_zPb_DbResult 
-atPb_WriteContactToPbmTable(T_zPb_WebContact*pPbRecord,BOOL pbNewFlag){
-T_zPb_DbResult result=ZPB_DB_OK;CHAR sql[ZPB_MAX_BYTES_DB]={(0xc67+4861-0x1f64)}
-;if(NULL==pPbRecord){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x57\x72\x69\x74\x65\x43\x6f\x6e\x74\x61\x63\x74\x54\x6f\x50\x62\x6d\x54\x61\x62\x6c\x65\x3a\x69\x6e\x76\x61\x6c\x69\x64\x20\x69\x6e\x70\x75\x74"
-);return ZPB_DB_ERROR_INVALIDPTR;}slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x57\x72\x69\x74\x65\x43\x6f\x6e\x74\x61\x63\x74\x54\x6f\x50\x62\x6d\x54\x61\x62\x6c\x65\x3a\x69\x6e\x70\x75\x74\x20\x69\x6e\x64\x65\x78\x20\x69\x73\x20\x25\x64\x2c\x6c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64" "\n"
-,pPbRecord->pbIndex,pPbRecord->pbLocation);if(TRUE==pbNewFlag){atPb_SqlNewOneRec
-(pPbRecord,sql,sizeof(sql));}else{atPb_SqlModifyOneRec(pPbRecord,sql,sizeof(sql)
-);}result=atPb_ExecDbSql(sql,NULL,NULL);if(ZPB_DB_OK==result){if(
-ZPB_LOCATION_USIM==pPbRecord->pbLocation){g_zPb_SimIndex[(pPbRecord->pbIndex)]=
-PBM_SUCCESS;}else if(ZPB_LOCATION_AP==pPbRecord->pbLocation){g_zPb_ApIndex[(
-pPbRecord->pbIndex)]=PBM_SUCCESS;}}return result;}SINT32 atPb_DbCountTableLineCb
-(VOID*fvarg,int line,char**zresult,char**lname){if((0x6a+9234-0x247b)>line){slog
-(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x72\x65\x63\x6f\x72\x64\x20\x6e\x6f\x20\x64\x61\x74\x61\x2e"
-);return-(0x1a19+334-0x1b66);}*(int*)fvarg=atoi(zresult[(0xf9d+2448-0x192d)]);
-return(0x14f2+2451-0x1e85);}T_zPb_DbResult atPb_SetSimCapacityTable(
-T_zPb_UsimCapacity pbPara){T_zPb_DbResult result=ZPB_DB_OK;CHAR sql[
-ZPB_MAX_BYTES_DB]={(0x5f4+6581-0x1fa9)};UINT32 count=(0xbcb+6172-0x23e7);
-snprintf(sql,sizeof(sql)-(0x1a32+1835-0x215c),
-"\x73\x65\x6c\x65\x63\x74\x20\x63\x6f\x75\x6e\x74\x28\x2a\x29\x20\x66\x72\x6f\x6d\x20\x25\x73"
-,ZPB_DB_SIM_CAPABILITY_TABLE);(VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&
-count);if((0x83b+5003-0x1bc6)<count){memset(sql,(0x78+2703-0xb07),sizeof(sql));
-snprintf(sql,sizeof(sql)-(0xc87+846-0xfd4),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x53\x69\x6d\x5f\x74\x79\x70\x65\x3e\x3d\x30"
-,ZPB_DB_SIM_CAPABILITY_TABLE);result=atPb_ExecDbSql(sql,NULL,NULL);if(ZPB_DB_OK
-!=result){slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x53\x65\x74\x53\x69\x6d\x43\x61\x70\x61\x63\x69\x74\x79\x54\x61\x62\x6c\x65\x3a\x66\x61\x69\x6c\x21" "\n"
-);return result;}}memset(sql,(0x126a+213-0x133f),sizeof(sql));snprintf(sql,
-sizeof(sql)-(0x91f+1686-0xfb4),"insert into %s (Sim_type,Max_record_number,Used_record_number,Max_number_len,Max_name_len,Max_anr_len,Max_anr1_len, \

-	          Max_email_len,Max_sne_len) values(\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')",ZPB_DB_SIM_CAPABILITY_TABLE,pbPara.simType,pbPara.maxRecordNum,pbPara.
-usedRecordNum,pbPara.maxNumberLen,pbPara.maxNameLen,pbPara.maxAnrLen,pbPara.
-maxAnr1Len,pbPara.maxEmailLen,pbPara.maxSneLen);slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x53\x65\x74\x53\x69\x6d\x43\x61\x70\x61\x63\x69\x74\x79\x54\x61\x62\x6c\x65\x3a\x6f\x6b\x21" "\n"
-);return atPb_ExecDbSql(sql,NULL,NULL);}T_zPb_DbResult atPb_SetApCapacityTable()
-{T_zPb_DbResult result=ZPB_DB_OK;CHAR sql[ZPB_MAX_BYTES_DB]={(0xdf4+4783-0x20a3)
-};SINT32 count=(0x1e4d+1940-0x25e1);T_zPb_ApCapacity pbPara={
-(0x1c3b+1800-0x2343)};snprintf(sql,sizeof(sql)-(0x14c0+3297-0x21a0),
-"\x73\x65\x6c\x65\x63\x74\x20\x63\x6f\x75\x6e\x74\x28\x2a\x29\x20\x66\x72\x6f\x6d\x20\x25\x73"
-,ZPB_DB_DEVICE_CAPABILITY_TABLE);(VOID)atPb_ExecDbSql(sql,
-atPb_DbCountTableLineCb,&count);if((0x18df+221-0x19bc)<count){memset(sql,
-(0x1c+6659-0x1a1f),sizeof(sql));snprintf(sql,sizeof(sql)-(0x10e0+2762-0x1ba9),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73",
-ZPB_DB_DEVICE_CAPABILITY_TABLE);result=atPb_ExecDbSql(sql,NULL,NULL);if(
-ZPB_DB_OK!=result){slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x53\x65\x74\x41\x70\x43\x61\x70\x61\x63\x69\x74\x79\x54\x61\x62\x6c\x65\x3a\x66\x61\x69\x6c\x21" "\n"
-);return result;}}memset(sql,(0xa61+6377-0x234a),sizeof(sql));snprintf(sql,
-sizeof(sql)-(0x4ad+6230-0x1d02),
-"\x73\x65\x6c\x65\x63\x74\x20\x63\x6f\x75\x6e\x74\x28\x2a\x29\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64"
-,ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP);result=atPb_ExecDbSql(sql,
-atPb_DbCountTableLineCb,&count);if(ZPB_DB_OK==result){pbPara.usedRecordNum=count
-;pbPara.maxRecordNum=ZPB_AP_MAX_RECORD;}slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x6d\x61\x78\x5f\x72\x65\x63\x5f\x6e\x75\x6d\x3d\x25\x64\x2c\x75\x73\x65\x64\x3d\x25\x64"
-,pbPara.maxRecordNum,pbPara.usedRecordNum);memset(sql,(0x1892+418-0x1a34),sizeof
-(sql));snprintf(sql,sizeof(sql)-(0x911+6386-0x2202),
-"\x69\x6e\x73\x65\x72\x74\x20\x69\x6e\x74\x6f\x20\x25\x73\x20\x28\x4d\x61\x78\x5f\x72\x65\x63\x6f\x72\x64\x5f\x6e\x75\x6d\x62\x65\x72\x2c\x55\x73\x65\x64\x5f\x72\x65\x63\x6f\x72\x64\x5f\x6e\x75\x6d\x62\x65\x72\x29\x20\x76\x61\x6c\x75\x65\x73\x28" "\'" "\x25\x64" "\'" "\x2c" "\'" "\x25\x64" "\'" "\x29"
-,ZPB_DB_DEVICE_CAPABILITY_TABLE,pbPara.maxRecordNum,pbPara.usedRecordNum);return
- atPb_ExecDbSql(sql,NULL,NULL);}T_zPb_DbResult atPb_DbGetIndexByGroupCb(VOID*
-fvarg,int line,char**zresult,char**lname){T_zPb_ApIndex*pbIndex=NULL;int i=
-(0x523+5894-0x1c29);if((0xc05+4139-0x1c2f)>line){return ZPB_DB_ERROR;}pbIndex=(
-T_zPb_ApIndex*)fvarg;i=pbIndex->count;slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x44\x62\x47\x65\x74\x49\x6e\x64\x65\x78\x42\x79\x47\x72\x6f\x75\x70\x43\x62\x20\x65\x6e\x74\x65\x72\x2c\x69\x3d\x25\x64" "\n"
-,i);pbIndex->apIndex[i+(0x63f+7847-0x24e5)]=atoi(zresult[(0x5e5+4079-0x15d4)]);
-slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x67\x65\x74\x5f\x69\x6e\x64\x65\x78\x5f\x62\x79\x5f\x67\x72\x6f\x75\x70\x5f\x63\x62\x3a\x70\x62\x6d\x5f\x69\x6e\x64\x65\x78\x3d\x25\x64"
-,pbIndex->apIndex[i+(0x1624+1631-0x1c82)]);pbIndex->count=i+(0x23c+2043-0xa36);
-slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x67\x65\x74\x5f\x69\x6e\x64\x65\x78\x5f\x62\x79\x5f\x67\x72\x6f\x75\x70\x5f\x63\x62\x3a\x70\x62\x6d\x20\x63\x6f\x75\x6e\x74\x20\x69\x73\x20\x25\x64"
-,pbIndex->count);return ZPB_DB_OK;}T_zPb_DbResult atPb_DelRecFromPbmTableByGroup
-(T_zPb_ApIndex*index){T_zPb_DbResult result=ZPB_DB_OK;CHAR sql[ZPB_MAX_BYTES_DB]
-={(0x5f+1373-0x5bc)};SINT32 countByGroup=(0xebf+267-0xfca);CHAR pbGroup[
-ZPB_PARAM_SIZE20]={(0x837+1702-0xedd)};sc_cfg_get(ZPB_NV_GROUP,pbGroup,sizeof(
-pbGroup));snprintf(sql,sizeof(sql)-(0x1090+3204-0x1d13),
-"\x73\x65\x6c\x65\x63\x74\x20\x63\x6f\x75\x6e\x74\x28\x2a\x29\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64\x20\x61\x6e\x64\x20\x28\x50\x62\x6d\x5f\x67\x72\x6f\x75\x70\x3d" "\"" "\x25\x73" "\"" "\x29"
-,ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP,pbGroup);(VOID)atPb_ExecDbSql(sql,
-atPb_DbCountTableLineCb,&countByGroup);memset(sql,(0x1d41+1412-0x22c5),sizeof(
-sql));snprintf(sql,sizeof(sql)-(0xbc5+84-0xc18),
-"\x73\x65\x6c\x65\x63\x74\x20\x50\x62\x6d\x5f\x69\x6e\x64\x65\x78\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64\x20\x61\x6e\x64\x20\x28\x50\x62\x6d\x5f\x67\x72\x6f\x75\x70\x3d" "\"" "\x25\x73" "\"" "\x29"
-,ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP,pbGroup);result=atPb_ExecDbSql(sql,
-atPb_DbGetIndexByGroupCb,index);if(countByGroup==index->count){memset(sql,
-(0x7e8+6380-0x20d4),sizeof(sql));snprintf(sql,sizeof(sql)-(0x189d+1369-0x1df5),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64\x20\x61\x6e\x64\x20\x28\x50\x62\x6d\x5f\x67\x72\x6f\x75\x70\x3d" "\"" "\x25\x73" "\"" "\x29"
-,ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP,pbGroup);if(ZPB_DB_OK==atPb_ExecDbSql(sql,NULL
-,NULL)){(VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG,ZPB_OPERATE_SUC);}slog(PB_PRINT,
-SLOG_DEBUG,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x65\x78\x65\x63\x20\x74\x61\x62\x6c\x65\x20\x25\x73\x20\x72\x65\x73\x75\x6c\x74\x20\x25\x64" "\n"
-,ZPB_DB_PBM_TABLE,result);}else{return ZPB_DB_ERROR;}(VOID)sc_cfg_set(
-ZPB_NV_GROUP,"");return result;}VOID atPb_GetLocationIndexForDel(T_zPb_DelInfo*
-recData,SINT32 delTime){T_zPb_Header pbHeader={(0x50d+1274-0xa07)};if(NULL==
-recData){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x47\x65\x74\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x49\x6e\x64\x65\x78\x46\x6f\x72\x44\x65\x6c\x2d\x2d\x69\x6e\x76\x61\x6c\x69\x64\x20\x69\x6e\x70\x75\x74" "\n"
-);return;}pbHeader.pbId=recData->delId[delTime];if(ZPB_DB_OK!=
-atPb_GetIndexLocationById(&pbHeader)){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x66\x69\x6e\x64\x20\x69\x6e\x64\x65\x78\x20\x61\x6e\x64\x20\x6c\x6f\x63\x61\x74\x69\x6f\x6e\x20\x66\x61\x69\x6c\x65\x64"
-);return;}recData->delIndex[delTime]=pbHeader.pbIndex;recData->delLocation=
-pbHeader.pbLocation;slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x64\x65\x6c\x20\x69\x6e\x64\x65\x78\x3d\x25\x64\x2c\x6c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64\x2c\x64\x65\x6c\x5f\x70\x62\x6d\x5f\x74\x69\x6d\x65\x3d\x25\x64"
-,recData->delIndex[delTime],recData->delLocation,delTime);}T_zPb_DbResult 
-atPb_DelARecFromPbmTable(T_zPb_DelInfo*pbPara,SINT32 delTime){T_zPb_DbResult 
-result=ZPB_DB_OK;CHAR sql[ZPB_MAX_BYTES_DB]={(0x1603+2123-0x1e4e)};if(NULL==
-pbPara){slog(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x70\x62\x6d\x3a\x69\x6e\x76\x61\x6c\x69\x64\x20\x69\x6e\x70\x75\x74"
-);return ZPB_DB_ERROR_INVALIDPTR;}atPb_GetLocationIndexForDel(pbPara,delTime);
-slog(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x44\x65\x6c\x41\x52\x65\x63\x46\x72\x6f\x6d\x50\x62\x6d\x54\x61\x62\x6c\x65\x20\x65\x6e\x74\x65\x72\x2c\x64\x65\x6c\x54\x69\x6d\x65\x3d\x25\x64\x2c\x69\x64\x3d\x25\x64" "\n"
-,delTime,pbPara->delId[delTime]);snprintf(sql,sizeof(sql)-(0xa9d+31-0xabb),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x69\x64\x3d\x25\x64"
-,ZPB_DB_PBM_TABLE,pbPara->delId[delTime]);result=atPb_ExecDbSql(sql,NULL,NULL);
-if(ZPB_DB_OK==result){if(ZPB_LOCATION_AP==pbPara->delLocation){g_zPb_ApIndex[(
-pbPara->delIndex[delTime])]=PBM_ERROR_NOT_FOUND;}else if(ZPB_LOCATION_USIM==
-pbPara->delLocation){g_zPb_SimIndex[(pbPara->delIndex[delTime])]=
-PBM_ERROR_NOT_FOUND;}}return result;}VOID atPb_ClearSimPbmIndexArray(VOID){
-SINT32 i=(0xff+4212-0x1172);for(i=(0x1127+5041-0x24d7);(i<=g_zPb_SimIndex[
-(0x1634+3491-0x23d7)])&&(i<(ZPB_SIM_MAX_RECORD+(0x16bc+555-0x18e6)));i++){
-g_zPb_SimIndex[i]=PBM_ERROR_NOT_FOUND;}}VOID atPb_ClearApPbmIndexArray(VOID){
-SINT32 i=(0x66b+2883-0x11ad);for(i=(0x155a+956-0x1915);(i<=g_zPb_ApIndex[
-(0x254+4705-0x14b5)])&&(i<(ZPB_AP_MAX_RECORD+(0x4ab+8038-0x2410)));i++){
-g_zPb_ApIndex[i]=PBM_ERROR_NOT_FOUND;}}T_zPb_DbResult 
-atPb_DelAllRecsFromPbmTable(T_zPb_DelInfo*pbPara){T_zPb_DbResult result=
-ZPB_DB_OK;CHAR sql[ZPB_MAX_BYTES_DB]={(0x602+6240-0x1e62)};if(NULL==pbPara){slog
-(PB_PRINT,SLOG_ERR,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x44\x65\x6c\x41\x6c\x6c\x52\x65\x63\x73\x46\x72\x6f\x6d\x50\x62\x6d\x54\x61\x62\x6c\x65\x3a\x69\x6e\x76\x61\x6c\x69\x64\x20\x69\x6e\x70\x75\x74" "\n"
-);return ZPB_DB_ERROR_INVALIDPTR;}snprintf(sql,sizeof(sql)-(0x41c+1190-0x8c1),
-"\x64\x65\x6c\x65\x74\x65\x20\x66\x72\x6f\x6d\x20\x25\x73\x20\x77\x68\x65\x72\x65\x20\x4c\x6f\x63\x61\x74\x69\x6f\x6e\x3d\x25\x64"
-,ZPB_DB_PBM_TABLE,pbPara->delLocation);result=atPb_ExecDbSql(sql,NULL,NULL);slog
-(PB_PRINT,SLOG_DEBUG,
-"\x70\x62\x3a\x61\x74\x50\x62\x5f\x44\x65\x6c\x41\x6c\x6c\x52\x65\x63\x73\x46\x72\x6f\x6d\x50\x62\x6d\x54\x61\x62\x6c\x65\x3a\x65\x78\x65\x63\x20\x74\x61\x62\x6c\x65\x20\x25\x73\x20\x72\x65\x73\x75\x6c\x74\x20\x25\x64"
-,ZPB_DB_PBM_TABLE,result);if(ZPB_LOCATION_USIM==pbPara->delLocation){
-atPb_ClearSimPbmIndexArray();}else if(ZPB_LOCATION_AP==pbPara->delLocation){
-atPb_ClearApPbmIndexArray();}else if(ZPB_LOCATION_ALL==pbPara->delLocation){
-atPb_ClearSimPbmIndexArray();atPb_ClearApPbmIndexArray();}return result;}
+    return ZUFI_SUCC;

+}

+

+T_zPb_DbResult atPb_DelSimRecFromPbTable(SINT32 index)

+{

+    T_zPb_DbResult  result                  = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+

+    snprintf(sql,sizeof(sql),"delete from %s where location=%d and Pbm_index=%d",ZPB_DB_PBM_TABLE, ZPB_LOCATION_USIM,index);

+    result = atPb_ExecDbSql(sql,NULL,NULL);

+

+    if(ZPB_DB_OK == result)

+    {

+        g_zPb_SimIndex[index] = PBM_ERROR_NOT_FOUND;

+    }

+    return result;

+}

+

+T_zPb_DbResult atPb_LoadARecToPbmTable(T_zPb_WebContact *pbPara)

+{

+    T_zPb_DbResult  result                  = ZPB_DB_ERROR;

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+    if(NULL == pbPara)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:atPb_LoadARecToPbmTable:invalid input");/*lint  !e26*/

+        return ZPB_DB_ERROR_INVALIDPTR;

+    }

+    snprintf(sql,sizeof(sql),"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne) \

+			values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",

+            ZPB_DB_PBM_TABLE,

+            pbPara->pbIndex,

+            pbPara->pbLocation,

+            pbPara->mobilNumber,

+            pbPara->pbType,

+            pbPara->name,

+            pbPara->homeNumber,

+            pbPara->officeNumber,

+            pbPara->email,

+            pbPara->sne);

+    result = atPb_ExecDbSql(sql,NULL,NULL);

+    if(ZPB_DB_OK==result)

+    {

+        CHAR pbMax[50]={0};

+        sc_cfg_get(ZPB_NV_USIMINDEXMAX,pbMax,sizeof(pbMax));

+        if((pbPara->pbIndex>=1)&&(pbPara->pbIndex <= atoi(pbMax)))/*Comment: Èç¹ûµç»°±¾ÔÚË÷ÒýÄÚ,ZhaoYong,2008/12/23  10:49 */

+        {

+            g_zPb_SimIndex[pbPara->pbIndex] = PBM_SUCCESS;

+        }

+        (VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG, ZPB_OPERATE_SUC);

+    }

+    else

+    {

+        (VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG, ZPB_NEW_ERROR);

+    }

+    slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:exec table %s result %d\n", ZPB_DB_PBM_TABLE,result);

+    return result;

+}

+

+VOID atPb_SqlModifyOneRec(T_zPb_WebContact *pbmPara,char *sql,int len)

+{

+    printf("pb:atPb_SqlModifyOneRec enter");/*lint  !e26*/

+

+    if(ZPB_LOCATION_USIM == pbmPara->pbLocation)

+    {

+        snprintf(sql,len,"update %s set Pbm_index=\'%d\',Location=\'%d\',Number=\'%s\',Type=\'%d\',Name=\'%s\',Anr=\'%s\', \

+        		Anr1=\'%s\',Email=\'%s\',Sne=\'%s\' where id=%d",

+                ZPB_DB_PBM_TABLE,

+                pbmPara->pbIndex,

+                pbmPara->pbLocation,

+                pbmPara->mobilNumber,

+                pbmPara->pbType,

+                pbmPara->name,

+                pbmPara->homeNumber,

+                pbmPara->officeNumber,

+                pbmPara->email,

+                pbmPara->sne,

+                pbmPara->pbId);

+    }

+    else if(ZPB_LOCATION_AP == pbmPara->pbLocation)

+    {

+        snprintf(sql,len,"update %s set Pbm_index=\'%d\',Location=\'%d\',Number=\'%s\',Type=\'%d\',Name=\'%s\',Anr=\'%s\', \

+					Anr1=\'%s\',Email=\'%s\',Sne=\'%s\',Pbm_group=\'%s\' where id=%d",

+                ZPB_DB_PBM_TABLE,

+                pbmPara->pbIndex,

+                pbmPara->pbLocation,

+                pbmPara->mobilNumber,

+                pbmPara->pbType,

+                pbmPara->name,

+                pbmPara->homeNumber,

+                pbmPara->officeNumber,

+                pbmPara->email,

+                pbmPara->sne,

+                pbmPara->group,

+                pbmPara->pbId);

+    }

+}

+

+T_zPb_DbResult atPb_DbGetParamCb(VOID *fvarg,int line,char **zresult,char **lname)

+{

+    T_zPb_Header para = {0};

+

+    if(1 > line)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:atPb_DbGetParamCb:record no data.");/*lint  !e26*/

+        return ZPB_DB_ERROR;

+    }

+

+    para.pbIndex      = atoi(zresult[0]);

+    para.pbLocation   = atoi(zresult[1]);

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DbGetParamCb: index=%d,location=%d", para.pbIndex, para.pbLocation);

+    memcpy(fvarg,&para,sizeof(para));

+    return ZPB_DB_OK;

+}

+T_zPb_DbResult atPb_GetIndexLocationById(T_zPb_Header *pbPara)

+{

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+

+    snprintf(sql,sizeof(sql)-1,"select Pbm_index,Location from %s where id=%d",

+            ZPB_DB_PBM_TABLE,

+            pbPara->pbId);

+

+    memset(pbPara, 0,sizeof(T_zPb_Header));

+    return atPb_ExecDbSql(sql,atPb_DbGetParamCb, pbPara);

+}

+

+VOID atPb_SqlNewOneRec(T_zPb_WebContact *pbmPara,CHAR *sql,int len)

+{

+    if(ZPB_LOCATION_USIM == pbmPara->pbLocation)

+    {

+        snprintf(sql,len,"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne)\

+    			values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",

+                ZPB_DB_PBM_TABLE,

+                pbmPara->pbIndex,

+                pbmPara->pbLocation,

+                pbmPara->mobilNumber,

+                pbmPara->pbType,

+                pbmPara->name,

+                pbmPara->homeNumber,

+                pbmPara->officeNumber,

+                pbmPara->email,

+                pbmPara->sne);

+

+    }

+    else if(ZPB_LOCATION_AP == pbmPara->pbLocation)

+    {

+        snprintf(sql,len,"insert into %s (Pbm_index,Location,Number,Type,Name,Anr,Anr1,Email,Sne,Pbm_group)\

+				values(\'%d\',\'%d\',\'%s\',\'%d\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\',\'%s\')",

+                ZPB_DB_PBM_TABLE,

+                pbmPara->pbIndex,

+                pbmPara->pbLocation,

+                pbmPara->mobilNumber,

+                pbmPara->pbType,

+                pbmPara->name,

+                pbmPara->homeNumber,

+                pbmPara->officeNumber,

+                pbmPara->email,

+                pbmPara->sne,

+                pbmPara->group);

+    }

+}

+

+

+T_zPb_DbResult atPb_WriteContactToPbmTable(T_zPb_WebContact *pPbRecord, BOOL pbNewFlag)

+{

+    T_zPb_DbResult  result                  = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+    //UINT8           ascName[ZPB_TEXT_SIZE_BYTES]={0};

+

+    if(NULL == pPbRecord)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:atPb_WriteContactToPbmTable:invalid input");/*lint  !e26*/

+        return ZPB_DB_ERROR_INVALIDPTR;

+    }

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_WriteContactToPbmTable:input index is %d,location=%d\n",pPbRecord->pbIndex,pPbRecord->pbLocation);

+

+    //atPb_EncodeNameToAscii(pbRecord->name,ascName);

+    if(TRUE == pbNewFlag)

+    {

+        atPb_SqlNewOneRec(pPbRecord,sql,sizeof(sql));

+    }

+    else

+    {

+        atPb_SqlModifyOneRec(pPbRecord,sql,sizeof(sql));

+    }

+    result = atPb_ExecDbSql(sql,NULL,NULL);

+

+    if(ZPB_DB_OK == result)

+    {

+        if(ZPB_LOCATION_USIM == pPbRecord->pbLocation)

+        {

+            g_zPb_SimIndex[(pPbRecord->pbIndex)] = PBM_SUCCESS;

+        }

+        else if(ZPB_LOCATION_AP == pPbRecord->pbLocation)

+        {

+            g_zPb_ApIndex[(pPbRecord->pbIndex)] = PBM_SUCCESS;

+        }

+        //(VOID)system("adb push /etc_rw/config/pbm.db /usr/zte/zte_conf/config");

+    }

+    return result;

+}

+

+

+

+SINT32 atPb_DbCountTableLineCb(VOID *fvarg,int line,char **zresult,char **lname)

+{

+    if(1 > line)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:record no data.");/*lint  !e26*/

+        return -1;

+    }

+    *(int*)fvarg = atoi(zresult[0]);

+

+    return 0;

+}

+

+T_zPb_DbResult atPb_SetSimCapacityTable(T_zPb_UsimCapacity pbPara)

+{

+    T_zPb_DbResult  result                  = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+    UINT32          count                   = 0;

+

+    snprintf(sql,sizeof(sql)-1,"select count(*) from %s",ZPB_DB_SIM_CAPABILITY_TABLE);

+    (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);

+    if(0 < count)

+    {

+        memset(sql, 0, sizeof(sql));

+        snprintf(sql,sizeof(sql)-1,"delete from %s where Sim_type>=0",ZPB_DB_SIM_CAPABILITY_TABLE);

+        result = atPb_ExecDbSql(sql,NULL,NULL);

+        if(ZPB_DB_OK != result)

+        {

+            slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetSimCapacityTable:fail!\n");

+            return result;

+        }

+    }

+

+    memset(sql, 0, sizeof(sql));

+    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, \

+	          Max_email_len,Max_sne_len) values(\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\',\'%d\')",

+            ZPB_DB_SIM_CAPABILITY_TABLE,

+            pbPara.simType,

+            pbPara.maxRecordNum,

+            pbPara.usedRecordNum,

+            pbPara.maxNumberLen,

+            pbPara.maxNameLen,

+            pbPara.maxAnrLen,

+            pbPara.maxAnr1Len,

+            pbPara.maxEmailLen,

+            pbPara.maxSneLen);

+    

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetSimCapacityTable:ok!\n");

+    return atPb_ExecDbSql(sql,NULL,NULL);

+}

+

+T_zPb_DbResult atPb_SetApCapacityTable()

+{

+    T_zPb_DbResult      result                  = ZPB_DB_OK;

+    CHAR                sql[ZPB_MAX_BYTES_DB]   = {0};

+    SINT32              count                   = 0;

+    T_zPb_ApCapacity    pbPara                  = {0};

+    snprintf(sql,sizeof(sql)-1,"select count(*) from %s",ZPB_DB_DEVICE_CAPABILITY_TABLE);

+    (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);

+    if(0 < count)

+    {

+        memset(sql, 0, sizeof(sql));

+        snprintf(sql,sizeof(sql)-1,"delete from %s",ZPB_DB_DEVICE_CAPABILITY_TABLE);

+        result = atPb_ExecDbSql(sql,NULL,NULL);

+        if(ZPB_DB_OK != result)

+        {

+            slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_SetApCapacityTable:fail!\n");

+            return result;

+        }

+    }

+    memset(sql, 0, sizeof(sql));

+    snprintf(sql,sizeof(sql)-1,"select count(*) from %s where Location=%d",ZPB_DB_PBM_TABLE,ZPB_LOCATION_AP);

+    result = atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&count);

+    if(ZPB_DB_OK == result)

+    {

+        pbPara.usedRecordNum = count;

+        pbPara.maxRecordNum  = ZPB_AP_MAX_RECORD;

+    }

+    slog(PB_PRINT,SLOG_DEBUG,"pb:max_rec_num=%d,used=%d",pbPara.maxRecordNum,pbPara.usedRecordNum);

+

+    memset(sql, 0, sizeof(sql));

+    snprintf(sql,sizeof(sql)-1,"insert into %s (Max_record_number,Used_record_number) values(\'%d\',\'%d\')",

+            ZPB_DB_DEVICE_CAPABILITY_TABLE,

+            pbPara.maxRecordNum,

+            pbPara.usedRecordNum);

+    return atPb_ExecDbSql(sql,NULL,NULL);

+}

+

+T_zPb_DbResult atPb_DbGetIndexByGroupCb(VOID *fvarg,int line,char **zresult,char **lname)

+{

+    T_zPb_ApIndex   *pbIndex    = NULL;

+    int             i           = 0;

+

+    if(1 > line)

+    {

+        return ZPB_DB_ERROR;

+    }

+

+    pbIndex = (T_zPb_ApIndex*)fvarg;

+    i = pbIndex->count;

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DbGetIndexByGroupCb enter,i=%d\n",i);

+

+    pbIndex->apIndex[i+1]= atoi(zresult[0]);

+    slog(PB_PRINT,SLOG_DEBUG,"pb:get_index_by_group_cb:pbm_index=%d",pbIndex->apIndex[i+1]);

+

+    pbIndex->count = i + 1;

+    slog(PB_PRINT,SLOG_DEBUG,"pb:get_index_by_group_cb:pbm count is %d",pbIndex->count);

+    return ZPB_DB_OK;

+}

+

+T_zPb_DbResult atPb_DelRecFromPbmTableByGroup(T_zPb_ApIndex *index)

+{

+    T_zPb_DbResult  result                      = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB]       = {0};

+    SINT32          countByGroup                = 0;

+    CHAR            pbGroup[ZPB_PARAM_SIZE20]   = {0};

+

+    sc_cfg_get(ZPB_NV_GROUP,pbGroup,sizeof(pbGroup));

+    snprintf(sql,sizeof(sql)-1,"select count(*) from %s where Location=%d and (Pbm_group=\"%s\")",

+            ZPB_DB_PBM_TABLE, ZPB_LOCATION_AP, pbGroup);

+    (VOID)atPb_ExecDbSql(sql,atPb_DbCountTableLineCb,&countByGroup);

+

+    memset(sql,0,sizeof(sql));

+    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);

+    result = atPb_ExecDbSql(sql,atPb_DbGetIndexByGroupCb, index);    /*lint !e64*/

+

+    if(countByGroup == index->count)

+    {

+        memset(sql,0,sizeof(sql));

+        snprintf(sql,sizeof(sql)-1,"delete from %s where Location=%d and (Pbm_group=\"%s\")",

+                ZPB_DB_PBM_TABLE,

+                ZPB_LOCATION_AP,

+                pbGroup);

+

+        if(ZPB_DB_OK == atPb_ExecDbSql(sql,NULL,NULL))

+        {

+            (VOID)sc_cfg_set(ZPB_NV_WRITE_FLAG, ZPB_OPERATE_SUC);

+        }

+        slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:exec table %s result %d\n", ZPB_DB_PBM_TABLE,result);

+    }

+    else

+    {

+        return ZPB_DB_ERROR;

+    }

+    /*write group nvconfig ""*/

+    (VOID)sc_cfg_set(ZPB_NV_GROUP, "");

+    return result;

+}

+

+VOID atPb_GetLocationIndexForDel(T_zPb_DelInfo *recData,SINT32 delTime)

+{

+    T_zPb_Header pbHeader = {0};

+

+    if(NULL == recData)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:atPb_GetLocationIndexForDel--invalid input\n");

+        return;

+    }

+

+    pbHeader.pbId = recData->delId[delTime];

+

+    if(ZPB_DB_OK != atPb_GetIndexLocationById(&pbHeader))

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:find index and location failed");

+        return;

+    }

+    recData->delIndex[delTime]  = pbHeader.pbIndex;

+    recData->delLocation        = pbHeader.pbLocation;

+    slog(PB_PRINT,SLOG_DEBUG,"pb:pbm:del index=%d,location=%d,del_pbm_time=%d",

+            recData->delIndex[delTime],recData->delLocation,delTime);

+}

+

+/* ¶ÌÐÅת´æ»òÐ޸쬏ÄΪÏÈ·¢atÃüÁÔÙ´æÊý¾Ý¿â£¬¹Ê´æ´¢³É¹¦¶øatÃüÁî·¢ËÍʧ°Üɾ³ý֮ǰ´æ´¢µÄ¶ÌÐÅÕâÖÖ³¡¾°²»´æÔÚ

+T_zPb_DbResult atPb_DelRecordFromDBWhenAddErr()

+{

+    T_zPb_DbResult  result                  = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+

+    sprintf(sql,"delete from %s where Pbm_index=%ld",ZPB_DB_PBM_TABLE,g_zPb_pbIndex);

+    result = atPb_ExecDbSql(sql,NULL,NULL);

+

+    if(ZPB_DB_OK == result)

+    {

+       g_zPb_SimIndex[g_zPb_pbIndex] = PBM_ERROR_NOT_FOUND;

+    }

+    

+    printf("[PB] atPb_DelRecordFromDBWhenAddErr  result=%d,g_zPb_pbIndex=%d\n", result,g_zPb_pbIndex);

+    g_zPb_pbIndex = 0;

+    return result;

+}*/

+

+

+T_zPb_DbResult atPb_DelARecFromPbmTable(T_zPb_DelInfo *pbPara, SINT32 delTime)

+{

+    T_zPb_DbResult  result                  = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+

+    if(NULL == pbPara)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:pbm:invalid input");

+        return ZPB_DB_ERROR_INVALIDPTR;

+    }

+    atPb_GetLocationIndexForDel(pbPara, delTime);//del_pbm_time);

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DelARecFromPbmTable enter,delTime=%d,id=%d\n",delTime,pbPara->delId[delTime]);

+

+    snprintf(sql,sizeof(sql)-1,"delete from %s where id=%d",ZPB_DB_PBM_TABLE,pbPara->delId[delTime]);//del_pbm_time]);// ÔÝʱÏȶ¨Îª0

+    result = atPb_ExecDbSql(sql,NULL,NULL);

+

+    if(ZPB_DB_OK == result)

+    {

+        if(ZPB_LOCATION_AP == pbPara->delLocation)

+        {

+            g_zPb_ApIndex[(pbPara->delIndex[delTime])] = PBM_ERROR_NOT_FOUND;

+        }

+        else if(ZPB_LOCATION_USIM == pbPara->delLocation)

+        {

+            g_zPb_SimIndex[(pbPara->delIndex[delTime])] = PBM_ERROR_NOT_FOUND;

+        }

+    }

+    return result;

+}

+VOID atPb_ClearSimPbmIndexArray(VOID)

+{

+    SINT32 i = 1;

+

+    for(i = 1; (i <= g_zPb_SimIndex[0]) && (i < (ZPB_SIM_MAX_RECORD+1)); i++)

+    {

+        g_zPb_SimIndex[i] = PBM_ERROR_NOT_FOUND;

+    }

+}

+

+VOID atPb_ClearApPbmIndexArray(VOID)

+{

+    SINT32 i = 1;

+

+    for(i = 1 ; (i <= g_zPb_ApIndex[0]) && (i < (ZPB_AP_MAX_RECORD+1)); i++)

+    {

+        g_zPb_ApIndex[i] = PBM_ERROR_NOT_FOUND;

+    }

+}

+

+T_zPb_DbResult atPb_DelAllRecsFromPbmTable(T_zPb_DelInfo *pbPara)

+{

+    T_zPb_DbResult  result                  = ZPB_DB_OK;

+    CHAR            sql[ZPB_MAX_BYTES_DB]   = {0};

+

+    if(NULL == pbPara)

+    {

+        slog(PB_PRINT,SLOG_ERR,"pb:atPb_DelAllRecsFromPbmTable:invalid input\n");/*lint  !e26*/

+        return ZPB_DB_ERROR_INVALIDPTR;

+    }

+    snprintf(sql,sizeof(sql)-1,"delete from %s where Location=%d",ZPB_DB_PBM_TABLE, pbPara->delLocation);

+    result = atPb_ExecDbSql(sql,NULL,NULL);

+    slog(PB_PRINT,SLOG_DEBUG,"pb:atPb_DelAllRecsFromPbmTable:exec table %s result %d", ZPB_DB_PBM_TABLE,result);

+

+    if(ZPB_LOCATION_USIM == pbPara->delLocation)

+    {

+        atPb_ClearSimPbmIndexArray();

+    }

+    else if(ZPB_LOCATION_AP == pbPara->delLocation)

+    {

+        atPb_ClearApPbmIndexArray();

+    }

+    else if(ZPB_LOCATION_ALL == pbPara->delLocation)

+    {

+        atPb_ClearSimPbmIndexArray();

+        atPb_ClearApPbmIndexArray();

+    }

+    return result;

+}

+

+