| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include "stdafx.h"
- #include "CConfigLocal.h"
- #include "Config.h"
- CConfigLocal::CConfigLocal()
- {
- m_res_num = 0;
- }
- CConfigLocal::~CConfigLocal()
- {
- }
- /*****************************************************************
- **【函数名称】 Load
- **【函数功能】 从配置文件中号码资源信息
- **【参数】 a_lpFileName 配置文件名
- **【返回值】
- ****************************************************************/
- void CConfigLocal::load()
- {
- char t_config_filename[128] = { 0 };
- strcpy(t_config_filename, "./TelRes.ini");
- // 读取配置文件头
- int nTotalCount = GetPrivateProfileInt("Head", "TotalCount", 0, t_config_filename);
- ASSERT(nTotalCount != 0);
- m_res_num = 0;
- // 读取单个命令的配置信息
- char t_item_name[32];
- char t_tel_num[32];
- // 读取配置文件内容
- for (int i = 0; i<nTotalCount; i++)
- {
- ZeroMemory(t_item_name, 32);
- sprintf_s(t_item_name, 32, "T%03d", i);
-
- ZeroMemory(t_tel_num, 32);
- GetPrivateProfileString("TEL_RES", t_item_name, "", t_tel_num, 31, t_config_filename);
-
- if (strlen(t_tel_num) == 0) {
- break;
- }
-
- string t_res_str;
- t_res_str = t_tel_num;
- m_ResSet.insert(t_res_str);
- m_res_num = m_ResSet.size();
-
- } // end for(TotalCount)
- return ;
- }
- bool CConfigLocal::isContains(char* p_tel)
- {
- if (m_res_num == 0)
- return true;
- if (p_tel == NULL)
- return false;
- if (strlen(p_tel) == 0)
- return false;
- char t_tel_buf[32] = { 0 };
- getCallNumFromSipAddr(p_tel, t_tel_buf);
-
- //string t_tel_str;
- //t_tel_str = t_tel_buf;
- set<string>::iterator it = m_ResSet.find(t_tel_buf);
- if (it != m_ResSet.end())
- {
- return true;
- }
- return false;
- }
- void CConfigLocal::getCallNumFromSipAddr(char* p_sip_uri, char* p_tel_buf)
- {
- if (p_sip_uri == NULL)
- return;
- if (p_tel_buf == NULL)
- return;
-
- char* t_p_pos;
- char t_szTmpAddr[200];
- lstrcpy(t_szTmpAddr, p_sip_uri);
- TCHAR *p = strstr(t_szTmpAddr, _T("@"));
- if (p != NULL)
- *p = 0;
- p = strstr(t_szTmpAddr, _T(":"));
- if (p == NULL)
- t_p_pos = t_szTmpAddr;
- else
- t_p_pos = p + 1;
- strncpy(p_tel_buf, t_p_pos, sizeof(p_tel_buf)-1);
- return;
- }
|