// Generate the Unicode string cache file name void GenerateUnicodeCacheFileName(wchar_t *name, UINT size, wchar_t *strfilename, UINT strfilesize, UCHAR *filehash) { wchar_t tmp[MAX_SIZE]; wchar_t hashstr[64]; wchar_t hashtemp[MAX_SIZE]; wchar_t exe[MAX_SIZE]; UCHAR hash[SHA1_SIZE]; // Validate arguments if (name == NULL || strfilename == NULL || filehash == NULL) { return; } GetExeDirW(exe, sizeof(exe)); UniStrCpy(hashtemp, sizeof(hashtemp), strfilename); BinToStrW(tmp, sizeof(tmp), filehash, MD5_SIZE); UniStrCat(hashtemp, sizeof(hashtemp), tmp); UniStrCat(hashtemp, sizeof(hashtemp), exe); UniStrLower(hashtemp); Hash(hash, hashtemp, UniStrLen(hashtemp) * sizeof(wchar_t), true); BinToStrW(hashstr, sizeof(hashstr), hash, 4); UniFormat(tmp, sizeof(tmp), UNICODE_CACHE_FILE, hashstr); UniStrLower(tmp); #ifndef OS_WIN32 UniStrCpy(exe, sizeof(exe), L"/tmp"); #else // OS_WIN32 StrToUni(exe, sizeof(exe), MsGetTempDir()); #endif // OS_WIN32 UniFormat(name, size, L"%s/%s", exe, tmp); NormalizePathW(name, size, name); }
// Get network connection name from Ethernet device name void GetEthNetworkConnectionName(wchar_t *dst, UINT size, char *device_name) { WP_ADAPTER *t; char *tmp = NULL, guid[MAX_SIZE]; wchar_t *ncname = NULL; UniStrCpy(dst, size, L""); // Validate arguments if (device_name == NULL || IsEthSupported() == false || IsNt() == false || MsIsWin2000OrGreater() == false) { return; } Lock(eth_list_lock); InitEthAdaptersList(); t = Win32EthSearch(device_name); if (t == NULL) { Unlock(eth_list_lock); return; } tmp = CopyStr(t->Name); Unlock(eth_list_lock); if (IsEmptyStr(t->Guid) == false) { StrCpy(guid, sizeof(guid), t->Guid); Free(tmp); } else { ReplaceStr(guid, sizeof(guid), tmp, "\\Device\\SEE_", ""); Free(tmp); ReplaceStr(guid, sizeof(guid), guid, "\\Device\\NPF_", ""); ReplaceStr(guid, sizeof(guid), guid, "\\Device\\PCD_", ""); } if(guid == NULL) { return; } ncname = MsGetNetworkConnectionName(guid); if(ncname != NULL) { UniStrCpy(dst, size, ncname); } Free(ncname); }
// Create a backup of the configuration file void BackupCfgWEx(CFG_RW *rw, FOLDER *f, wchar_t *original, UINT revision_number) { wchar_t dirname[MAX_PATH]; wchar_t filename[MAX_PATH]; wchar_t fullpath[MAX_PATH]; wchar_t datestr[MAX_PATH]; SYSTEMTIME st; // Validate arguments if (f == NULL || filename == NULL || rw == NULL) { return; } // Determine the directory name UniFormat(dirname, sizeof(dirname), L"@backup.%s", original[0] == L'@' ? original + 1 : original); // Determine the file name LocalTime(&st); UniFormat(datestr, sizeof(datestr), L"%04u%02u%02u%02u_%s", st.wYear, st.wMonth, st.wDay, st.wHour, original[0] == L'@' ? original + 1 : original); if (revision_number == INFINITE) { UniStrCpy(filename, sizeof(filename), datestr); } else { UniFormat(filename, sizeof(filename), L"%08u_%s", revision_number, original[0] == L'@' ? original + 1 : original); } // Don't save if the date and time has not been changed if (UniStrCmpi(datestr, rw->LastSavedDateStr) == 0) { return; } UniStrCpy(rw->LastSavedDateStr, sizeof(rw->LastSavedDateStr), datestr); // Check the existence of file name if (IsFileExistsW(filename)) { return; } // Create the directory MakeDirW(dirname); // Save the file UniFormat(fullpath, sizeof(fullpath), L"%s/%s", dirname, filename); CfgSaveW(f, fullpath); }
// Update void NmMainDlgRefresh(HWND hWnd, RPC *r) { #if 0 RPC_NAT_STATUS t; wchar_t tmp[MAX_SIZE]; wchar_t tmp2[MAX_SIZE]; // Validate arguments if (r == NULL || hWnd == NULL) { return; } Zero(&t, sizeof(RPC_NAT_STATUS)); CALL(hWnd, NcGetStatus(r, &t)); if (t.Online == false) { UniStrCpy(tmp, sizeof(tmp), _UU("NM_OFFLINE")); Enable(hWnd, B_CONNECT); Disable(hWnd, B_DISCONNECT); } else { if (t.Connected) { UniFormat(tmp, sizeof(tmp), _UU("NM_CONNECTED"), t.Status.ServerName); } else { if (t.LastError == ERR_NO_ERROR) { UniStrCpy(tmp, sizeof(tmp), _UU("NM_CONNECTING")); } else { UniFormat(tmp, sizeof(tmp), _UU("NM_CONNECT_ERROR"), t.LastError, _E(t.LastError)); } } Disable(hWnd, B_CONNECT); Enable(hWnd, B_DISCONNECT); } UniFormat(tmp2, sizeof(tmp2), _UU("NM_STATUS_TAG"), tmp); SetText(hWnd, S_STATUS, tmp2); FreeRpcNatStatus(&t); #endif }
// Evaluation whether the specified file exists bool CmdEvalIsFile(CONSOLE *c, wchar_t *str, void *param) { wchar_t tmp[MAX_PATH]; // Validate arguments if (c == NULL || str == NULL) { return false; } UniStrCpy(tmp, sizeof(tmp), str); if (IsEmptyUniStr(tmp)) { c->Write(c, _UU("CMD_FILE_NAME_EMPTY")); return false; } if (IsFileExistsW(tmp) == false) { wchar_t tmp2[MAX_SIZE]; UniFormat(tmp2, sizeof(tmp2), _UU("CMD_FILE_NOT_FOUND"), tmp); c->Write(c, tmp2); return false; } return true; }
// Format policy value void FormatPolicyValue(wchar_t *str, UINT size, UINT id, UINT value) { POLICY_ITEM *p; // Validate arguments if (str == NULL) { return; } p = GetPolicyItem(id); if (p->TypeInt == false) { // bool type if (value == 0) { UniStrCpy(str, size, L"No"); } else { UniStrCpy(str, size, L"Yes"); } } else { // int type if (value == 0 && p->AllowZero) { UniStrCpy(str, size, _UU("CMD_NO_SETTINGS")); } else { UniFormat(str, size, _UU(p->FormatStr), value); } } }
// リンクサーバースレッド void LinkServerSessionThread(THREAD *t, void *param) { LINK *k = (LINK *)param; CONNECTION *c; SESSION *s; POLICY *policy; wchar_t name[MAX_SIZE]; // 引数チェック if (t == NULL || param == NULL) { return; } // サーバーコネクションの作成 c = NewServerConnection(k->Cedar, NULL, t); c->Protocol = CONNECTION_HUB_LINK_SERVER; // ポリシーの作成 policy = ZeroMalloc(sizeof(POLICY)); Copy(policy, k->Policy, sizeof(POLICY)); // サーバーセッションの作成 s = NewServerSession(k->Cedar, c, k->Hub, LINK_USER_NAME, policy); s->LinkModeServer = true; s->Link = k; c->Session = s; ReleaseConnection(c); // ユーザー名 s->Username = CopyStr(LINK_USER_NAME_PRINT); k->ServerSession = s; AddRef(k->ServerSession->ref); // 初期化完了を通知 NoticeThreadInit(t); UniStrCpy(name, sizeof(name), k->Option->AccountName); HLog(s->Hub, "LH_LINK_START", name, s->Name); // セッションのメイン関数 SessionMain(s); HLog(s->Hub, "LH_LINK_STOP", name); ReleaseSession(s); }
// Link server thread void LinkServerSessionThread(THREAD *t, void *param) { LINK *k = (LINK *)param; CONNECTION *c; SESSION *s; POLICY *policy; wchar_t name[MAX_SIZE]; // Validate arguments if (t == NULL || param == NULL) { return; } // Create a server connection c = NewServerConnection(k->Cedar, NULL, t); c->Protocol = CONNECTION_HUB_LINK_SERVER; // Create a policy policy = ZeroMalloc(sizeof(POLICY)); Copy(policy, k->Policy, sizeof(POLICY)); // Create a server session s = NewServerSession(k->Cedar, c, k->Hub, LINK_USER_NAME, policy); s->LinkModeServer = true; s->Link = k; c->Session = s; ReleaseConnection(c); // User name s->Username = CopyStr(LINK_USER_NAME_PRINT); k->ServerSession = s; AddRef(k->ServerSession->ref); // Notify the initialization completion NoticeThreadInit(t); UniStrCpy(name, sizeof(name), k->Option->AccountName); HLog(s->Hub, "LH_LINK_START", name, s->Name); // Main function of session SessionMain(s); HLog(s->Hub, "LH_LINK_STOP", name); ReleaseSession(s); }
// Unicode 文字列型の VALUE の作成 VALUE *NewUniStrValue(wchar_t *str) { VALUE *v; // 引数チェック if (str == NULL) { return NULL; } // メモリ確保 v = Malloc(sizeof(VALUE)); // 文字列コピー v->Size = UniStrSize(str); v->UniStr = Malloc(v->Size); UniStrCpy(v->UniStr, v->Size, str); UniTrim(v->UniStr); return v; }
// Get the current installation state for the given architecture void ViLoadCurrentInstalledStatusForArch(VI_SETTING_ARCH *a) { char tmp[MAX_SIZE]; UINT build; wchar_t *dir; // Validate arguments if (a == NULL) { return; } if (a->Supported == false) { // Unsupported return; } // Read from the registry Format(tmp, sizeof(tmp), "%s\\%s", SW_REG_KEY, "vpnclient"); build = MsRegReadIntEx2(REG_LOCAL_MACHINE, tmp, "InstalledBuild", false, true); dir = MsRegReadStrEx2W(REG_LOCAL_MACHINE, tmp, "InstalledDir", false, true); if (build == 0 || UniIsEmptyStr(dir)) { // Not installed a->CurrentInstalled = false; } else { // Installed a->CurrentInstalled = true; a->CurrentInstalledBuild = build; UniStrCpy(a->CurrentInstalledPathW, sizeof(a->CurrentInstalledPathW), dir); } Free(dir); }
// Get the value of the unicode_string type bool CfgGetUniStr(FOLDER *f, char *name, wchar_t *str, UINT size) { ITEM *t; // Validate arguments if (f == NULL || name == NULL || str == NULL) { return false; } str[0] = 0; t = CfgFindItem(f, name); if (t == NULL) { return false; } if (t->Type != ITEM_TYPE_STRING) { return false; } UniStrCpy(str, size, t->Buf); return true; }
// Get description string for range of the policy value void GetPolicyValueRangeStr(wchar_t *str, UINT size, UINT id) { POLICY_ITEM *p; // Validate arguments if (str == NULL) { return; } p = GetPolicyItem(id); if (p->TypeInt == false) { // bool type UniStrCpy(str, size, _UU("CMD_PolicyList_Range_Bool")); } else { wchar_t *tag; wchar_t tmp1[256], tmp2[256]; // int type if (p->AllowZero) { tag = _UU("CMD_PolicyList_Range_Int_2"); } else { tag = _UU("CMD_PolicyList_Range_Int_1"); } UniFormat(tmp1, sizeof(tmp1), _UU(p->FormatStr), p->MinValue); UniFormat(tmp2, sizeof(tmp2), _UU(p->FormatStr), p->MaxValue); UniFormat(str, size, tag, tmp1, tmp2); } }
// Download thread void ViDownloadThread(THREAD *thread, void *param) { VI_INSTALL_DLG *d; VI_SETTING_ARCH *a; HWND hWnd; UINT num_files = 2; VI_DOWNLOAD_FILE files[2]; VI_DOWNLOAD_FILE *f; UINT i; // Validate arguments if (thread == NULL || param == NULL) { return; } d = (VI_INSTALL_DLG *)param; hWnd = d->hWnd; Zero(files, sizeof(files)); a = ViGetSuitableArchForCpu(); // File body f = &files[0]; StrCpy(f->SrcPath, sizeof(f->SrcPath), a->Path); // Configuration file if (IsEmptyStr(setting.SettingPath) == false) { f = &files[1]; StrCpy(f->SrcPath, sizeof(f->SrcPath), setting.SettingPath); } else { // No configuration file num_files = 1; } for (i = 0;i < num_files;i++) { bool b = true; if (i == 0 && setting.DownloadNotRequired) { b = false; } if (b) { wchar_t tmp[MAX_SIZE]; IO *dest = NULL; VI_FILE *down; UINT ret; UINT totalsize; UINT currentsize; wchar_t filename_w[MAX_PATH]; f = &files[i]; GetFileNameFromFilePath(f->FileName, sizeof(f->FileName), f->SrcPath); MakeSafeFileName(f->FileName, sizeof(f->FileName), f->FileName); StrToUni(filename_w, sizeof(filename_w), f->FileName); ConbinePathW(f->DestPathW, sizeof(f->DestPathW), MsGetMyTempDirW(), filename_w); ViInstallDlgSetPos(hWnd, 0); UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADSTART+skip), f->FileName); ViInstallDlgSetText(d, hWnd, S_STATUS, tmp); down = ViOpenFile(f->SrcPath); if (down == NULL) { MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_DOWNLOAD_ERROR+skip), f->FileName); ViInstallDlgCancel(hWnd); return; } dest = FileCreateW(f->DestPathW); if (dest == NULL) { MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_TEMP_ERROR+skip), f->DestPathW); ViCloseFile(down); ViInstallDlgCancel(hWnd); return; } totalsize = ViGetFileSize(down); currentsize = 0; UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING3+skip), f->FileName); ViInstallDlgSetText(d, hWnd, S_STATUS, tmp); while (true) { UINT pos = 0; if (d->Halt) { // User cancel FileClose(dest); ViCloseFile(down); return; } UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING3+skip), f->FileName); ViInstallDlgSetText(d, hWnd, IDS_DOWNLOADING3+skip, tmp); ret = ViReadFile(down, d->Buf, d->BufSize); if (ret == INFINITE) { // Communication error MsgBoxEx(hWnd, MB_ICONSTOP, _U(IDS_DOWNLOAD_ERROR+skip), f->FileName); FileClose(dest); ViCloseFile(down); ViInstallDlgCancel(hWnd); return; } // Draw progress currentsize += ret; if (totalsize != 0) { UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING+skip), ((float)totalsize) / 1024.0f / 1024.0f, ((float)currentsize) / 1024.0f / 1024.0f); pos = (UINT)(((float)currentsize) * 100.0f / ((float)totalsize)); } else { UniFormat(tmp, sizeof(tmp), _U(IDS_DOWNLOADING2+skip), ((float)currentsize) / 1024.0f / 1024.0f); pos = (UINT)(((float)currentsize) * 100.0f / (1024.0f * 1024.0f * 10.0f)); } ViInstallDlgSetText(d, hWnd, S_SIZEINFO, tmp); ViInstallDlgSetPos(hWnd, pos); if (ret == 0) { // Download Complete break; } else { FileWrite(dest, d->Buf, ret); } } ViCloseFile(down); FileClose(dest); } } UniStrCpy(setting.DownloadedInstallerPathW, sizeof(setting.DownloadedInstallerPathW), files[0].DestPathW); if (num_files >= 2) { UniStrCpy(setting.DownloadedSettingPathW, sizeof(setting.DownloadedSettingPathW), files[1].DestPathW); } PostMessageA(hWnd, WM_VI_DOWNLOAD_FINISHED, 0, 0); }
// Read the string table bool LoadTableMain(wchar_t *filename) { BUF *b; UINT64 t1, t2; UCHAR hash[MD5_SIZE]; // Validate arguments if (filename == NULL) { return false; } if (MayaquaIsMinimalMode()) { return true; } if (UniStrCmpi(old_table_name, filename) == 0) { // Already loaded return true; } t1 = Tick64(); // Open the file b = ReadDumpW(filename); if (b == NULL) { char tmp[MAX_SIZE]; StrCpy(tmp, sizeof(tmp), "Error: Can't read string tables (file not found).\r\nPlease check hamcore.se2.\r\n\r\n(First, reboot the computer. If this problem occurs again, please reinstall VPN software files.)"); Alert(tmp, NULL); exit(-1); return false; } Hash(hash, b->Buf, b->Size, false); if (LoadUnicodeCache(filename, b->Size, hash) == false) { if (LoadTableFromBuf(b) == false) { FreeBuf(b); return false; } SaveUnicodeCache(filename, b->Size, hash); //Debug("Unicode Source: strtable.stb\n"); } else { //Debug("Unicode Source: unicode_cache\n"); } FreeBuf(b); SetLocale(_UU("DEFAULE_LOCALE")); UniStrCpy(old_table_name, sizeof(old_table_name), filename); t2 = Tick64(); if (StrCmpi(_SS("STRTABLE_ID"), STRTABLE_ID) != 0) { char tmp[MAX_SIZE]; Format(tmp, sizeof(tmp), "Error: Can't read string tables (invalid version: '%s'!='%s').\r\nPlease check hamcore.se2.\r\n\r\n(First, reboot the computer. If this problem occurs again, please reinstall VPN software files.)", _SS("STRTABLE_ID"), STRTABLE_ID); Alert(tmp, NULL); exit(-1); return false; } //Debug("Unicode File Read Cost: %u (%u Lines)\n", (UINT)(t2 - t1), LIST_NUM(TableList)); return true; }
LIST *GetEthAdapterListInternal() { LIST *o; LIST *ret; UINT size; char *buf; UINT i, j; char *qos_tag = " (Microsoft's Packet Scheduler)"; SU *su = NULL; LIST *su_adapter_list = NULL; // Try to use SeLow if (enable_selow) { su = SuInit(); } o = NewListFast(CompareWpAdapter); size = 200000; buf = ZeroMalloc(size); // Try to enumerate with SeLow if (su != NULL) { su_adapter_list = SuGetAdapterList(su); if (su_adapter_list == NULL) { // Fail to enumerate SuFree(su); su = NULL; //WHERE; is_using_selow = false; } else { //WHERE; is_using_selow = true; } } else { is_using_selow = false; } if (su_adapter_list != NULL) { // If 1 or more adapters are enumerated by SeLow, create adapter list object UINT i; for (i = 0;i < LIST_NUM(su_adapter_list);i++) { SU_ADAPTER_LIST *t = LIST_DATA(su_adapter_list, i); WP_ADAPTER *a = ZeroMalloc(sizeof(WP_ADAPTER)); StrCpy(a->Name, sizeof(a->Name), t->Name); StrCpy(a->Guid, sizeof(a->Guid), t->Guid); StrCpy(a->Title, sizeof(a->Title), t->Info.FriendlyName); TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); if (EndWith(a->Title, qos_tag)) { a->Title[StrLen(a->Title) - StrLen(qos_tag)] = 0; TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); } Add(o, a); } } else { // When SeLow is not used, create adapter list with SEE or WinPcap if (wp->PacketGetAdapterNames(buf, &size) == false) { Free(buf); return o; } i = 0; if (OS_IS_WINDOWS_NT(GetOsInfo()->OsType)) { // Windows NT if (size >= 2 && buf[0] != 0 && buf[1] != 0) { goto ANSI_STR; } while (true) { wchar_t tmp[MAX_SIZE]; WP_ADAPTER *a; UniStrCpy(tmp, sizeof(tmp), L""); if (*((wchar_t *)(&buf[i])) == 0) { i += sizeof(wchar_t); break; } for (;*((wchar_t *)(&buf[i])) != 0;i += sizeof(wchar_t)) { wchar_t str[2]; str[0] = *((wchar_t *)(&buf[i])); str[1] = 0; UniStrCat(tmp, sizeof(tmp), str); } i += sizeof(wchar_t); a = ZeroMalloc(sizeof(WP_ADAPTER)); UniToStr(a->Name, sizeof(a->Name), tmp); Add(o, a); } } else { // Windows 9x ANSI_STR: while (true) { char tmp[MAX_SIZE]; WP_ADAPTER *a; StrCpy(tmp, sizeof(tmp), ""); if (*((char *)(&buf[i])) == 0) { i += sizeof(char); break; } for (;*((char *)(&buf[i])) != 0;i += sizeof(char)) { char str[2]; str[0] = *((char *)(&buf[i])); str[1] = 0; StrCat(tmp, sizeof(tmp), str); } i += sizeof(char); a = ZeroMalloc(sizeof(WP_ADAPTER)); StrCpy(a->Name, sizeof(a->Name), tmp); Add(o, a); } } for (j = 0;j < LIST_NUM(o);j++) { WP_ADAPTER *a = LIST_DATA(o, j); StrCpy(a->Title, sizeof(a->Title), &buf[i]); i += StrSize(a->Title); // If device description is "Unknown" in Win9x, skip 1 byte if (OS_IS_WINDOWS_9X(GetOsInfo()->OsType)) { if (StrCmp(a->Title, "Unknown") == 0) { if (buf[i] == 0) { i+=sizeof(char); } } } TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); if (EndWith(a->Title, qos_tag)) { a->Title[StrLen(a->Title) - StrLen(qos_tag)] = 0; TrimCrlf(a->Title); Trim(a->Title); TrimCrlf(a->Title); Trim(a->Title); } } } for (j = 0;j < LIST_NUM(o);j++) { // Extract GUID WP_ADAPTER *a = LIST_DATA(o, j); if (IsEmptyStr(a->Guid)) { StrCpy(a->Guid, sizeof(a->Guid), a->Name); ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\SEE_", ""); ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\NPF_", ""); ReplaceStr(a->Guid, sizeof(a->Guid), a->Guid, "\\Device\\PCD_", ""); } } // Sort if (su_adapter_list != NULL) { // Since adapter list made by SeLow is already sorted, don't sort here Sort(o); } ret = NewListFast(CompareWpAdapter); for (i = 0;i < LIST_NUM(o);i++) { WP_ADAPTER *a = LIST_DATA(o, i); ADAPTER *ad; bool is_ethernet = false; bool ok = false; if (SearchStrEx(a->Title, "ppp", 0, false) != INFINITE || SearchStrEx(a->Title, "wan", 0, false) != INFINITE || SearchStrEx(a->Title, "dialup", 0, false) != INFINITE || SearchStrEx(a->Title, "pptp", 0, false) != INFINITE || SearchStrEx(a->Title, "telepho", 0, false) != INFINITE || SearchStrEx(a->Title, "modem", 0, false) != INFINITE || SearchStrEx(a->Title, "ras", 0, false) != INFINITE) { Free(a); continue; } // Determine whether the adapter type is Ethernet if (su == NULL) { // Determine with See ad = wp->PacketOpenAdapter(a->Name); if (ad != NULL) { NetType type; if (wp->PacketGetNetType(ad, &type)) { if (type.LinkType == 0) { is_ethernet = true; } } wp->PacketCloseAdapter(ad); } } else { // In using SeLow, all devices should be Ethernet device is_ethernet = true; } if (is_ethernet) { // Add only Ethernet device char tmp[MAX_SIZE]; UINT k; StrCpy(tmp, sizeof(tmp), a->Title); for (k = 0;;k++) { if (k == 0) { StrCpy(tmp, sizeof(tmp), a->Title); } else { Format(tmp, sizeof(tmp), "%s (%u)", a->Title, k + 1); } ok = true; for (j = 0;j < LIST_NUM(ret);j++) { WP_ADAPTER *aa = LIST_DATA(ret, j); if (StrCmpi(aa->Title, tmp) == 0) { ok = false; } } if (ok) { break; } } StrCpy(a->Title, sizeof(a->Title), tmp); a->Id = Win32EthGenIdFromGuid(a->Guid); Add(ret, a); } if (ok == false) { Free(a); } } Free(buf); Sort(ret); ReleaseList(o); if (su != NULL) { SuFreeAdapterList(su_adapter_list); SuFree(su); } return ret; }
// Interpret a line TABLE *ParseTableLine(char *line, char *prefix, UINT prefix_size, LIST *replace_list) { UINT i, len; UINT len_name; UINT string_start; char *name; char *name2; UINT name2_size; wchar_t *unistr; char *str; UINT unistr_size, str_size; TABLE *t; // Validate arguments if (line == NULL || prefix == NULL) { return NULL; } TrimLeft(line); // No line len = StrLen(line); if (len == 0) { return NULL; } // Comment if (line[0] == '#' || (line[0] == '/' && line[1] == '/')) { return NULL; } // Search to the end position of the name len_name = 0; for (i = 0;;i++) { if (line[i] == 0) { // There is only one token return NULL; } if (line[i] == ' ' || line[i] == '\t') { break; } len_name++; } name = Malloc(len_name + 1); StrCpy(name, len_name + 1, line); string_start = len_name; for (i = len_name;i < len;i++) { if (line[i] != ' ' && line[i] != '\t') { break; } string_start++; } if (i == len) { Free(name); return NULL; } // Unescape UnescapeStr(&line[string_start]); // Convert to Unicode unistr_size = CalcUtf8ToUni(&line[string_start], StrLen(&line[string_start])); if (unistr_size == 0) { Free(name); return NULL; } unistr = Malloc(unistr_size); Utf8ToUni(unistr, unistr_size, &line[string_start], StrLen(&line[string_start])); if (UniInChar(unistr, L'$')) { // Replace the replacement string wchar_t *tmp; UINT tmp_size = (UniStrSize(unistr) + 1024) * 2; UINT i; tmp = Malloc(tmp_size); UniStrCpy(tmp, tmp_size, unistr); for (i = 0; i < LIST_NUM(replace_list);i++) { TABLE *r = LIST_DATA(replace_list, i); UniReplaceStrEx(tmp, tmp_size, tmp, (wchar_t *)r->name, r->unistr, false); } unistr = CopyUniStr(tmp); Free(tmp); } // Convert to ANSI str_size = CalcUniToStr(unistr); if (str_size == 0) { str_size = 1; str = Malloc(1); str[0] = 0; } else { str = Malloc(str_size); UniToStr(str, str_size, unistr); } if (StrCmpi(name, "PREFIX") == 0) { // Prefix is specified StrCpy(prefix, prefix_size, str); Trim(prefix); if (StrCmpi(prefix, "$") == 0 || StrCmpi(prefix, "NULL") == 0) { prefix[0] = 0; } Free(name); Free(str); Free(unistr); return NULL; } name2_size = StrLen(name) + StrLen(prefix) + 2; name2 = ZeroMalloc(name2_size); if (prefix[0] != 0) { StrCat(name2, name2_size, prefix); StrCat(name2, name2_size, "@"); } StrCat(name2, name2_size, name); Free(name); // Create a TABLE t = Malloc(sizeof(TABLE)); StrUpper(name2); t->name = name2; t->str = str; t->unistr = unistr; return t; }
// License dialog update void EmLicenseDlgRefresh(HWND hWnd, RPC *s) { RPC_ENUM_LICENSE_KEY t; RPC_EL_LICENSE_STATUS st; UINT i; wchar_t tmp[MAX_SIZE]; LVB *b; // Validate arguments if (hWnd == NULL || s == NULL) { return; } Zero(&t, sizeof(t)); if (CALL(hWnd, EcEnumLicenseKey(s, &t)) == false) { Close(hWnd); return; } b = LvInsertStart(); for (i = 0;i < t.NumItem;i++) { wchar_t tmp1[32], tmp2[LICENSE_KEYSTR_LEN + 1], tmp3[LICENSE_MAX_PRODUCT_NAME_LEN + 1], *tmp4, tmp5[128], tmp6[LICENSE_LICENSEID_STR_LEN + 1], tmp7[64], tmp8[64], tmp9[64]; RPC_ENUM_LICENSE_KEY_ITEM *e = &t.Items[i]; UniToStru(tmp1, e->Id); StrToUni(tmp2, sizeof(tmp2), e->LicenseKey); StrToUni(tmp3, sizeof(tmp3), e->LicenseName); tmp4 = LiGetLicenseStatusStr(e->Status); if (e->Expires == 0) { UniStrCpy(tmp5, sizeof(tmp5), _UU("SM_LICENSE_NO_EXPIRES")); } else { GetDateStrEx64(tmp5, sizeof(tmp5), e->Expires, NULL); } StrToUni(tmp6, sizeof(tmp6), e->LicenseId); UniToStru(tmp7, e->ProductId); UniFormat(tmp8, sizeof(tmp8), L"%I64u", e->SystemId); UniToStru(tmp9, e->SerialId); LvInsertAdd(b, e->Status == LICENSE_STATUS_OK ? ICO_PASS : ICO_DISCARD, (void *)e->Id, 9, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7, tmp8, tmp9); } LvInsertEnd(b, hWnd, L_LIST); FreeRpcEnumLicenseKey(&t); Zero(&st, sizeof(st)); if (CALL(hWnd, EcGetLicenseStatus(s, &st)) == false) { Close(hWnd); return; } b = LvInsertStart(); if (st.Valid == false) { LvInsertAdd(b, 0, NULL, 2, _UU("EM_NO_LICENSE_COLUMN"), _UU("EM_NO_LICENSE")); } else { // Current system ID UniFormat(tmp, sizeof(tmp), L"%I64u", st.SystemId); LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_SYSTEM_ID"), tmp); // Expiration date of the current license product if (st.SystemExpires == 0) { UniStrCpy(tmp, sizeof(tmp), _UU("SM_LICENSE_NO_EXPIRES")); } else { GetDateStrEx64(tmp, sizeof(tmp), st.SystemExpires, NULL); } LvInsertAdd(b, 0, NULL, 2, _UU("SM_LICENSE_STATUS_EXPIRES"), tmp); } LvInsertEnd(b, hWnd, L_STATUS); if (LvNum(hWnd, L_STATUS) >= 1) { LvAutoSize(hWnd, L_STATUS); } EmLicenseDlgUpdate(hWnd, s); }
// Update status void UtSpeedMeterDlgRefreshStatus(HWND hWnd) { char *title; MS_ADAPTER *a; UINT i; // Validate arguments if (hWnd == NULL) { return; } title = selected_adapter; a = MsGetAdapter(title); if (a == NULL) { LbReset(hWnd, L_STATUS); Disable(hWnd, L_STATUS); } else { LVB *b; wchar_t tmp[MAX_SIZE]; wchar_t tmp2[MAX_SIZE]; char str[MAX_SIZE]; b = LvInsertStart(); UniStrCpy(tmp, sizeof(tmp), a->TitleW); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TITLE"), tmp); StrToUni(tmp, sizeof(tmp), a->Guid); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_GUID"), tmp); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TYPE"), MsGetAdapterTypeStr(a->Type)); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_TYPE2"), (!a->IsNotEthernetLan ? _UU("SEC_YES") : _UU("SEC_NO"))); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_STATUS"), MsGetAdapterStatusStr(a->Status)); UniToStr3(tmp, sizeof(tmp), a->Mtu); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_MTU"), tmp); UniToStr3(tmp, sizeof(tmp), a->Speed); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SPEED"), tmp); Zero(str, sizeof(str)); BinToStrEx2(str, sizeof(str), a->Address, a->AddressSize, '-'); StrToUni(tmp, sizeof(tmp), str); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_ADDRESS"), tmp); UniToStr3(tmp, sizeof(tmp), a->RecvBytes); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_BYTES"), tmp); UniToStr3(tmp, sizeof(tmp), a->RecvPacketsBroadcast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_BCASTS"), tmp); UniToStr3(tmp, sizeof(tmp), a->RecvPacketsUnicast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_RECV_UNICASTS"), tmp); UniToStr3(tmp, sizeof(tmp), a->SendBytes); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_BYTES"), tmp); UniToStr3(tmp, sizeof(tmp), a->SendPacketsBroadcast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_BCASTS"), tmp); UniToStr3(tmp, sizeof(tmp), a->SendPacketsUnicast); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_SEND_UNICASTS"), tmp); for (i = 0;i < a->NumIpAddress;i++) { UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_IP"), i + 1); IPToUniStr(tmp, sizeof(tmp), &a->IpAddresses[i]); LvInsertAdd(b, 0, NULL, 2, tmp2, tmp); UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_SUBNET"), i + 1); IPToUniStr(tmp, sizeof(tmp), &a->SubnetMasks[i]); LvInsertAdd(b, 0, NULL, 2, tmp2, tmp); } for (i = 0;i < a->NumGateway;i++) { UniFormat(tmp2, sizeof(tmp2), _UU("UT_SM_ST_GATEWAY"), i + 1); IPToUniStr(tmp, sizeof(tmp), &a->Gateways[i]); LvInsertAdd(b, 0, NULL, 2, tmp2, tmp); } if (a->UseDhcp) { IPToUniStr(tmp, sizeof(tmp), &a->DhcpServer); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP"), tmp); GetDateTimeStrEx64(tmp, sizeof(tmp), a->DhcpLeaseStart, NULL); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP_1"), tmp); GetDateTimeStrEx64(tmp, sizeof(tmp), a->DhcpLeaseExpires, NULL); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_DHCP_2"), tmp); } if (a->UseWins) { IPToUniStr(tmp, sizeof(tmp), &a->PrimaryWinsServer); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_WINS_1"), tmp); IPToUniStr(tmp, sizeof(tmp), &a->SecondaryWinsServer); LvInsertAdd(b, 0, NULL, 2, _UU("UT_SM_ST_WINS_2"), tmp); } LvInsertEnd(b, hWnd, L_STATUS); Enable(hWnd, L_STATUS); MsFreeAdapter(a); } }