/* ディレクトリダイアログ用汎用ルーチン */ BOOL BrowseDirDlg(TWin *parentWin, const char *title, const char *defaultDir, char *buf) { IMalloc *iMalloc = NULL; BROWSEINFOW brInfo; LPITEMIDLIST pidlBrowse; BOOL ret = FALSE; Wstr buf_w(MAX_PATH), defaultDir_w(MAX_PATH), title_w(title); if (!SUCCEEDED(SHGetMalloc(&iMalloc))) return FALSE; U8toW(defaultDir, defaultDir_w.Buf(), MAX_PATH); brInfo.hwndOwner = parentWin->hWnd; brInfo.pidlRoot = 0; brInfo.pszDisplayName = buf_w.Buf(); brInfo.lpszTitle = title_w; brInfo.ulFlags = BIF_RETURNONLYFSDIRS; brInfo.lpfn = BrowseDirDlgProc; brInfo.lParam = (LPARAM)defaultDir_w.Buf(); brInfo.iImage = 0; if ((pidlBrowse = SHBrowseForFolderV((BROWSEINFO *)&brInfo))) { ret = SHGetPathFromIDListV(pidlBrowse, buf_w.Buf()); iMalloc->Free(pidlBrowse); if (ret) WtoU8(buf_w, buf, MAX_PATH_U8); } iMalloc->Release(); return ret; }
BOOL TRegistry::EnumKey(DWORD cnt, LPSTR buf, int size) { Wstr buf_w(size); if (!EnumKeyW(cnt, buf_w.Buf(), size)) return FALSE; WtoS(buf_w.s(), buf, size, strMode); return TRUE; }
bool parse_clientlogin_response(NETLIBHTTPREQUEST *nlhr, NETLIBHTTPHEADER *my_headers, CMStringA &token, CMStringA &secret, time_t &hosttime) { //TODO: validate response //TODO: return false on errors //TODO: extract token, secret, hosttime from response int datalen = 0; for (int i = 0; i < nlhr->headersCount; i++) { if (!mir_strcmp(nlhr->headers[i].szName, "Set-Cookie")) { my_headers[0].szName = "Cookie"; my_headers[0].szValue = mir_strdup(nlhr->headers[i].szValue); } } ptrW buf_w(mir_utf8decodeW(nlhr->pData)); HXML root = xmlParseString(buf_w, &datalen, _T("")); if (!root) return false; HXML status = xmlGetChildByPath(root, _T("response/statusCode"), 0); if (!status) return false; LPCTSTR status_text = xmlGetText(status); // TODO: check other than 200 codes and print some debug info on errors if (wcscmp(status_text, L"200")) return false; HXML secret_node = xmlGetChildByPath(root, _T("response/data/sessionSecret"), 0); HXML hosttime_node = xmlGetChildByPath(root, _T("response/data/hostTime"), 0); if (!secret_node || !hosttime_node) return false; HXML token_node = xmlGetChildByPath(root, _T("response/data/token/a"), 0); if (!token_node) return false; LPCTSTR secret_w = xmlGetText(secret_node), token_w = xmlGetText(token_node), hosttime_w = xmlGetText(hosttime_node); if (!secret_w || !token_w || !hosttime_w) return false; secret = _T2A(secret_w); token = _T2A(token_w); hosttime = strtol(_T2A(hosttime_w), NULL, 10); return true; }
bool parse_start_socar_session_response(const char *response, CMStringA &bos_host, unsigned short &bos_port, CMStringA &cookie, CMStringA &tls_cert_name, bool encryption = true) { //TODO: extract bos_host, bos_port, cookie, tls_cert_name int datalen = 0; ptrW buf_w(mir_utf8decodeW(response)); HXML root = xmlParseString(buf_w, &datalen, _T("")); if (!root) return false; HXML status = xmlGetChildByPath(root, _T("response/statusCode"), 0); if (!status) return false; LPCTSTR status_text = xmlGetText(status); //TODO: check other than 200 codes and print some debug info on errors if (wcscmp(status_text, L"200")) return false; HXML host_node = xmlGetChildByPath(root, _T("response/data/host"), 0); HXML port_node = xmlGetChildByPath(root, _T("response/data/port"), 0); HXML cookie_node = xmlGetChildByPath(root, _T("response/data/cookie"), 0); if (!host_node || !port_node || !cookie_node) return false; LPCTSTR host_w = xmlGetText(host_node), port_w = xmlGetText(port_node), cookie_w = xmlGetText(cookie_node); if (!host_w || !port_w || !cookie_w) return false; bos_host = _T2A(host_w); bos_port = atoi(_T2A(port_w)); cookie = _T2A(cookie_w); if (encryption) { HXML tls_node = xmlGetChildByPath(root, _T("response/data/tlsCertName"), 0); //tls is optional, so this is not fatal error if (tls_node) { LPCTSTR certname_w = xmlGetText(tls_node); if (certname_w) tls_cert_name = _T2A(certname_w); } } return true; }