void CToxProto::BootstrapNodesFromIni(bool isIPv6) { if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH)))) { char fileName[MAX_PATH]; mir_strcpy(fileName, VARS(TOX_INI_PATH)); char *section, sections[MAX_PATH], value[MAX_PATH]; GetPrivateProfileSectionNamesA(sections, _countof(sections), fileName); section = sections; while (*section != NULL) { if (strstr(section, TOX_SETTINGS_NODE_PREFIX) == section) { GetPrivateProfileStringA(section, "IPv4", NULL, value, _countof(value), fileName); ptrA address(mir_strdup(value)); int port = GetPrivateProfileIntA(section, "Port", 33445, fileName); GetPrivateProfileStringA(section, "PubKey", NULL, value, _countof(value), fileName); ptrA pubKey(mir_strdup(value)); BootstrapNode(address, port, pubKey); if (isIPv6) { GetPrivateProfileStringA(section, "IPv6", NULL, value, _countof(value), fileName); address = mir_strdup(value); BootstrapNode(address, port, pubKey); } } section += mir_strlen(section) + 1; } } }
iniConfig::iniConfig(LPCSTR fileName) { this->fileName = fileName; SetLastError(ERROR_SUCCESS); GetPrivateProfileSectionNamesA(buffer, sizeof buffer, fileName); if (GetLastError() == ERROR_FILE_NOT_FOUND) logFile << "Config: file not found!" << std::endl; }
void TelnetReader::GetTelnetIPS() { telnetIPList_Aft.clear(); telnetIPList_Arp.clear(); if (path.empty()) { return; } int i; int iPos = 0; int iMaxCount; char chSectionNames[MAX_ALLSECTIONS] = {0}; //存放所有提出来的字符串 char chSection[MAX_SECTION] = {0}; //存放一个段名 string filename = path + "\\telnet.ini"; DWORD dw = GetPrivateProfileSectionNamesA(chSectionNames, MAX_ALLSECTIONS, filename.c_str()); if (dw == 0) { return; } //以下循环,截断到两个连续的0 for (i = 0; i < MAX_ALLSECTIONS; i++) { if (chSectionNames[i] == 0) if (0 == chSectionNames[i+1]) break; } iMaxCount = i + 1; //得到telnet.ini中所有的section list<string> sectionList; for (i = 0; i < iMaxCount; i++) { chSection[iPos++] = chSectionNames[i]; if (chSectionNames[i] == 0) { sectionList.push_back((string)chSection); memset(chSection, 0, MAX_SECTION); iPos=0; } } char IniBuff[50]; for (list<string>::iterator iter = sectionList.begin(); iter != sectionList.end(); ++iter) { ZeroMemory(IniBuff, 50); GetPrivateProfileStringA((*iter).c_str(), "HostIp", "", IniBuff, 50, filename.c_str()); string hostip = IniBuff; ZeroMemory(IniBuff, 50); GetPrivateProfileStringA((*iter).c_str(), "indicatorIndex", "", IniBuff, 50, filename.c_str()); string indicatorIndex = IniBuff; if (indicatorIndex == "20000") { telnetIPList_Aft.push_back(hostip); } else if(indicatorIndex == "20001") { telnetIPList_Arp.push_back(hostip); } } ////测试telnetIPList_Aft及telnetIPList_Arp //for (list<string>::iterator iter = telnetIPList_Aft.begin(); iter != telnetIPList_Aft.end(); ++iter) //{ // cout<<"telnet ip (by aft): "<<*iter<<endl; //} //for (list<string>::iterator iter = telnetIPList_Arp.begin(); iter != telnetIPList_Arp.end(); ++iter) //{ // cout<<"telnet ip (by arp): "<<*iter<<endl; //} }
/*********************************************************************** * GetPrivateProfileSectionNames (KERNEL.143) */ WORD WINAPI GetPrivateProfileSectionNames16( LPSTR buffer, WORD size, LPCSTR filename ) { return GetPrivateProfileSectionNamesA(buffer,size,filename); }
/*********************************************************************** * GetProfileSectionNames (KERNEL.142) */ WORD WINAPI GetProfileSectionNames16(LPSTR buffer, WORD size) { return GetPrivateProfileSectionNamesA(buffer,size,"win.ini"); }
void CToxProto::SearchByNameAsync(void *arg) { char *query = (char*)arg; char *name = strtok(query, "@"); char *domain = strtok(NULL, ""); int resolved = 0; if (IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH)))) { char fileName[MAX_PATH]; mir_strcpy(fileName, VARS(TOX_INI_PATH)); char *section, sections[MAX_PATH], value[TOX_PUBLIC_KEY_SIZE * 2]; GetPrivateProfileSectionNamesA(sections, _countof(sections), fileName); section = sections; while (*section != NULL) { if (strstr(section, "Dns_") == section) { GetPrivateProfileStringA(section, "Domain", NULL, value, _countof(value), fileName); ptrA dnsDomain(mir_strdup(value)); GetPrivateProfileStringA(section, "PubKey", NULL, value, _countof(value), fileName); ToxBinAddress dnsPubKey = value; if (domain == NULL || mir_strcmpi(domain, dnsDomain) == 0) { void *dns = tox_dns3_new((uint8_t*)(const uint8_t*)dnsPubKey); uint32_t requestId = 0; uint8_t dnsString[MAX_PATH]; size_t length = tox_generate_dns3_string(dns, dnsString, sizeof(dnsString), &requestId, (uint8_t*)CharLowerA(name), (uint8_t)mir_strlen(name)); if (length != TOX_ERROR) { dnsString[length] = 0; char dnsQuery[MAX_PATH * 2]; mir_snprintf(dnsQuery, "_%s._tox.%s", dnsString, dnsDomain); ToxHexAddress address = ResolveToxAddressFromDns(dnsQuery); if (!address.IsEmpty()) { PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) }; psr.flags = PSR_UTF8; psr.id.a = mir_strdup(address); psr.nick.a = mir_strdup(name); char email[MAX_PATH]; mir_snprintf(email, "%s@%s", name, domain); psr.email.a = mir_strdup(email); ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); break; } } tox_dns3_kill(dns); } } section += mir_strlen(section) + 1; } } if (resolved == 0 && domain) { char dnsQuery[MAX_PATH]; mir_snprintf(dnsQuery, "%s._tox.%s", name, domain); ToxHexAddress address = ResolveToxAddressFromDns(dnsQuery); if (!address.IsEmpty()) { PROTOSEARCHRESULT psr = { sizeof(PROTOSEARCHRESULT) }; psr.flags = PSR_UTF8; psr.id.a = mir_strdup(address); psr.nick.a = mir_strdup(name); char email[MAX_PATH]; mir_snprintf(email, "%s@%s", name, domain); psr.email.a = mir_strdup(email); ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_DATA, (HANDLE)1, (LPARAM)&psr); } } ProtoBroadcastAck(NULL, ACKTYPE_SEARCH, ACKRESULT_SUCCESS, (HANDLE)1, 0); mir_free(arg); }
static void test_profile_sections_names(void) { HANDLE h; int ret; DWORD count; char buf[100]; WCHAR bufW[100]; static const char content[]="[section1]\r\n[section2]\r\n[section3]\r\n"; static const char testfile3[]=".\\testwine3.ini"; static const WCHAR testfile3W[]={ '.','\\','t','e','s','t','w','i','n','e','3','.','i','n','i',0 }; static const WCHAR not_here[] = {'.','\\','n','o','t','_','h','e','r','e','.','i','n','i',0}; DeleteFileA( testfile3 ); h = CreateFileA( testfile3, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); ok( h != INVALID_HANDLE_VALUE, " cannot create %s\n", testfile3); if( h == INVALID_HANDLE_VALUE) return; WriteFile( h, content, sizeof(content), &count, NULL); CloseHandle( h); /* Test with sufficiently large buffer */ ret = GetPrivateProfileSectionNamesA( buf, 29, testfile3 ); ok( ret == 27, "expected return size 27, got %d\n", ret ); ok( buf[ret-1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" ); /* Test with exactly fitting buffer */ ret = GetPrivateProfileSectionNamesA( buf, 28, testfile3 ); ok( ret == 26, "expected return size 26, got %d\n", ret ); ok( buf[ret+1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" ); /* Test with a buffer too small */ ret = GetPrivateProfileSectionNamesA( buf, 27, testfile3 ); ok( ret == 25, "expected return size 25, got %d\n", ret ); ok( buf[ret+1] == 0 && buf[ret] == 0, "returned buffer not terminated with double-null\n" ); /* Tests on nonexistent file */ memset(buf, 0xcc, sizeof(buf)); ret = GetPrivateProfileSectionNamesA( buf, 10, ".\\not_here.ini" ); ok( ret == 0, "expected return size 0, got %d\n", ret ); ok( buf[0] == 0, "returned buffer not terminated with null\n" ); ok( buf[1] != 0, "returned buffer terminated with double-null\n" ); /* Test with sufficiently large buffer */ SetLastError(0xdeadbeef); ret = GetPrivateProfileSectionNamesW( bufW, 29, testfile3W ); if (ret == 0 && (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)) { skip("GetPrivateProfileSectionNamesW is not implemented\n"); DeleteFileA( testfile3 ); return; } ok( ret == 27, "expected return size 27, got %d\n", ret ); ok( bufW[ret-1] == 0 && bufW[ret] == 0, "returned buffer not terminated with double-null\n" ); /* Test with exactly fitting buffer */ ret = GetPrivateProfileSectionNamesW( bufW, 28, testfile3W ); ok( ret == 26, "expected return size 26, got %d\n", ret ); ok( bufW[ret+1] == 0 && bufW[ret] == 0, "returned buffer not terminated with double-null\n" ); /* Test with a buffer too small */ ret = GetPrivateProfileSectionNamesW( bufW, 27, testfile3W ); ok( ret == 25, "expected return size 25, got %d\n", ret ); ok( bufW[ret+1] == 0 && bufW[ret] == 0, "returned buffer not terminated with double-null\n" ); DeleteFileA( testfile3 ); /* Tests on nonexistent file */ memset(bufW, 0xcc, sizeof(bufW)); ret = GetPrivateProfileSectionNamesW( bufW, 10, not_here ); ok( ret == 0, "expected return size 0, got %d\n", ret ); ok( bufW[0] == 0, "returned buffer not terminated with null\n" ); ok( bufW[1] != 0, "returned buffer terminated with double-null\n" ); }
void ReadIniFile(HWND hwndDlg, const char* ini_file_drop) { ini_file_loaded=true; char section_names[2048]=""; char temp_name[256]=""; char lvl_text[10]=""; char md5_text[10]=""; char init_value[100]=""; char chk_text[10]="", diff_text[10]=""; int total_count=0; SendDlgItemMessageA(hwndDlg, IDC_LIST_CERTS, CB_RESETCONTENT, 0, 0); if(total_certs) { for(int i=0; i<total_certs; i++) { free(cert_names[i]); } free(cert_names); total_certs=0; cert_names=0; } int len_sections=GetPrivateProfileSectionNamesA(section_names, 2048, ini_file_drop); for(int i=0; i<len_sections; i++) { if(!section_names[i]) total_count++; } total_certs=total_count; cert_names=(char**)malloc(total_certs*4); for(int i=0,j=0; i<len_sections; i++) { if(section_names[i]) { sprintf(temp_name, "%s%c", temp_name, section_names[i]); } else { memset(lvl_text, 0, 10); GetPrivateProfileStringA(temp_name, "level", "", lvl_text, 10, ini_file_drop); if(!strcmp(lvl_text, "29")) { cert_names[j]=(char*)malloc(strlen(temp_name)+1); strcpy(cert_names[j], temp_name); j++; total_certs=j; } memset(temp_name, 0, 256); } } for(int i=0; i<total_certs; i++) { GetPrivateProfileStringA(cert_names[i], "chk", "", chk_text, 10, ini_file_drop); GetPrivateProfileStringA(cert_names[i], "diff", "", diff_text, 10, ini_file_drop); GetPrivateProfileStringA(cert_names[i], "md5", "", md5_text, 10, ini_file_drop); GetPrivateProfileStringA(cert_names[i], "pub", "", init_value, 100, ini_file_drop); char* test123=strtok(init_value, ",");; wsprintf(temp_name, "Checksum : %s - MD5 : %s - Diff : %08s - BasePoint : %s", chk_text, md5_text, diff_text, test123); AddListItem(hwndDlg, temp_name); memset(temp_name, 0, 256); } GetPrivateProfileStringA(cert_names[0], "first_dw", "", first_dword_text, 10, ini_file_drop); SendDlgItemMessageA(hwndDlg, IDC_LIST_CERTS, CB_SETCURSEL, 0, 0); GetPrivateProfileStringA(cert_names[0], "pub", "", cur_pub_text, 256, ini_file); GetPrivateProfileStringA(cert_names[0], "diff", "", cur_dif_text, 10, ini_file); GetPrivateProfileStringA(cert_names[0], "md5", "", cur_md5_text, 10, ini_file); //v9.60 support GetPrivateProfileStringA(cert_names[0], "seed1", "", cur_seed1_text, 10, ini_file); GetPrivateProfileStringA(cert_names[0], "seed2", "", cur_seed2_text, 10, ini_file); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_OLD, cur_pub_text); sprintf(temp_name, "%X", strlen(cur_pub_text)); SetDlgItemTextA(hwndDlg, IDC_EDT_PUBVALS_OLD_LEN, temp_name); EnableWindow(GetDlgItem(hwndDlg, IDC_EDT_TEMPLATE), 1); }
void CToxOptionsNodeList::OnInitDialog() { m_nodes.SetExtendedListViewStyle(LVS_EX_SUBITEMIMAGES | LVS_EX_FULLROWSELECT | LVS_EX_LABELTIP); HIMAGELIST hImageList = m_nodes.CreateImageList(LVSIL_SMALL); HICON icon = Skin_LoadIcon(SKINICON_OTHER_TYPING); ImageList_AddIcon(hImageList, icon); IcoLib_ReleaseIcon(icon); icon = Skin_LoadIcon(SKINICON_OTHER_DELETE); ImageList_AddIcon(hImageList, icon); IcoLib_ReleaseIcon(icon); m_nodes.AddColumn(0, _T("IPv4"), 100); m_nodes.AddColumn(1, _T("IPv6"), 100); m_nodes.AddColumn(2, TranslateT("Port"), 50); m_nodes.AddColumn(3, TranslateT("Public key"), 130); m_nodes.AddColumn(4, _T(""), 32 - GetSystemMetrics(SM_CXVSCROLL)); m_nodes.AddColumn(5, _T(""), 32 - GetSystemMetrics(SM_CXVSCROLL)); m_nodes.EnableGroupView(TRUE); m_nodes.AddGroup(0, TranslateT("Common nodes")); m_nodes.AddGroup(1, TranslateT("User nodes")); //////////////////////////////////////// int iItem = -1; if (CToxProto::IsFileExists((TCHAR*)VARST(_T(TOX_INI_PATH)))) { char fileName[MAX_PATH]; mir_strcpy(fileName, VARS(TOX_INI_PATH)); char *section, sections[MAX_PATH], value[MAX_PATH]; GetPrivateProfileSectionNamesA(sections, _countof(sections), fileName); section = sections; while (*section != NULL) { if (strstr(section, TOX_SETTINGS_NODE_PREFIX) == section) { GetPrivateProfileStringA(section, "IPv4", NULL, value, _countof(value), fileName); iItem = m_nodes.AddItem(mir_a2t(value), -1, NULL, 0); GetPrivateProfileStringA(section, "IPv6", NULL, value, _countof(value), fileName); m_nodes.SetItem(iItem, 1, mir_a2t(value)); GetPrivateProfileStringA(section, "Port", NULL, value, _countof(value), fileName); m_nodes.SetItem(iItem, 2, mir_a2t(value)); GetPrivateProfileStringA(section, "PubKey", NULL, value, _countof(value), fileName); m_nodes.SetItem(iItem, 3, mir_a2t(value)); } section += mir_strlen(section) + 1; } } char module[MAX_PATH], setting[MAX_PATH]; mir_snprintf(module, "%s_Nodes", m_proto->m_szModuleName); int nodeCount = db_get_w(NULL, module, TOX_SETTINGS_NODE_COUNT, 0); for (int i = 0; i < nodeCount; i++) { mir_snprintf(setting, TOX_SETTINGS_NODE_IPV4, i); ptrT value(db_get_tsa(NULL, module, setting)); iItem = m_nodes.AddItem(value, -1, NULL, 1); mir_snprintf(setting, TOX_SETTINGS_NODE_IPV6, i); value = db_get_tsa(NULL, module, setting); m_nodes.SetItem(iItem, 1, value); mir_snprintf(setting, TOX_SETTINGS_NODE_PORT, i); int port = db_get_w(NULL, module, setting, 0); if (port > 0) { char portNum[10]; itoa(port, portNum, 10); m_nodes.SetItem(iItem, 2, mir_a2t(portNum)); } mir_snprintf(setting, TOX_SETTINGS_NODE_PKEY, i); value = db_get_tsa(NULL, module, setting); m_nodes.SetItem(iItem, 3, value); m_nodes.SetItem(iItem, 4, _T(""), 0); m_nodes.SetItem(iItem, 5, _T(""), 1); } }