void CStreamCtrlDlg::EnumIP() { ULONG len = 0; // 列挙に必要なバイト数です。 DWORD ret = GetAdaptersAddresses(AF_UNSPEC, 0, 0, 0, &len); if(ret != ERROR_BUFFER_OVERFLOW) return; // メモリ不足以外のエラーなら制御を返します。 // 要求されたバイト数 len 分のメモリを adpts に用意します。 PIP_ADAPTER_ADDRESSES adpts = (PIP_ADAPTER_ADDRESSES)new BYTE[len]; if(adpts == 0) return; // メモリを用意できなければ制御を返します。 ret = GetAdaptersAddresses(AF_INET, 0, 0, adpts, &len); // adpts に情報を列挙します。 if(ret != ERROR_SUCCESS) { // アダプタを列挙できなかったら制御を返します。 delete [] adpts; return; } WSADATA data; ZeroMemory(&data, sizeof(data)); WSAStartup(MAKEWORD(2, 2), &data); // adpts 配列内の各アダプタ情報を一つずつ adpt に入れてみていきます。 for(PIP_ADAPTER_ADDRESSES adpt = adpts; adpt; adpt = adpt->Next) { if(adpt->PhysicalAddressLength == 0) continue; // データリンク層を持たないなら if(adpt->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue; // ループバック アドレスなら // adpt アダプタ情報の IP アドレスを一つずつ uni に入れてみていきます。 for(PIP_ADAPTER_UNICAST_ADDRESS uni = adpt->FirstUnicastAddress; uni; uni = uni->Next) { // DNS に対して適切なアドレスでない(プライベートなど)ならば if(~(uni->Flags) & IP_ADAPTER_ADDRESS_DNS_ELIGIBLE) continue; // 次のアドレスへ // アプリケーションが使うべきでないアドレスなら if(uni->Flags & IP_ADAPTER_ADDRESS_TRANSIENT) continue; // 次のアドレスへ char host[NI_MAXHOST + 1] = {'\0'}; // host に「0.0.0.0」形式の文字列を取得します。 if(getnameinfo(uni->Address.lpSockaddr, uni->Address.iSockaddrLength , host, sizeof(host), 0, 0, NI_NUMERICHOST/*NI_NAMEREQD*/) == 0) { wstring strW; AtoW(host, strW); SendDlgItemMessage(this->hwnd , IDC_COMBO_IP, CB_ADDSTRING , 0 , (LPARAM)strW.c_str()); } } } WSACleanup(); delete [] adpts; if(SendDlgItemMessage(this->hwnd , IDC_COMBO_IP, CB_GETCOUNT , 0 , 0) > 0) { SendDlgItemMessage(this->hwnd , IDC_COMBO_IP, CB_SETCURSEL , 0 , 0); } }
char *AtoU8(const char *src, BOOL noStatic) { static char *_buf = NULL; char *tmp = NULL; char *&buf = noStatic ? tmp : _buf; if (buf) { delete [] buf; buf = NULL; } WCHAR *wsrc = AtoW(src, TRUE); if (wsrc) { buf = WtoU8(wsrc, TRUE); } delete [] wsrc; return buf; }
BOOL UrlEncodeUTF8(LPCWSTR src, DWORD srcSize, wstring& dest) { if( src == NULL || srcSize == 0 ){ return FALSE; } char* pBuff = NULL; int iLen = 0; iLen = WideCharToMultiByte(CP_UTF8, 0, src, -1, NULL, 0, NULL, NULL); pBuff = new char[iLen+1]; ZeroMemory(pBuff, iLen+1); WideCharToMultiByte(CP_UTF8, 0, src, -1, pBuff, iLen, NULL, NULL); string destBuff; for( int i=0; i<iLen; i++ ){ if( ( pBuff[i] >= 'A' && pBuff[i] <= 'Z' ) || ( pBuff[i] >= 'a' && pBuff[i] <= 'z' ) || ( pBuff[i] >= '0' && pBuff[i] <= '9' ) || pBuff[i] == '.' || pBuff[i] == '-' || pBuff[i] == '_' || pBuff[i] == '~' ) { destBuff+=pBuff[i]; }else if( pBuff[i] == ' ' ){ destBuff+="%20"; }else if( pBuff[i] == '\0' ){ }else{ char cEnc[4]=""; sprintf_s( cEnc, 4, "%%%02X", (BYTE)pBuff[i] ); destBuff+=cEnc; } } delete[] pBuff; AtoW(destBuff, dest); return TRUE; }
/* MAKE_EXPORT DragQueryFileW_new=DragQueryFileW */ UINT WINAPI DragQueryFileW_new(HDROP hDrop, UINT iFile, LPWSTR lpszFileW, UINT cch) { UINT ret; ALLOC_A(lpszFile, cch * 2); ret = DragQueryFileA(hDrop, iFile, lpszFileA, cch); if (ret && lpszFileA && iFile != 0xffffffff) { DWORD lasterr = GetLastError(); ret = AtoW(lpszFile, cch); if (!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER) ret = cch; if (ret) ret--; SetLastError(lasterr); } return ret; }
/* int CSOAPUtil::EscapeXmlString(wstring& src) { Replace(src, L"&", L"&"); Replace(src, L"<", L"<"); Replace(src, L">", L">"); Replace(src, L"\"", L"""); Replace(src, L"'", L"'"); return 1; } */ int CSOAPUtil::CreateSOAPResponseBody(char* actionXmlns, char* actionName, vector<SOAP_RESPONSE_ARG>* argumentList, char* xml, int* xmlSize) { string createXml = ""; string buff = ""; wstring buffW = L""; string buffUTF8 = ""; createXml = soapStart; Format(buff, soapActionTag, actionName, actionXmlns); createXml+=buff; for( size_t i=0; i<argumentList->size(); i++ ) { AtoW((*argumentList)[i].val, buffW); EscapeXmlString(buffW); WtoUTF8(buffW, buffUTF8); Format(buff, soapArgumentTag, (*argumentList)[i].name.c_str(), buffUTF8.c_str(), (*argumentList)[i].name.c_str()); createXml+=buff; } Format(buff, soapActionTagEnd, actionName); createXml+=buff; createXml += soapEnd; if( *xmlSize < (int)createXml.size() ) { *xmlSize = (int)createXml.size()+1; return 2; } if( xml != NULL ) { strcpy_s(xml, *xmlSize, createXml.c_str()); } *xmlSize = (int)createXml.size()+1; return 1; }
BOOL NetPlaceConvertV(void *src, void *dst) { IShellLink *shellLink; // VC4 には IShellLink ANSI 版しか定義がないための暫定処置 IPersistFile *persistFile; // (実際は NT系では IShellLinkW を呼び出し) WCHAR wSrcBuf[MAX_PATH], wDstBuf[MAX_PATH]; WCHAR *wSrc = IS_WINNT_V ? (WCHAR *)src : wSrcBuf; WCHAR *wDst = IS_WINNT_V ? wDstBuf : (WCHAR *)dst; BOOL ret = FALSE; DWORD attr, attr_mask = FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_READONLY; if (SHGetPathFromIDListV == NULL) // NT4.0 系は無視 return FALSE; if ((attr = GetFileAttributesV(src)) == 0xffffffff || (attr & attr_mask) != attr_mask) return FALSE; // ディレクトリかつronly でないものは関係ない if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLinkV, (void **)&shellLink))) { if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) { if (!IS_WINNT_V) AtoW((char *)src, wSrc, MAX_PATH); if (SUCCEEDED(persistFile->Load(wSrc, STGM_READ))) { if (SUCCEEDED(shellLink->GetPath((char *)wDst, MAX_PATH, 0, SLGP_UNCPRIORITY))) { if (!IS_WINNT_V) WtoA(wDst, (char *)wDstBuf, MAX_PATH); MakePathV(dst, wDstBuf, EMPTY_STR_V); ret = TRUE; } } persistFile->Release(); } shellLink->Release(); } return ret; }
HRESULT MAPIContact::GetContactImage(wstring &wstrImagePath) { HRESULT hr = S_OK; Zimbra::Util::ScopedInterface<IStream> pSrcStream; { Zimbra::Util::ScopedRowSet pAttachRows; Zimbra::Util::ScopedInterface<IMAPITable> pAttachTable; SizedSPropTagArray(3, attachProps) = { 3, { PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME } }; hr = m_pMessage->GetAttachmentTable(MAPI_UNICODE, pAttachTable.getptr()); if (SUCCEEDED(hr)) { if (FAILED(hr = pAttachTable->SetColumns((LPSPropTagArray) & attachProps, 0))) return hr; ULONG ulRowCount = 0; if (FAILED(hr = pAttachTable->GetRowCount(0, &ulRowCount))) return hr; if (FAILED(hr = pAttachTable->QueryRows(ulRowCount, 0, pAttachRows.getptr()))) return hr; if (SUCCEEDED(hr)) { hr = MAPI_E_NOT_FOUND; for (unsigned int i = 0; i < pAttachRows->cRows; i++) { // if property couldn't be found or returns error, skip it if ((pAttachRows->aRow[i].lpProps[2].ulPropTag == PT_ERROR) || (pAttachRows->aRow[i].lpProps[2].Value.err == MAPI_E_NOT_FOUND)) continue; // Discard the attachmetnt if its not contact picture if (_tcscmp(pAttachRows->aRow[i].lpProps[2].Value.LPSZ, _T( "ContactPicture.jpg"))) continue; Zimbra::Util::ScopedInterface<IAttach> pAttach; if (FAILED(hr = m_pMessage->OpenAttach( pAttachRows->aRow[i].lpProps[0].Value.l, NULL, 0, pAttach.getptr()))) continue; if (FAILED(hr = pAttach->OpenProperty(PR_ATTACH_DATA_BIN, &IID_IStream, STGM_READ, 0, (LPUNKNOWN FAR *)pSrcStream.getptr()))) return hr; break; } } } } if (hr != S_OK) return hr; // copy image to file wstring wstrTempAppDirPath; char *lpszDirName = NULL; char *lpszUniqueName = NULL; Zimbra::Util::ScopedInterface<IStream> pDestStream; if (!Zimbra::MAPI::Util::GetAppTemporaryDirectory(wstrTempAppDirPath)) return MAPI_E_ACCESS_DENIED; WtoA((LPWSTR)wstrTempAppDirPath.c_str(), lpszDirName); string strFQFileName = lpszDirName; WtoA((LPWSTR)Zimbra::MAPI::Util::GetUniqueName().c_str(), lpszUniqueName); strFQFileName += "\\ZmContact_"; strFQFileName += lpszUniqueName; strFQFileName += ".jpg"; SafeDelete(lpszDirName); SafeDelete(lpszUniqueName); // Open stream on file if (FAILED(hr = OpenStreamOnFile(MAPIAllocateBuffer, MAPIFreeBuffer, STGM_CREATE | STGM_READWRITE, (LPTSTR)strFQFileName.c_str(), NULL, pDestStream.getptr()))) return hr; ULARGE_INTEGER liAll = { 0 }; liAll.QuadPart = (ULONGLONG)-1; if (FAILED(hr = pSrcStream->CopyTo(pDestStream.get(), liAll, NULL, NULL))) return hr; if (FAILED(hr = pDestStream->Commit(0))) { return hr; ; } // mime file path LPWSTR lpwstrFQFileName = NULL; AtoW((LPSTR)strFQFileName.c_str(), lpwstrFQFileName); wstrImagePath = lpwstrFQFileName; SafeDelete(lpwstrFQFileName); return hr; }
BOOL TInstDlg::UnInstall(void) { char buf[MAX_PATH]; char setupDir[MAX_PATH] = ""; ::GetModuleFileName(NULL, setupDir, sizeof(setupDir)); GetParentDir(setupDir, setupDir); BOOL is_shext = FALSE; is_shext = ShellExtFunc(setupDir, CHECK_SHELLEXT); if (is_shext && IsWinVista() && !TIsUserAnAdmin()) { RunAsAdmin(TRUE); return TRUE; } if (MessageBox(GetLoadStr(IDS_START), UNINSTALL_STR, MB_OKCANCEL|MB_ICONINFORMATION) != IDOK) return FALSE; // スタートメニュー&デスクトップから削除 TRegistry reg(HKEY_CURRENT_USER, BY_MBCS); if (reg.OpenKey(REGSTR_SHELLFOLDERS)) { char *regStr[] = { REGSTR_PROGRAMS, REGSTR_DESKTOP, NULL }; for (int cnt=0; regStr[cnt] != NULL; cnt++) { if (reg.GetStr(regStr[cnt], buf, sizeof(buf))) { if (cnt == 0) RemoveSameLink(buf); ::wsprintf(buf + strlen(buf), "\\%s", FASTCOPY_SHORTCUT); if (IS_WINNT_V) { Wstr w_buf(buf, BY_MBCS); DeleteLinkV(w_buf.Buf()); } else { DeleteLinkV(buf); } } } reg.CloseKey(); } ShellExtFunc(setupDir, UNREGISTER_SHELLEXT); #ifdef _WIN64 if (IS_WINNT_V) { #else if (IS_WINNT_V && TIsWow64()) { #endif SHELLEXECUTEINFO sei = { sizeof(sei) }; char arg[1024]; sprintf(arg, "\"%s\\%s\",%s", setupDir, CURRENT_SHEXTDLL_EX, "DllUnregisterServer"); sei.lpFile = "rundll32.exe"; sei.lpParameters = arg; ShellExecuteEx(&sei); } // レジストリからアンインストール情報を削除 if (reg.OpenKey(REGSTR_PATH_UNINSTALL)) { if (reg.OpenKey(FASTCOPY)) { if (reg.GetStr(REGSTR_VAL_UNINSTALLER_COMMANDLINE, setupDir, sizeof(setupDir))) GetParentDir(setupDir, setupDir); reg.CloseKey(); } reg.DeleteKey(FASTCOPY); reg.CloseKey(); } // 終了メッセージ MessageBox(is_shext ? GetLoadStr(IDS_UNINSTSHEXTFIN) : GetLoadStr(IDS_UNINSTFIN)); // インストールディレクトリを開く if (GetFileAttributes(setupDir) != 0xffffffff) { ::ShellExecute(NULL, NULL, setupDir, 0, 0, SW_SHOW); } // AppDataディレクトリを開く if (IsWinVista()) { WCHAR wbuf[MAX_PATH] = L"", upath[MAX_PATH] = L""; WCHAR fastcopy_dir[MAX_PATH] = L"", *fastcopy_dirname = NULL; Wstr w_setup(setupDir); if (TIsVirtualizedDirV(w_setup.Buf())) { if (TSHGetSpecialFolderPathV(NULL, wbuf, CSIDL_APPDATA, FALSE)) { GetFullPathNameW(w_setup.Buf(), MAX_PATH, fastcopy_dir, &fastcopy_dirname); MakePathV(upath, wbuf, fastcopy_dirname); if (GetFileAttributesV(upath) != 0xffffffff) { ::ShellExecuteW(NULL, NULL, upath, 0, 0, SW_SHOW); } } } } ::PostQuitMessage(0); return TRUE; } BOOL ReadLink(char *src, char *dest, char *arg=NULL) { IShellLink *shellLink; // 実際は IShellLinkA or IShellLinkW IPersistFile *persistFile; WCHAR wbuf[MAX_PATH]; BOOL ret = FALSE; if (SUCCEEDED(CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (void **)&shellLink))) { if (SUCCEEDED(shellLink->QueryInterface(IID_IPersistFile, (void **)&persistFile))) { AtoW(src, wbuf, MAX_PATH); if (SUCCEEDED(persistFile->Load(wbuf, STGM_READ))) { if (SUCCEEDED(shellLink->GetPath(dest, MAX_PATH, NULL, 0))) { if (arg) { shellLink->GetArguments(arg, MAX_PATH); } ret = TRUE; } } persistFile->Release(); } shellLink->Release(); } return ret; }
BOOL CEpgDBUtil::AddSDT(const CSDTTable* sdt) { CBlockLock lock(&this->dbLock); DWORD key = ((DWORD)sdt->original_network_id)<<16 | sdt->transport_stream_id; map<DWORD, DB_TS_INFO>::iterator itrTS; itrTS = this->serviceInfoList.find(key); if( itrTS == this->serviceInfoList.end() ){ DB_TS_INFO info; info.original_network_id = sdt->original_network_id; info.transport_stream_id = sdt->transport_stream_id; for(size_t i=0; i<sdt->serviceInfoList.size(); i++ ){ DB_SERVICE_INFO item; item.original_network_id = sdt->original_network_id; item.transport_stream_id = sdt->transport_stream_id; item.service_id = sdt->serviceInfoList[i].service_id; for( size_t j=0; j<sdt->serviceInfoList[i].descriptorList.size(); j++ ){ if( sdt->serviceInfoList[i].descriptorList[j].GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::service_descriptor ){ const AribDescriptor::CDescriptor* service = &sdt->serviceInfoList[i].descriptorList[j]; CARIB8CharDecode arib; string service_provider_name = ""; string service_name = ""; const char* src; DWORD srcSize; src = service->GetStringOrEmpty(AribDescriptor::service_provider_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_provider_name); } src = service->GetStringOrEmpty(AribDescriptor::service_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_name); } AtoW(service_provider_name, item.service_provider_name); AtoW(service_name, item.service_name); item.service_type = (BYTE)service->GetNumber(AribDescriptor::service_type); } } info.serviceList.insert(std::make_pair(item.service_id, item)); } this->serviceInfoList.insert(std::make_pair(key, info)); }else{ for(size_t i=0; i<sdt->serviceInfoList.size(); i++ ){ map<WORD,DB_SERVICE_INFO>::iterator itrS; itrS = itrTS->second.serviceList.find(sdt->serviceInfoList[i].service_id); if( itrS == itrTS->second.serviceList.end()){ DB_SERVICE_INFO item; item.original_network_id = sdt->original_network_id; item.transport_stream_id = sdt->transport_stream_id; item.service_id = sdt->serviceInfoList[i].service_id; for( size_t j=0; j<sdt->serviceInfoList[i].descriptorList.size(); j++ ){ if( sdt->serviceInfoList[i].descriptorList[j].GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::service_descriptor ){ const AribDescriptor::CDescriptor* service = &sdt->serviceInfoList[i].descriptorList[j]; CARIB8CharDecode arib; string service_provider_name = ""; string service_name = ""; const char* src; DWORD srcSize; src = service->GetStringOrEmpty(AribDescriptor::service_provider_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_provider_name); } src = service->GetStringOrEmpty(AribDescriptor::service_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_name); } AtoW(service_provider_name, item.service_provider_name); AtoW(service_name, item.service_name); item.service_type = (BYTE)service->GetNumber(AribDescriptor::service_type); } } itrTS->second.serviceList.insert(std::make_pair(item.service_id, item)); } } } return TRUE; }
//自ストリームのサービス一覧をSITから取得する //引数: // serviceListSize [OUT]serviceListの個数 // serviceList [OUT]サービス情報のリスト(DLL内で自動的にdeleteする。次に取得を行うまで有効) BOOL CDecodeUtil::GetServiceListSIT( DWORD* serviceListSize, SERVICE_INFO** serviceList ) { if( this->sitInfo == NULL || this->patInfo == NULL ){ return FALSE; } SAFE_DELETE_ARRAY(this->serviceList); //ONID WORD ONID = 0xFFFF; for( size_t i=0; i<this->sitInfo->descriptorList.size(); i++ ){ if( this->sitInfo->descriptorList[i]->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::network_identification_descriptor ){ ONID = (WORD)this->sitInfo->descriptorList[i]->GetNumber(AribDescriptor::network_id); } } //TSID WORD TSID = 0xFFFF; TSID = this->patInfo->transport_stream_id; *serviceListSize = (DWORD)this->sitInfo->serviceLoopList.size(); this->serviceList = new SERVICE_INFO[*serviceListSize]; wstring network_nameW = L""; wstring ts_nameW = L""; BYTE remote_control_key_id = 0; //サービスリスト for( DWORD i=0; i<*serviceListSize; i++ ){ this->serviceList[i].original_network_id = ONID; this->serviceList[i].transport_stream_id = TSID; this->serviceList[i].service_id = this->sitInfo->serviceLoopList[i]->service_id; this->serviceList[i].extInfo = new SERVICE_EXT_INFO; for( size_t j=0; j<this->sitInfo->serviceLoopList[i]->descriptorList.size(); j++ ){ if( this->sitInfo->serviceLoopList[i]->descriptorList[j]->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::service_descriptor ){ AribDescriptor::CDescriptor* service = this->sitInfo->serviceLoopList[i]->descriptorList[j]; CARIB8CharDecode arib; string service_provider_name = ""; string service_name = ""; const char* src; DWORD srcSize; src = service->GetStringOrEmpty(AribDescriptor::service_provider_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_provider_name); } src = service->GetStringOrEmpty(AribDescriptor::service_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_name); } wstring service_provider_nameW = L""; wstring service_nameW = L""; AtoW(service_provider_name, service_provider_nameW); AtoW(service_name, service_nameW); this->serviceList[i].extInfo->service_type = (BYTE)service->GetNumber(AribDescriptor::service_type); if( service_provider_nameW.size() > 0 ){ this->serviceList[i].extInfo->service_provider_name = new WCHAR[service_provider_nameW.size()+1]; wcscpy_s(this->serviceList[i].extInfo->service_provider_name, service_provider_nameW.size()+1, service_provider_nameW.c_str()); } if( service_nameW.size() > 0 ){ this->serviceList[i].extInfo->service_name = new WCHAR[service_nameW.size()+1]; wcscpy_s(this->serviceList[i].extInfo->service_name, service_nameW.size()+1, service_nameW.c_str()); } } } if( network_nameW.size() > 0 ){ this->serviceList[i].extInfo->network_name = new WCHAR[network_nameW.size()+1]; wcscpy_s(this->serviceList[i].extInfo->network_name, network_nameW.size()+1, network_nameW.c_str()); } if( ts_nameW.size() > 0 ){ this->serviceList[i].extInfo->ts_name = new WCHAR[ts_nameW.size()+1]; wcscpy_s(this->serviceList[i].extInfo->ts_name, ts_nameW.size()+1, ts_nameW.c_str()); } this->serviceList[i].extInfo->remote_control_key_id = remote_control_key_id; this->serviceList[i].extInfo->partialReceptionFlag = FALSE; } *serviceList = this->serviceList; return TRUE; }
// 返回客户端请求对象, 如果返回空字符串,说明客户端请求格式错误. std::wstring CHTTPRequest::GetUrlObject() { std::wstring strObject(L""); const char* lpszRequest = m_pData; const char *pStart = NULL, *pEnd = NULL; // 第一行的第一个空格的下一个字符开始是请求的文件名开始. for(int i = 0; i < m_nPos; ++i) { if(lpszRequest[i] == ' ') { pStart = lpszRequest + i + 1; break; } if(lpszRequest[i] == '\n') break; } if(pStart == NULL) return strObject; // 从第一行的末尾方向查找第一个空格,实例: GET / HTTP/1.1 pEnd = strstr(lpszRequest, "\r\n"); ASSERT(pEnd); if(pEnd == NULL || pEnd < pStart) return strObject; while(pEnd >= pStart) { if(pEnd[0] == ' ') { pEnd--; break; } pEnd--; } if(pEnd == NULL || pEnd < pStart) return strObject; // 已经取到了开始和结束的位置. int nObjectLen = pEnd - pStart + 1; char *pszObject = new char[nObjectLen + 1]; ASSERT(pszObject); ZeroMemory(pszObject, nObjectLen + 1); // UTF8解码 int nNewPos = 0; BOOL bUTF8 = FALSE; for( int i = 0; i < nObjectLen; ++i) { if(pStart[i] == '?') { // '?' 后面是参数,忽略. break; } if(pStart[i] == '%' && i + 1 < nObjectLen && i + 2 < nObjectLen) { char szValue[5] = {0}, *pStopPos = NULL; szValue[0] = '0'; szValue[1] = 'x'; szValue[2] = pStart[i + 1]; szValue[3] = pStart[i + 2]; szValue[4] = 0; pszObject[nNewPos++] = (char) strtol(szValue, &pStopPos, 16); i += 2; // 空格会被编码为 %20 if(pszObject[nNewPos - 1] != ' ') { bUTF8 = TRUE; } } else { // 获取的是URL,不应该替换正斜杠 //if(pStart[i] == '/') pszObject[nNewPos++] = '\\'; //else pszObject[nNewPos++] = pStart[i]; pszObject[nNewPos++] = pStart[i]; } } if(bUTF8) { strObject = UTF8toW(pszObject); //std::wstring wURL = UTF8toW(pszObject); //strObject = WtoA(wURL.c_str()); } else { strObject = AtoW(pszObject); } delete[] pszObject; return strObject; }
void DoReport(LPCTSTR lpstrCmdLine, BOOL *pIsHandled) { WSADATA wsaData = {0}; WSAStartup(MAKEWORD(2, 2), &wsaData); //LogFinal(LOG::KBugReport) << L"Bugreport启动命令行: " << lpstrCmdLine; REPORT_CONTEXT report; std::wstring strProductName; const TCHAR * p = _tcsstr(lpstrCmdLine, _T("pid=")); if (p) { *pIsHandled = TRUE; DWORD client_process_id = _tcstoul(p + _tcslen(_T("pid=")), 0, 0); p = _tcsstr(lpstrCmdLine, _T("context=")); if (p) { void *addr = (void*)_tcstoul(p + _tcslen(_T("context=")), 0, 0); //YYBrowser Begin //by ZC. 2013-10-30 11:26. // hClientProcess客户进程,即是启动YGCrashReport的进程,不一定是崩溃的目标进程。 HANDLE client_process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, client_process_id); // 崩溃目标进程。 HANDLE target_process_handle = NULL; //YYBrowser End if (!client_process_handle) LogFinal(LOG::KBugReport) << L"打开进程句柄失败"; //解释REPORT_PARAMS CRASH_LAUNCH_PARAMS crash_launch_params = {0}; DWORD cbRead = 0; if (addr && ::ReadProcessMemory(client_process_handle, addr, &crash_launch_params, sizeof(crash_launch_params), &cbRead)) { LogFinal(LOG::KBugReport) << L"读取REPORT_PARAMS成功"; std::set<std::wstring> setSuspectModule; std::set<std::wstring> setModule; std::wstring strPathNoExt = GenerateNewFilePath(crash_launch_params.dwPID); report.strZipFilePath = strPathNoExt + _T(".zip"); report.strOSVer = GetOSVer(); AtoW(crash_launch_params.szProductName, -1, strProductName); report.dwReportId = crash_launch_params.dwReportId; report.strUserId = crash_launch_params.szUserId; report.strProductId = crash_launch_params.szProductId; report.strProductVer = crash_launch_params.szProductVer; report.strProductVerDetail = crash_launch_params.szProductVerDetail; //AtoW(crash_launch_params.szRestartExePath, -1, report.wstrRestartExePath); report.strDynaReleaseVer = crash_launch_params.szDynaReleaseVer; WriteBugInfo(report.dwReportId); report.dwCount24Hour = GetBugCount(report.dwReportId); //parse 自定义文件路径 if (crash_launch_params.nFileCount > 0) { char *pPaths = new char[MAX_PATH * crash_launch_params.nFileCount]; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCustomFilePaths, pPaths, MAX_PATH * crash_launch_params.nFileCount, &cbRead)) { for (UINT k = 0; k < cbRead / MAX_PATH; k++) { std::wstring wstrPath; AtoW(pPaths + k * MAX_PATH, -1, wstrPath); report.vecOtherFilePath.push_back(wstrPath); } } delete [] pPaths; pPaths = NULL; } //生成log std::string strLog; char szTemp[1024] = {0}; //Date time_t curTime = 0; time(&curTime); strftime(szTemp, _countof(szTemp)-1, "%Y-%m-%d %H.%M.%S\r\n", localtime(&curTime)); strLog += szTemp; strLog += "\r\n"; //异常信息 strLog += "Exception:\r\n"; const char *pModName = strrchr(crash_launch_params.szExcepModPath, '\\'); if (pModName) pModName++; else pModName = crash_launch_params.szExcepModPath; report.strExcepModuleName = pModName; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "Module=%s\r\n", pModName); strLog += szTemp; //YYBrowser Begin //打开目标进程。by ZC. 2013-10-30 11:30. target_process_handle = ::OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, crash_launch_params.dwPID); //YYBrowser End //YYBrowser Begin //从目标进程中读出结构异常。by ZC. 2013-10-30 11:28. if (crash_launch_params.pExceptionInfo) { EXCEPTION_RECORD excep = {0}; CONTEXT ct = {0}; EXCEPTION_POINTERS ptr = {0}; if (::ReadProcessMemory(target_process_handle, crash_launch_params.pExceptionInfo, &ptr, sizeof(ptr), &cbRead) && ::ReadProcessMemory(target_process_handle, ptr.ExceptionRecord, &excep, sizeof(excep), &cbRead) && ::ReadProcessMemory(target_process_handle, ptr.ContextRecord, &ct, sizeof(ct), &cbRead)) { report.dwExcepAddr = (DWORD)excep.ExceptionAddress; report.dwExcepCode = excep.ExceptionCode; report.strExcepDiscription = GetExceptionDescription(excep.ExceptionCode); _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "ExceptionCode=0x%08x, %s\r\n", excep.ExceptionCode, GetExceptionDescription(excep.ExceptionCode)); strLog += szTemp; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "eip=0x%08x, ebp=0x%08x, esp=0x%08x, eax=0x%08x, ebx=0x%08x, ecx=0x%08x, edx=0x%08x, esi=0x%08x, edi=0x%08x\r\n", ct.Eip, ct.Ebp, ct.Esp, ct.Eax, ct.Ebx, ct.Ecx, ct.Edx, ct.Esi, ct.Edi); strLog += szTemp; } strLog += "\r\n"; } //YYBrowser End strLog += "Summary:\r\n"; strLog += GetSummary(client_process_handle); strLog += "UserId(YY)=" + report.strUserId + "\r\n"; strLog += "ProductVer=" + report.strProductVer + "\r\n"; strLog += "DynaReleaseVer=" + report.strDynaReleaseVer + "\r\n"; strLog += "ProductVerDetail=" + report.strProductVerDetail + "\r\n"; _snprintf_s(szTemp, _countof(szTemp), _TRUNCATE, "ReportId=%u\r\n", report.dwReportId); strLog += szTemp; strLog += "\r\n"; std::string strLoginHistoryLog; std::string strLoginHistory = ReadLoginHistory(strLoginHistoryLog); //用户自定义信息 strLog += "CustomProperty:\r\n"; char *pCustomProperty = new char[crash_launch_params.cchCustomProperty + 1]; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCustomProperty, pCustomProperty, crash_launch_params.cchCustomProperty, &cbRead)) { pCustomProperty[cbRead/sizeof(char)] = 0; report.strCustomProperty = pCustomProperty; } strLog += report.strCustomProperty; if(strLoginHistory.size()>0) { if(report.strCustomProperty.size()>0) { report.strCustomProperty+="&"; } report.strCustomProperty+=strLoginHistory; } if(strLoginHistoryLog.size()>0) { strLog += "\r\n"; strLog += strLoginHistoryLog; } strLog += "\r\n"; //CallStack strLog += "Call Stack:\r\n"; char *pCallStack = new char[crash_launch_params.cchCallStack + 1]; cbRead = 0; if (::ReadProcessMemory(client_process_handle, crash_launch_params.lpszCallStack, pCallStack, crash_launch_params.cchCallStack, &cbRead)) { pCallStack[cbRead/sizeof(char)] = 0; strLog += pCallStack; } strLog += "\r\n"; //收集进程列表&检测运行环境 std::string strProcListA; std::wstring strProcListW; report.dwRunEnvironment = CheckRunEnvironment(strProcListW); WtoA(strProcListW.c_str(), -1, strProcListA); strLog += "Process List:\r\n"; strLog += strProcListA; strLog += "\r\n"; //收集版本的语言种类,不写入日志 report.strProductLang = GetLanguageName(); //模块列表 strLog += "Module List:\r\n"; strLog += GetModuleList(target_process_handle,&setModule,&setSuspectModule); strLog += "\r\n"; //程序Log strLog += "Log:\r\n"; TCHAR szExePath[MAX_PATH] = {0}; GetModuleFileNameEx(target_process_handle, NULL, szExePath, _countof(szExePath)); TCHAR *p = _tcsrchr(szExePath, _T('.')); if (p) *p = 0; TCHAR* pExeName = _tcsrchr(szExePath, _T('\\')); if (pExeName) pExeName++; else pExeName = szExePath; const DWORD dwMaxLogSize = 1024 * 200; // char *pContent = new char [dwMaxLogSize]; // GetLastLog(pExeName, reportParams.dwPID, 0, pContent, dwMaxLogSize); // strLog += pContent; // delete [] pContent; // pContent = NULL; strLog += "\r\n\r\n"; /************************************************************************/ /*功能:在日志文件中添加安装目录下所有dll和rcc文件的md5*/ /***************************只有yy.exe崩溃时,才会计算相关文件的md5*/ if (StrCmpIA(crash_launch_params.szProductId, "YY") == 0) { strLog += "[List *.dll and *.rcc files MD5:] \r\n\r\n"; TCHAR szCurrentProcesspath[MAX_PATH] = {0}; if ( GetModuleFileName(NULL,szCurrentProcesspath,_countof(szCurrentProcesspath)) > 0) { TCHAR* p_findDir = _tcsrchr(szCurrentProcesspath,_T('\\')); std::wstring rawCurrentProcessPath = szCurrentProcesspath; std::wstring strCurrentProcesspath = rawCurrentProcessPath.substr(0, p_findDir - szCurrentProcesspath); strLog += dwCalculateMD5(strCurrentProcesspath.c_str()); } else { strLog += "Get the files'MD5 failed!"; } } else { strLog += "Hint:\r\nThe crash was caused by the other products except the YY!"; } /************************************************************************/ TCHAR szLogPath[_MAX_PATH] = {0}; _sntprintf_s(szLogPath, _countof(szLogPath), _TRUNCATE, _T("%s.txt"), strPathNoExt.c_str()); report.strLogPath = szLogPath; LogFinal(LOG::KBugReport) << L"写入log文件: " << szLogPath; HANDLE hFile = ::CreateFile(szLogPath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, NULL, NULL); DWORD dwWriten = 0; ::WriteFile(hFile, strLog.c_str(), strLog.size(), &dwWriten, NULL); ::CloseHandle(hFile); //生成dump TCHAR szDumpPath[_MAX_PATH] = {0}; _sntprintf_s(szDumpPath, _countof(szDumpPath), _TRUNCATE, _T("%s.dmp"), strPathNoExt.c_str()); LogFinal(LOG::KBugReport) << L"生成dump文件: " << szDumpPath; int nDumpType = (MiniDumpNormal|MiniDumpWithHandleData|MiniDumpWithIndirectlyReferencedMemory|MiniDumpWithUnloadedModules|MiniDumpWithProcessThreadData); if (!CreateDump(szDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, nDumpType, MyMiniDumpCallBack, &crash_launch_params)) { crash_launch_params.curCustomDataIdx = 0; CreateDump(szDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, MiniDumpNormal, MyMiniDumpCallBack, &crash_launch_params); } report.strDumpPath = szDumpPath; //生成fulldump CRegKey key; LONG lResult = key.Open(HKEY_CURRENT_USER, _T("Software\\duowan\\bugreport"), KEY_READ); if (ERROR_SUCCESS == lResult) { TCHAR szFullDump[1024] = {0}; DWORD dwSize = _countof(szFullDump); lResult = key.QueryValue(szFullDump, _T("fulldump"), &dwSize); if (ERROR_SUCCESS == lResult) { szFullDump[dwSize] = 0; if (_tcsicmp(szFullDump, _T("yes")) == 0) { nDumpType = (MiniDumpNormal | MiniDumpWithFullMemory | MiniDumpWithIndirectlyReferencedMemory | MiniDumpWithHandleData | MiniDumpWithUnloadedModules | MiniDumpWithProcessThreadData); TCHAR szFullDumpPath[_MAX_PATH] = {0}; ::GetTempPath(_countof(szFullDumpPath), szFullDumpPath); _tcsncat_s(szFullDumpPath, _countof(szFullDumpPath), _T("duowan\\fulldump.dmp"), _TRUNCATE); LogFinal(LOG::KBugReport) << L"生成fulldump文件: " << szFullDumpPath; CreateDump(szFullDumpPath, crash_launch_params.dwPID, crash_launch_params.dwTID, crash_launch_params.pExceptionInfo, nDumpType, MyMiniDumpCallBack, &crash_launch_params); } } } ::SetEvent(crash_launch_params.evDumpComplete); if (crash_launch_params.bShowReportUI) { LogFinal(LOG::KBugReport) << L"开始弹出崩溃界面"; std::string strRecv; bool bShowModifyStatus = false; //if(GetBugModifyStatus(&report,strRecv)) //{ // const char* p = strstr(strRecv.c_str(),"return=true"); // if(p) // { // bShowModifyStatus = true; // } //} CMessageLoop theLoop; _Module.AddMessageLoop(&theLoop); CDlgReport dlgMain(strProductName.c_str(), &report, crash_launch_params.dwPID, &setModule, &setSuspectModule, bShowModifyStatus, strRecv.c_str()); dlgMain.Create(NULL); dlgMain.ShowWindow(SW_SHOW); theLoop.Run(); _Module.RemoveMessageLoop(); } else { SendReport(&report, &setModule, &setSuspectModule); } } else { LogFinal(LOG::KBugReport) << L"读取崩溃进程REPORT_PARAMS失败"; } ::CloseHandle(target_process_handle); ::CloseHandle(client_process_handle); } } }
void *toV(const char *src, BOOL noStatic) { if (IS_WINNT_V) { return AtoW(src, noStatic); } return noStatic ? strdupNew(src) : (char *)src; }
WCHAR *toW(const void *src, BOOL noStatic) { if (!IS_WINNT_V) { return AtoW((char *)src, noStatic); } return noStatic ? wcsdupNew((WCHAR *)src) : (WCHAR *)src; }
void TInifile::Init(const char *_ini_file) { InitCore(IsUTF8(_ini_file) ? U8toW(_ini_file) : AtoW(_ini_file)); }
//自ストリームのサービス一覧を取得する //引数: // serviceListSize [OUT]serviceListの個数 // serviceList [OUT]サービス情報のリスト(DLL内で自動的にdeleteする。次に取得を行うまで有効) BOOL CDecodeUtil::GetServiceListActual( DWORD* serviceListSize, SERVICE_INFO** serviceList ) { SAFE_DELETE_ARRAY(this->serviceList); if( this->nitActualInfo == NULL || this->sdtActualInfo == NULL ){ return GetServiceListSIT(serviceListSize, serviceList); }else{ if( this->nitActualInfo->last_section_number+1 != this->nitActualInfo->nitSection.size() || this->sdtActualInfo->last_section_number+1 != this->sdtActualInfo->sdtSection.size() ){ return FALSE; } } *serviceListSize = 0; map<BYTE, CSDTTable*>::iterator itrSdt; for(itrSdt = this->sdtActualInfo->sdtSection.begin(); itrSdt != this->sdtActualInfo->sdtSection.end(); itrSdt++){ *serviceListSize += (DWORD)itrSdt->second->serviceInfoList.size(); } this->serviceList = new SERVICE_INFO[*serviceListSize]; wstring network_nameW = L""; wstring ts_nameW = L""; BYTE remote_control_key_id = 0; vector<WORD> partialServiceList; map<BYTE, CNITTable*>::iterator itrNit; for( itrNit = this->nitActualInfo->nitSection.begin(); itrNit != this->nitActualInfo->nitSection.end(); itrNit++ ){ for( size_t i=0; i<itrNit->second->descriptorList.size(); i++ ){ if( itrNit->second->descriptorList[i]->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::network_name_descriptor ){ AribDescriptor::CDescriptor* networkName = itrNit->second->descriptorList[i]; DWORD srcSize; const char* src = networkName->GetStringOrEmpty(AribDescriptor::d_char, &srcSize); if( srcSize > 0 ){ CARIB8CharDecode arib; string network_name = ""; arib.PSISI((const BYTE*)src, srcSize, &network_name); AtoW(network_name, network_nameW); } } } for( size_t i=0; i<itrNit->second->TSInfoList.size(); i++ ){ for( size_t j=0; j<itrNit->second->TSInfoList[i]->descriptorList.size(); j++ ){ if( itrNit->second->TSInfoList[i]->descriptorList[j]->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::ts_information_descriptor ){ AribDescriptor::CDescriptor* TSInfo = itrNit->second->TSInfoList[i]->descriptorList[j]; DWORD srcSize; const char* src = TSInfo->GetStringOrEmpty(AribDescriptor::ts_name_char, &srcSize); if( srcSize > 0 ){ CARIB8CharDecode arib; string ts_name = ""; arib.PSISI((const BYTE*)src, srcSize, &ts_name); AtoW(ts_name, ts_nameW); } remote_control_key_id = (BYTE)TSInfo->GetNumber(AribDescriptor::remote_control_key_id); } if( itrNit->second->TSInfoList[i]->descriptorList[j]->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::partial_reception_descriptor ){ partialServiceList.clear(); AribDescriptor::CDescriptor::CLoopPointer lp; if( itrNit->second->TSInfoList[i]->descriptorList[j]->EnterLoop(lp) ){ for( DWORD k=0; itrNit->second->TSInfoList[i]->descriptorList[j]->SetLoopIndex(lp, k); k++ ){ partialServiceList.push_back((WORD)itrNit->second->TSInfoList[i]->descriptorList[j]->GetNumber(AribDescriptor::service_id, lp)); } } } } } } DWORD count = 0; for(itrSdt = this->sdtActualInfo->sdtSection.begin(); itrSdt != this->sdtActualInfo->sdtSection.end(); itrSdt++){ for( size_t i=0; i<itrSdt->second->serviceInfoList.size(); i++ ){ this->serviceList[count].original_network_id = itrSdt->second->original_network_id; this->serviceList[count].transport_stream_id = itrSdt->second->transport_stream_id; this->serviceList[count].service_id = itrSdt->second->serviceInfoList[i]->service_id; this->serviceList[count].extInfo = new SERVICE_EXT_INFO; for( size_t j=0; j<itrSdt->second->serviceInfoList[i]->descriptorList.size(); j++ ){ if( itrSdt->second->serviceInfoList[i]->descriptorList[j]->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::service_descriptor ){ AribDescriptor::CDescriptor* service = itrSdt->second->serviceInfoList[i]->descriptorList[j]; CARIB8CharDecode arib; string service_provider_name = ""; string service_name = ""; const char* src; DWORD srcSize; src = service->GetStringOrEmpty(AribDescriptor::service_provider_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_provider_name); } src = service->GetStringOrEmpty(AribDescriptor::service_name, &srcSize); if( srcSize > 0 ){ arib.PSISI((const BYTE*)src, srcSize, &service_name); } wstring service_provider_nameW = L""; wstring service_nameW = L""; AtoW(service_provider_name, service_provider_nameW); AtoW(service_name, service_nameW); this->serviceList[count].extInfo->service_type = (BYTE)service->GetNumber(AribDescriptor::service_type); if( service_provider_nameW.size() > 0 ){ this->serviceList[count].extInfo->service_provider_name = new WCHAR[service_provider_nameW.size()+1]; wcscpy_s(this->serviceList[count].extInfo->service_provider_name, service_provider_nameW.size()+1, service_provider_nameW.c_str()); } if( service_nameW.size() > 0 ){ this->serviceList[count].extInfo->service_name = new WCHAR[service_nameW.size()+1]; wcscpy_s(this->serviceList[count].extInfo->service_name, service_nameW.size()+1, service_nameW.c_str()); } } } if( network_nameW.size() > 0 ){ this->serviceList[count].extInfo->network_name = new WCHAR[network_nameW.size()+1]; wcscpy_s(this->serviceList[count].extInfo->network_name, network_nameW.size()+1, network_nameW.c_str()); } if( ts_nameW.size() > 0 ){ this->serviceList[count].extInfo->ts_name = new WCHAR[ts_nameW.size()+1]; wcscpy_s(this->serviceList[count].extInfo->ts_name, ts_nameW.size()+1, ts_nameW.c_str()); } this->serviceList[count].extInfo->remote_control_key_id = remote_control_key_id; this->serviceList[count].extInfo->partialReceptionFlag = FALSE; for( size_t j=0; j<partialServiceList.size(); j++ ){ if( partialServiceList[j] == this->serviceList[count].service_id ){ this->serviceList[count].extInfo->partialReceptionFlag = TRUE; } } count++; } } *serviceList = this->serviceList; return TRUE; }
HRESULT MAPIContact::GetContactImage(wstring &wstrImagePath,wstring &wstrContentType,wstring &wstrContentDisposition) { HRESULT hr = S_OK; LPSTR strExtension=".jpg"; Zimbra::Util::ScopedInterface<IStream> pSrcStream; { Zimbra::Util::ScopedRowSet pAttachRows; Zimbra::Util::ScopedInterface<IMAPITable> pAttachTable; SizedSPropTagArray(4, attachProps) = { 4, { PR_ATTACH_NUM, PR_ATTACH_SIZE, PR_ATTACH_LONG_FILENAME,PR_ATTACH_EXTENSION } }; hr = m_pMessage->GetAttachmentTable(MAPI_UNICODE, pAttachTable.getptr()); if (SUCCEEDED(hr)) { if (FAILED(hr = pAttachTable->SetColumns((LPSPropTagArray) & attachProps, 0))) return hr; ULONG ulRowCount = 0; if (FAILED(hr = pAttachTable->GetRowCount(0, &ulRowCount))) return hr; if (FAILED(hr = pAttachTable->QueryRows(ulRowCount, 0, pAttachRows.getptr()))) return hr; if (SUCCEEDED(hr)) { hr = MAPI_E_NOT_FOUND; for (unsigned int i = 0; i < pAttachRows->cRows; i++) { // if property couldn't be found or returns error, skip it if ((pAttachRows->aRow[i].lpProps[2].ulPropTag == PT_ERROR) || (pAttachRows->aRow[i].lpProps[2].Value.err == MAPI_E_NOT_FOUND)) continue; // Discard the attachmetnt if its not contact picture if (_tcscmp(pAttachRows->aRow[i].lpProps[2].Value.LPSZ, _T( "ContactPicture.jpg"))) continue; Zimbra::Util::ScopedInterface<IAttach> pAttach; if (FAILED(hr = m_pMessage->OpenAttach( pAttachRows->aRow[i].lpProps[0].Value.l, NULL, 0, pAttach.getptr()))) continue; if (FAILED(hr = pAttach->OpenProperty(PR_ATTACH_DATA_BIN, &IID_IStream, STGM_READ, 0, (LPUNKNOWN FAR *)pSrcStream.getptr()))) return hr; // LPSPropValue pProps = NULL; // ULONG cProps = 0; // hr = pAttach->GetProps((LPSPropTagArray) & attachProps, 0, &cProps, &pProps); if(pAttachRows->aRow[i].lpProps[3].ulPropTag == PR_ATTACH_EXTENSION_A) //if (pProps[PR_ATTACH_EXTENSION].ulPropTag == PR_ATTACH_EXTENSION_A) { // add a custom header for content location to support rfc2557 LPSTR pContentType = NULL; strExtension = pAttachRows->aRow[i].lpProps[3].Value.lpszA; Zimbra::MAPI::Util::GetContentTypeFromExtension(pAttachRows->aRow[i].lpProps[3].Value.lpszA, pContentType); LPWSTR lpwstrContentType = NULL; AtoW((LPSTR)pContentType, lpwstrContentType); wstrContentType = lpwstrContentType; } break; } } } } if (hr != S_OK) return hr; // copy image to file wstring wstrTempAppDirPath; char *lpszDirName = NULL; char *lpszUniqueName = NULL; Zimbra::Util::ScopedInterface<IStream> pDestStream; if (!Zimbra::MAPI::Util::GetAppTemporaryDirectory(wstrTempAppDirPath)) return MAPI_E_ACCESS_DENIED; WtoA((LPWSTR)wstrTempAppDirPath.c_str(), lpszDirName); string strFQFileName = lpszDirName; WtoA((LPWSTR)Zimbra::MAPI::Util::GetUniqueName().c_str(), lpszUniqueName); strFQFileName += "\\ZmContact_"; strFQFileName += lpszUniqueName; //strFQFileName += ".jpg"; strFQFileName += strExtension; SafeDelete(lpszDirName); SafeDelete(lpszUniqueName); // Open stream on file if (FAILED(hr = OpenStreamOnFile(MAPIAllocateBuffer, MAPIFreeBuffer, STGM_CREATE | STGM_READWRITE, (LPTSTR)strFQFileName.c_str(), NULL, pDestStream.getptr()))) return hr; ULARGE_INTEGER liAll = { 0 }; liAll.QuadPart = (ULONGLONG)-1; if (FAILED(hr = pSrcStream->CopyTo(pDestStream.get(), liAll, NULL, NULL))) return hr; if (FAILED(hr = pDestStream->Commit(0))) { return hr; ; } // mime file path LPWSTR lpwstrFQFileName = NULL; AtoW((LPSTR)strFQFileName.c_str(), lpwstrFQFileName); wstrImagePath = lpwstrFQFileName; LPSTR ppszCD; mimepp::String theCD; theCD.append("Content-Disposition: form-data; name=\""); theCD.append(strFQFileName.c_str()); theCD.append("\"; filename=\""); theCD.append(strFQFileName.c_str()); theCD.append("\""); const char *pFinal = theCD.c_str(); Zimbra::Util::CopyString(ppszCD, (LPSTR)pFinal); LPWSTR lpwstrContentDisp = NULL; AtoW((LPSTR)theCD.c_str(), lpwstrContentDisp); wstrContentDisposition = lpwstrContentDisp; /* LPSTR pContentType = NULL; Zimbra::MAPI::Util::GetContentTypeFromExtension(".jpg", pContentType); LPWSTR lpwstrContentType = NULL; AtoW((LPSTR)pContentType, lpwstrContentType); wstrContentType = lpwstrContentType;*/ SafeDelete(lpwstrFQFileName); return hr; }
BOOL CParseChText4::Parse1Line(string parseLine, CH_DATA4* chInfo ) { if( parseLine.empty() == true || chInfo == NULL ){ return FALSE; } string strBuff=""; Separate( parseLine, "\t", strBuff, parseLine); //Ch名 AtoW(strBuff, chInfo->chName); Separate( parseLine, "\t", strBuff, parseLine); //サービス名 AtoW(strBuff, chInfo->serviceName); Separate( parseLine, "\t", strBuff, parseLine); //ts_name or network_name AtoW(strBuff, chInfo->networkName); Separate( parseLine, "\t", strBuff, parseLine); //Space chInfo->space = atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //Ch chInfo->ch = atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //ONID chInfo->originalNetworkID = atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //TSID chInfo->transportStreamID = (WORD)atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //SID chInfo->serviceID = (WORD)atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //Service Type chInfo->serviceType = atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //Partial Flag chInfo->partialFlag = atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //Use chInfo->useViewFlag = atoi(strBuff.c_str()); Separate( parseLine, "\t", strBuff, parseLine); //リモコンID chInfo->remoconID = atoi(strBuff.c_str()); return TRUE; }
BOOL CEpgDBUtil::AddServiceList(const CNITTable* nit) { if( nit == NULL ){ return FALSE; } CBlockLock lock(&this->dbLock); wstring network_nameW = L""; for( size_t i=0; i<nit->descriptorList.size(); i++ ){ if( nit->descriptorList[i].GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::network_name_descriptor ){ const AribDescriptor::CDescriptor* networkName = &nit->descriptorList[i]; DWORD srcSize; const char* src = networkName->GetStringOrEmpty(AribDescriptor::d_char, &srcSize); if( srcSize > 0 ){ CARIB8CharDecode arib; string network_name = ""; arib.PSISI((const BYTE*)src, srcSize, &network_name); AtoW(network_name, network_nameW); } } } for( size_t i=0; i<nit->TSInfoList.size(); i++ ){ const CNITTable::TS_INFO_DATA* tsInfo = &nit->TSInfoList[i]; //サービス情報更新用 map<DWORD, DB_TS_INFO>::iterator itrFind; itrFind = this->serviceInfoList.find((DWORD)tsInfo->original_network_id << 16 | tsInfo->transport_stream_id); if( itrFind != this->serviceInfoList.end() ){ itrFind->second.network_name = network_nameW; } for( size_t j=0; j<tsInfo->descriptorList.size(); j++ ){ const AribDescriptor::CDescriptor* desc = &tsInfo->descriptorList[j]; if( desc->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::service_list_descriptor ){ AribDescriptor::CDescriptor::CLoopPointer lp; if( desc->EnterLoop(lp) ){ for( DWORD k=0; desc->SetLoopIndex(lp, k); k++ ){ ULONGLONG key = _Create64Key(tsInfo->original_network_id, tsInfo->transport_stream_id, (WORD)desc->GetNumber(AribDescriptor::service_id, lp)); map<ULONGLONG, BYTE>::iterator itrService; itrService = this->serviceList.find(key); if( itrService == this->serviceList.end() ){ this->serviceList.insert(pair<ULONGLONG, BYTE>(key, (BYTE)desc->GetNumber(AribDescriptor::service_type, lp))); } } } } if( desc->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::ts_information_descriptor && itrFind != this->serviceInfoList.end()){ //ts_nameとremote_control_key_id DWORD srcSize; const char* src = desc->GetStringOrEmpty(AribDescriptor::ts_name_char, &srcSize); if( srcSize > 0 ){ CARIB8CharDecode arib; string ts_name = ""; arib.PSISI((const BYTE*)src, srcSize, &ts_name); AtoW(ts_name, itrFind->second.ts_name); } itrFind->second.remote_control_key_id = (BYTE)desc->GetNumber(AribDescriptor::remote_control_key_id); } if( desc->GetNumber(AribDescriptor::descriptor_tag) == AribDescriptor::partial_reception_descriptor && itrFind != this->serviceInfoList.end()){ //部分受信フラグ AribDescriptor::CDescriptor::CLoopPointer lp; if( desc->EnterLoop(lp) ){ map<WORD,DB_SERVICE_INFO>::iterator itrService; for( DWORD k=0; desc->SetLoopIndex(lp, k); k++ ){ itrService = itrFind->second.serviceList.find((WORD)desc->GetNumber(AribDescriptor::service_id, lp)); if( itrService != itrFind->second.serviceList.end() ){ itrService->second.partialReceptionFlag = 1; } } } } } } return TRUE; }