// Bridging thread void BrBridgeThread(THREAD *thread, void *param) { BRIDGE *b; CONNECTION *c; SESSION *s; HUB *h; char name[MAX_SIZE]; // Validate arguments if (thread == NULL || param == NULL) { return; } b = (BRIDGE *)param; // Create a connection object c = NewServerConnection(b->Cedar, NULL, thread); c->Protocol = CONNECTION_HUB_BRIDGE; // Create a session object s = NewServerSession(b->Cedar, c, b->Hub, BRIDGE_USER_NAME, b->Policy); HLog(b->Hub, "LH_START_BRIDGE", b->Name, s->Name); StrCpy(name, sizeof(name), b->Name); h = b->Hub; AddRef(h->ref); s->BridgeMode = true; s->Bridge = b; c->Session = s; ReleaseConnection(c); // Dummy user name for local-bridge s->Username = CopyStr(BRIDGE_USER_NAME_PRINT); b->Session = s; AddRef(s->ref); // Notify completion NoticeThreadInit(thread); // Main procedure of the session Debug("Bridge %s Start.\n", b->Name); SessionMain(s); Debug("Bridge %s Stop.\n", b->Name); HLog(h, "LH_STOP_BRIDGE", name); ReleaseHub(h); ReleaseSession(s); }
SOCK *WpcSockConnect2(char *hostname, UINT port, INTERNET_SETTING *t, UINT *error_code, UINT timeout) { // Validate arguments INTERNET_SETTING t2; WPC_CONNECT c; if (t == NULL) { Zero(&t2, sizeof(t2)); t = &t2; } Zero(&c, sizeof(c)); StrCpy(c.HostName, sizeof(c.HostName), hostname); c.Port = port; c.ProxyType = t->ProxyType; StrCpy(c.ProxyHostName, sizeof(c.HostName), t->ProxyHostName); c.ProxyPort = t->ProxyPort; StrCpy(c.ProxyUsername, sizeof(c.ProxyUsername), t->ProxyUsername); StrCpy(c.ProxyPassword, sizeof(c.ProxyPassword), t->ProxyPassword); return WpcSockConnect(&c, error_code, timeout); }
BOOL AppUpgradeUtil::ObsoleteFile( LPCTSTR target, LPCTSTR log_file ) { TCHAR file_name[MAX_PATH + 1]; StrCpy(file_name, target); ::PathRemoveFileSpec(file_name); GetTempFileName(file_name, TEXT("~tmp"), 0, file_name); ::DeleteFile(file_name); BOOL bRet = ::MoveFile(target, file_name); if(bRet) { WriteLog4ObsoleteFile(target, file_name, log_file); } return bRet; }
// Show the status of the router bool NmStatus(HWND hWnd, SM_SERVER *s, void *param) { LVB *b; RPC_NAT_STATUS t; wchar_t tmp[MAX_SIZE]; SM_HUB *h = (SM_HUB *)param; // Validate arguments if (hWnd == NULL || s == NULL) { return false; } Zero(&t, sizeof(t)); StrCpy(t.HubName, sizeof(t.HubName), h->HubName); if (CALL(hWnd, ScGetSecureNATStatus(s->Rpc, &t)) == false) { return false; } b = LvInsertStart(); StrToUni(tmp, sizeof(tmp), h->HubName); LvInsertAdd(b, ICO_HUB, NULL, 2, _UU("SM_HUB_COLUMN_1"), tmp); UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumTcpSessions); LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("NM_STATUS_TCP"), tmp); UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumUdpSessions); LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("NM_STATUS_UDP"), tmp); UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumIcmpSessions); LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("NM_STATUS_ICMP"), tmp); UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_SESSION"), t.NumDnsSessions); LvInsertAdd(b, ICO_PROTOCOL, NULL, 2, _UU("NM_STATUS_DNS"), tmp); UniFormat(tmp, sizeof(tmp), _UU("SM_SNAT_NUM_CLIENT"), t.NumDhcpClients); LvInsertAdd(b, ICO_PROTOCOL_DHCP, NULL, 2, _UU("NM_STATUS_DHCP"), tmp); LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_SNAT_IS_KERNEL"), t.IsKernelMode ? _UU("SEC_YES") : _UU("SEC_NO")); LvInsertAdd(b, ICO_MACHINE, NULL, 2, _UU("SM_SNAT_IS_RAW"), t.IsRawIpMode ? _UU("SEC_YES") : _UU("SEC_NO")); LvInsertEnd(b, hWnd, L_STATUS); FreeRpcNatStatus(&t); return true; }
/** Check whether a reset is needed, and finish the reset reminder feature. If a reset is needed, Popup a menu to notice user, and finish the feature according to the user selection. **/ VOID EFIAPI SetupResetReminder ( VOID ) { EFI_INPUT_KEY Key; CHAR16 *StringBuffer1; CHAR16 *StringBuffer2; // //check any reset required change is applied? if yes, reset system // if (IsResetReminderFeatureEnable ()) { if (IsResetRequired ()) { StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); ASSERT (StringBuffer1 != NULL); StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16)); ASSERT (StringBuffer2 != NULL); StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now."); StrCpy (StringBuffer2, L"Press ENTER to reset"); // // Popup a menu to notice user // do { CreatePopUp (EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, &Key, StringBuffer1, StringBuffer2, NULL); } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); FreePool (StringBuffer1); FreePool (StringBuffer2); gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL); } } }
// --------------------------------------------------------------------------- // CreateFilePathHierarchy // --------------------------------------------------------------------------- HRESULT CreateFilePathHierarchy( LPCOLESTR pszName ) { HRESULT hr=S_OK; LPTSTR pszFileName; TCHAR szPath[MAX_PATH]; // Assert (pszPath ) ; StrCpy (szPath, pszName); pszFileName = PathFindFileName ( szPath ); if ( pszFileName <= szPath ) return E_INVALIDARG; // Send some error *(pszFileName-1) = 0; DWORD dw = GetFileAttributes( szPath ); if ( dw != (DWORD) -1 ) return S_OK; hr = FusionpHresultFromLastError(); switch (hr) { case HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND): { hr = CreateFilePathHierarchy(szPath); if (hr != S_OK) return hr; } case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): { if ( CreateDirectory( szPath, NULL ) ) return S_OK; else { hr = FusionpHresultFromLastError(); if(hr == HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)) hr = S_OK; else return hr; } } default: return hr; } }
void TrafficInformation::InitFile(__int64 sz,LPCSTR SrcName,LPCSTR DestName) { if(FullFileSize != -1) { TotalComplete++; TotalFiles = Max(TotalFiles, TotalSkipped+TotalComplete); TotalSize += FullFileSize; TotalFullSize = Max(TotalSize, TotalFullSize); } if(sz == -1) sz = 0; FullFileSize = sz; FileSize = 0; LastSize = 0; StartFileSize = 0; Cps = 0; FileStartTime = time(NULL); FileWaitTime = 0; AvCps[0] = 0; AvCps[1] = 0; AvCps[2] = 0; GET_TIME(LastTime); StrCpy(SrcFileName, SrcName, ARRAYSIZE(SrcFileName)); StrCpy(DestFileName, DestName, ARRAYSIZE(DestFileName)); }
// 文字列をコピーする char *CopyStr(char *str) { UINT len; char *dst; // 引数チェック if (str == NULL) { return NULL; } len = StrLen(str); dst = Malloc(len + 1); StrCpy(dst, len + 1, str); return dst; }
Boolean TrimMiddle(char* string) { int length = StrLen(string); char *stringCopy = new char[length +1]; if(!stringCopy) return FALSE; int j = 0; for(int i = 0; i < length; i++) if(string[i] != ' ') stringCopy[j++] = string[i]; stringCopy[j] = '\0'; StrCpy(string, stringCopy); delete stringCopy; return TRUE; }
// Get version of Windows void GetWinVer(RPC_WINVER *v) { // Validate arguments if (v == NULL) { return; } #ifdef OS_WIN32 Win32GetWinVer(v); #else // OS_WIN32 Zero(v, sizeof(RPC_WINVER)); StrCpy(v->Title, sizeof(v->Title), GetOsInfo()->OsProductName); #endif // OS_WIN32 }
// Copy a string char *CopyStr(char *str) { UINT len; char *dst; // Validate arguments if (str == NULL) { return NULL; } len = StrLen(str); dst = Malloc(len + 1); StrCpy(dst, len + 1, str); return dst; }
EFI_STATUS EFIAPI RemoveFileLock( IN EFI_FILE_HANDLE CurDir, IN CHAR16 * FileNameUser ) { EFI_STATUS Status = EFI_SUCCESS; EFI_FILE_HANDLE FileHandle; CHAR16* FileNameElite; FileNameElite = AllocateZeroPool(260*sizeof(CHAR16)); StrCpy(FileNameElite,FileNameUser); StrCat(FileNameElite,FILE_NAME_ELITE); StrCat(FileNameElite,g_NAME_ELITE); Status = CurDir->Open (CurDir, &FileHandle, FileNameElite, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); FreePool(FileNameElite); if (EFI_ERROR(Status)) { #ifdef FORCE_DEBUG Print(L"Error Open File RemoveFileLock\n"); #endif return Status; } else { #ifdef FORCE_DEBUG Print(L"RemoveFileLock OK\n"); #endif } Status=FileHandle->Delete(FileHandle); if( Status != EFI_SUCCESS ) { #ifdef FORCE_DEBUG Print(L"Write RemoveFileLock File Failed\n"); #endif return Status; } return EFI_SUCCESS; }
EFI_STATUS generate_path(CHAR16* name, EFI_LOADED_IMAGE *li, EFI_DEVICE_PATH **path, CHAR16 **PathName) { unsigned int pathlen; EFI_STATUS efi_status = EFI_SUCCESS; CHAR16 *devpathstr = DevicePathToStr(li->FilePath), *found = NULL; unsigned int i; for (i = 0; i < StrLen(devpathstr); i++) { if (devpathstr[i] == '/') devpathstr[i] = '\\'; if (devpathstr[i] == '\\') found = &devpathstr[i]; } if (!found) { pathlen = 0; } else { while (*(found - 1) == '\\') --found; *found = '\0'; pathlen = StrLen(devpathstr); } if (name[0] != '\\') pathlen++; *PathName = AllocatePool((pathlen + 1 + StrLen(name))*sizeof(CHAR16)); if (!*PathName) { Print(L"Failed to allocate path buffer\n"); efi_status = EFI_OUT_OF_RESOURCES; goto error; } StrCpy(*PathName, devpathstr); if (name[0] != '\\') StrCat(*PathName, L"\\"); StrCat(*PathName, name); *path = FileDevicePath(li->DeviceHandle, *PathName); error: FreePool(devpathstr); return efi_status; }
// Search a folder FOLDER *CfgFindFolder(FOLDER *parent, char *name) { FOLDER *f, ff; // Validate arguments if (parent == NULL || name == NULL) { return NULL; } ff.Name = ZeroMalloc(StrLen(name) + 1); StrCpy(ff.Name, 0, name); f = Search(parent->Folders, &ff); Free(ff.Name); return f; }
// Search for an item ITEM *CfgFindItem(FOLDER *parent, char *name) { ITEM *t, tt; // Validate arguments if (parent == NULL || name == NULL) { return NULL; } tt.Name = ZeroMalloc(StrLen(name) + 1); StrCpy(tt.Name, 0, name); t = Search(parent->Items, &tt); Free(tt.Name); return t; }
//--------------------------------------------------------------------------------- void FTPHost::Init(void) { Log(("FTPHost::Init %p",this)); memset(this,0,sizeof(*this)); Size = sizeof(*this); ExtCmdView = Opt.ExtCmdView; IOBuffSize = Opt.IOBuffSize; PassiveMode = Opt.PassiveMode; ProcessCmd = Opt.ProcessCmd; UseFirewall = Opt.Firewall[0] != 0; FFDup = Opt.FFDup; UndupFF = Opt.UndupFF; DecodeCmdLine= TRUE; ServerType = FTP_TYPE_DETECT; StrCpy(ListCMD, "LIST -la", ARRAYSIZE(ListCMD)); }
void CModuleHashNode::Init ( LPTSTR szPath, ALG_ID aAlgId, DWORD cbHash, BYTE *pHash) { if(lstrlen(szPath) <= MAX_PATH) StrCpy(_szPath, szPath); _aAlgId = aAlgId; if(_aAlgId && (cbHash <= MAX_HASH_LEN ) ) { memcpy(_bHash, pHash, cbHash); _cbHash = cbHash; _bHashGen = TRUE; } else { _bHashGen = FALSE; } }
// Get the interface that is connected to the specified Virtual HUB from the L3 switch L3IF *L3SearchIf(L3SW *s, char *hubname) { L3IF t, *f; // Validate arguments if (s == NULL || hubname == NULL) { return NULL; } Zero(&t, sizeof(t)); StrCpy(t.HubName, sizeof(t.HubName), hubname); f = Search(s->IfList, &t); return f; }
// Escape restoration of the string char *CfgUnescape(char *str) { char *tmp; char *ret; char tmp2[16]; UINT len, wp, i; UINT code; // Validate arguments if (str == NULL) { return NULL; } len = StrLen(str); tmp = ZeroMalloc(len + 1); wp = 0; if (len == 1 && str[0] == '$') { // Empty character tmp[0] = 0; } else { for (i = 0;i < len;i++) { if (str[i] != '$') { tmp[wp++] = str[i]; } else { tmp2[0] = '0'; tmp2[1] = 'x'; tmp2[2] = str[i + 1]; tmp2[3] = str[i + 2]; i += 2; tmp2[4] = 0; code = ToInt(tmp2); tmp[wp++] = (char)code; } } } ret = Malloc(StrLen(tmp) + 1); StrCpy(ret, StrLen(tmp) + 1, tmp); Free(tmp); return ret; }
EFIAPI FileDevicePathToText(EFI_DEVICE_PATH_PROTOCOL *FilePathProto) { EFI_STATUS Status; FILEPATH_DEVICE_PATH *FilePath; CHAR16 FilePathText[256]; // possible problem: if filepath is bigger CHAR16 *OutFilePathText; UINTN Size; UINTN SizeAll; UINTN i; FilePathText[0] = L'\0'; i = 4; SizeAll = 0; //DBG("FilePathProto->Type: %d, SubType: %d, Length: %d\n", FilePathProto->Type, FilePathProto->SubType, DevicePathNodeLength(FilePathProto)); while (FilePathProto != NULL && FilePathProto->Type != END_DEVICE_PATH_TYPE && i > 0) { if (FilePathProto->Type == MEDIA_DEVICE_PATH && FilePathProto->SubType == MEDIA_FILEPATH_DP) { FilePath = (FILEPATH_DEVICE_PATH *) FilePathProto; Size = (DevicePathNodeLength(FilePathProto) - 4) / 2; if (SizeAll + Size < 256) { if (SizeAll > 0 && FilePathText[SizeAll / 2 - 2] != L'\\') { StrCat(FilePathText, L"\\"); } StrCat(FilePathText, FilePath->PathName); SizeAll = StrSize(FilePathText); } } FilePathProto = NextDevicePathNode(FilePathProto); //DBG("FilePathProto->Type: %d, SubType: %d, Length: %d\n", FilePathProto->Type, FilePathProto->SubType, DevicePathNodeLength(FilePathProto)); i--; //DBG("FilePathText: %s\n", FilePathText); } OutFilePathText = NULL; Size = StrSize(FilePathText); if (Size > 2) { // we are allocating mem here - should be released by caller Status = gBS->AllocatePool(EfiBootServicesData, Size, (VOID*)&OutFilePathText); if (Status == EFI_SUCCESS) { StrCpy(OutFilePathText, FilePathText); } else { OutFilePathText = NULL; } } return OutFilePathText; }
// Get the string name that begins with the specified name TOKEN_LIST *GetTableNameStartWith(char *str) { UINT i; UINT len; LIST *o; TOKEN_LIST *t; char tmp[MAX_SIZE]; // Validate arguments if (str == NULL) { return NullToken(); } StrCpy(tmp, sizeof(tmp), str); StrUpper(tmp); len = StrLen(tmp); o = NewListFast(NULL); for (i = 0;i < LIST_NUM(TableList);i++) { TABLE *t = LIST_DATA(TableList, i); UINT len2 = StrLen(t->name); if (len2 >= len) { if (Cmp(t->name, tmp, len) == 0) { Insert(o, CopyStr(t->name)); } } } t = ZeroMalloc(sizeof(TOKEN_LIST)); t->NumTokens = LIST_NUM(o); t->Token = ZeroMalloc(sizeof(char *) * t->NumTokens); for (i = 0;i < t->NumTokens;i++) { t->Token[i] = LIST_DATA(o, i); } ReleaseList(o); return t; }
STDAPI GetCachePath(ASM_CACHE_FLAGS dwCacheFlags, LPWSTR pwzCachePath, PDWORD pcchPath) { HRESULT hr = S_OK; LPWSTR pszTemp = NULL; DWORD dwLen=0; if( !pcchPath || !dwCacheFlags || (dwCacheFlags & (dwCacheFlags-1))) return E_INVALIDARG; if(dwCacheFlags & ASM_CACHE_ZAP) { hr = GetZapDir(&pszTemp); } else if(dwCacheFlags & ASM_CACHE_GAC) { hr = GetGACDir(&pszTemp); } else if(dwCacheFlags & ASM_CACHE_DOWNLOAD) { hr = GetDownloadDir(&pszTemp); } else { hr = E_INVALIDARG; } if(FAILED(hr)) goto exit; dwLen = lstrlen(pszTemp); if(pwzCachePath && (*pcchPath > dwLen)) { StrCpy(pwzCachePath, pszTemp); } else { hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } *pcchPath = dwLen+1; exit : return hr; }
// Get registry key of the network class data by GUID bool GetClassRegKeyWin32(char *key, UINT key_size, char *short_key, UINT short_key_size, char *guid) { TOKEN_LIST *t; bool ret = false; UINT i; // Validate arguments if (key == NULL || short_key == NULL || guid == NULL) { return false; } t = MsRegEnumKey(REG_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}"); if (t == NULL) { return false; } for (i = 0;i < t->NumTokens;i++) { char keyname[MAX_SIZE]; char *value; Format(keyname, sizeof(keyname), "SYSTEM\\CurrentControlSet\\Control\\Class\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", t->Token[i]); value = MsRegReadStr(REG_LOCAL_MACHINE, keyname, "NetCfgInstanceId"); if (StrCmpi(value, guid) == 0) { ret = true; StrCpy(key, key_size, keyname); Format(short_key, short_key_size, "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s", t->Token[i]); } Free(value); } FreeToken(t); return ret; }
// Generate a combined name from NIC name and GUID void Win32EthMakeCombinedName(char *dst, UINT dst_size, char *nicname, char *guid) { // Validate arguments if (dst == NULL || nicname == NULL || guid == NULL) { return; } if (IsEmptyStr(guid) == false) { Format(dst, dst_size, "%s (ID=%010u)", nicname, Win32EthGenIdFromGuid(guid)); } else { StrCpy(dst, dst_size, nicname); } }
// [OK] button void NmEditVhOptionOnOk(HWND hWnd, SM_HUB *r) { VH_OPTION t; // Validate arguments if (hWnd == NULL || r == NULL) { return; } NmEditVhOptionFormToVH(hWnd, &t); StrCpy(t.HubName, sizeof(t.HubName), r->HubName); if (CALL(hWnd, ScSetSecureNATOption(r->Rpc, &t))) { EndDialog(hWnd, true); } }
VOID StatusToString ( OUT CHAR16 *Buffer, IN EFI_STATUS Status ) { UINTN Index; for (Index = 0; ErrorCodeTable[Index].Desc; Index +=1) { if (ErrorCodeTable[Index].Code == Status) { StrCpy (Buffer, ErrorCodeTable[Index].Desc); return; } } SPrint (Buffer, 0, L"%X", Status); }
/** Get Intel GOP driver version and copy it into IGD OpRegion GVER. This version is picked up by IGD driver and displayed in CUI. @param Event A pointer to the Event that triggered the callback. @param Context A pointer to private data registered with the callback function. @retval EFI_SUCCESS Video BIOS VBT information returned. @retval EFI_UNSUPPORTED Could not find VBT information (*VBiosVbtPtr = NULL). **/ EFI_STATUS EFIAPI SetGOPVersionCallback ( IN EFI_EVENT Event, IN VOID *Context ) { CHAR16 GopVersion[16] = {0}; EFI_STATUS Status; Status = GetGOPDriverVersion(GopVersion); if(!EFI_ERROR(Status)) { StrCpy((CHAR16*)&(mIgdOpRegion.OpRegion->Header.GOPV[0]), GopVersion); return Status; } return EFI_UNSUPPORTED; }
UINT StrCatLeft(char *dst, UINT size, char *src) { char *s; // Validate arguments if (dst == NULL || src == NULL) { return 0; } s = CopyStr(dst); StrCpy(dst, size, src); StrCat(dst, size, s); Free(s); return StrLen(dst); }
// ダイナミック仮想 HUB でサポートされていない DHCP オプションをクリアする void NiClearUnsupportedVhOptionForDynamicHub(VH_OPTION *o, bool initial) { // 引数チェック if (o == NULL) { return; } o->UseNat = false; if (initial) { Zero(&o->DhcpGatewayAddress, sizeof(IP)); Zero(&o->DhcpDnsServerAddress, sizeof(IP)); StrCpy(o->DhcpDomainName, sizeof(o->DhcpDomainName), ""); } }
static void GetWordTextOutHook (TEverythingParams *TP) { CurParams = TP; ScreenToClient(TP->WND, &(TP->Pt)); if (TP->Pt.y<0) { // point is outside the client area TCHAR buffer[256]; HMENU menu; TCHAR buffer2[256]; /* Reset window title to make some of the hooked function to be invoked */ GetWindowText(TP->WND, buffer, sizeof(buffer)/sizeof(buffer[0])); SetWindowText(TP->WND, TEXT("")); GetWindowText(TP->WND, buffer2, sizeof(buffer2)/sizeof(buffer2[0])); if (buffer2[0]) { // MDI window. TCHAR *p = StrStr(buffer, buffer2); if (p) { if (p == buffer) { // FWS_PREFIXTITLE StrCpy(buffer, buffer+lstrlen(buffer2)); } else { *p = TEXT('\0'); } } } CurParams->Active = TRUE; SetWindowText(TP->WND, buffer); CurParams->Active = FALSE; menu = GetMenu(TP->WND); if (menu) { ClientToScreen(TP->WND, &(TP->Pt)); IterateThroughItems(TP->WND, menu, &(TP->Pt)); } } else { /* redraw a part of the window to make some of the hooked functions to be invoked */ RECT UpdateRect; GetClientRect(TP->WND, &UpdateRect); UpdateRect.top = TP->Pt.y; UpdateRect.bottom = TP->Pt.y + 1; CurParams->Active = TRUE; InvalidateRect(TP->WND, &UpdateRect, FALSE); UpdateWindow(TP->WND); CurParams->Active = FALSE; } CurParams = NULL; }