00001 #include "stdafx.h"
00002 #include <atlisapi.h>
00003 #include "mplayerc.h"
00004 #include "resource.h"
00005 #include "MainFrm.h"
00006 #include "..\..\subtitles\TextFile.h"
00007 #include ".\webserver.h"
00008 #include ".\webclientsocket.h"
00009
00010 CWebClientSocket::CWebClientSocket(CWebServer* pWebServer, CMainFrame* pMainFrame)
00011 : m_pWebServer(pWebServer)
00012 , m_pMainFrame(pMainFrame)
00013 {
00014 }
00015
00016 CWebClientSocket::~CWebClientSocket()
00017 {
00018 }
00019
00020 bool CWebClientSocket::SetCookie(CString name, CString value, __time64_t expire, CString path, CString domain)
00021 {
00022 if(name.IsEmpty()) return(false);
00023 if(value.IsEmpty()) {m_cookie.RemoveKey(name); return true;}
00024
00025 m_cookie[name] = value;
00026
00027 m_cookieattribs[name].path = path;
00028 m_cookieattribs[name].domain = domain;
00029
00030 if(expire >= 0)
00031 {
00032 CTime t(expire);
00033 SYSTEMTIME st;
00034 t.GetAsSystemTime(st);
00035 CStringA str;
00036 SystemTimeToHttpDate(st, str);
00037 m_cookieattribs[name].expire = str;
00038 }
00039
00040 return true;
00041 }
00042
00043 void CWebClientSocket::Clear()
00044 {
00045 m_hdr.Empty();
00046 m_hdrlines.RemoveAll();
00047 m_data.Empty();
00048
00049 m_cmd.Empty();
00050 m_path.Empty();
00051 m_ver.Empty();
00052 m_get.RemoveAll();
00053 m_post.RemoveAll();
00054 m_cookie.RemoveAll();
00055 m_request.RemoveAll();
00056 }
00057
00058 void CWebClientSocket::Header()
00059 {
00060 if(m_cmd.IsEmpty())
00061 {
00062 if(m_hdr.IsEmpty()) return;
00063
00064 CList<CString> lines;
00065 Explode(m_hdr, lines, '\n');
00066 CString str = lines.RemoveHead();
00067
00068 CList<CString> sl;
00069 ExplodeMin(str, sl, ' ', 3);
00070 m_cmd = sl.RemoveHead().MakeUpper();
00071 m_path = sl.RemoveHead();
00072 m_ver = sl.RemoveHead().MakeUpper();
00073 ASSERT(sl.GetCount() == 0);
00074
00075 POSITION pos = lines.GetHeadPosition();
00076 while(pos)
00077 {
00078 Explode(lines.GetNext(pos), sl, ':', 2);
00079 if(sl.GetCount() == 2)
00080 m_hdrlines[sl.GetHead().MakeLower()] = sl.GetTail();
00081 }
00082 }
00083
00084
00085
00086 POSITION pos = m_hdrlines.GetStartPosition();
00087 while(pos)
00088 {
00089 CString key, value;
00090 m_hdrlines.GetNextAssoc(pos, key, value);
00091
00092 if(key == _T("cookie"))
00093 {
00094 CList<CString> sl;
00095 Explode(value, sl, ';');
00096 POSITION pos2 = sl.GetHeadPosition();
00097 while(pos2)
00098 {
00099 CList<CString> sl2;
00100 Explode(sl.GetNext(pos2), sl2, '=', 2);
00101 m_cookie[sl2.GetHead()] = sl2.GetCount() == 2 ? sl2.GetTail() : _T("");
00102 }
00103 }
00104 }
00105
00106
00107
00108 if(!m_cookie.Lookup(_T("MPCSESSIONID"), m_sessid))
00109 {
00110 srand((unsigned int)time(NULL));
00111 m_sessid.Format(_T("%08x"), rand()*0x12345678);
00112 SetCookie(_T("MPCSESSIONID"), m_sessid);
00113 }
00114 else
00115 {
00116
00117 }
00118
00119 CStringA reshdr, resbody;
00120
00121 if(m_cmd == _T("POST"))
00122 {
00123 CString str;
00124 if(m_hdrlines.Lookup(_T("content-length"), str))
00125 {
00126 int len = _tcstol(str, NULL, 10);
00127 str.Empty();
00128
00129 int err;
00130 char c;
00131
00132 int timeout = 1000;
00133
00134 do
00135 {
00136 for(; len > 0 && (err = Receive(&c, 1)) > 0; len--)
00137 {
00138 m_data += c;
00139 if(c == '\r') continue;
00140 str += c;
00141 if(c == '\n' || len == 1)
00142 {
00143 CList<CString> sl;
00144 Explode(AToT(UrlDecode(TToA(str))), sl, '&');
00145 POSITION pos = sl.GetHeadPosition();
00146 while(pos)
00147 {
00148 CList<CString> sl2;
00149 Explode(sl.GetNext(pos), sl2, '=', 2);
00150 m_post[sl2.GetHead().MakeLower()] = sl2.GetCount() == 2 ? sl2.GetTail() : _T("");
00151 }
00152 str.Empty();
00153 }
00154 }
00155
00156 if(err == SOCKET_ERROR)
00157 Sleep(1);
00158 }
00159 while(err == SOCKET_ERROR && GetLastError() == WSAEWOULDBLOCK
00160 && timeout-- > 0);
00161
00162
00163 Receive(&c, 1);
00164 Receive(&c, 1);
00165 }
00166 }
00167
00168 if(m_cmd == _T("GET") || m_cmd == _T("HEAD") || m_cmd == _T("POST"))
00169 {
00170 CList<CString> sl;
00171
00172 Explode(m_path, sl, '?', 2);
00173 m_path = sl.RemoveHead();
00174 m_query.Empty();
00175
00176 if(!sl.IsEmpty())
00177 {
00178 m_query = sl.GetTail();
00179
00180 Explode(Explode(m_query, sl, '#', 2), sl, '&');
00181
00182 POSITION pos = sl.GetHeadPosition();
00183 while(pos)
00184 {
00185 CList<CString> sl2;
00186 Explode(AToT(UrlDecode(TToA(sl.GetNext(pos)))), sl2, '=', 2);
00187
00188 m_get[sl2.GetHead()] = sl2.GetCount() == 2 ? sl2.GetTail() : _T("");
00189 }
00190 }
00191
00192
00193 {
00194 CString key, value;
00195 POSITION pos;
00196 pos = m_get.GetStartPosition();
00197 while(pos) {m_get.GetNextAssoc(pos, key, value); m_request[key] = value;}
00198 pos = m_post.GetStartPosition();
00199 while(pos) {m_post.GetNextAssoc(pos, key, value); m_request[key] = value;}
00200 pos = m_cookie.GetStartPosition();
00201 while(pos) {m_cookie.GetNextAssoc(pos, key, value); m_request[key] = value;}
00202 }
00203
00204 m_pWebServer->OnRequest(this, reshdr, resbody);
00205 }
00206 else
00207 {
00208 reshdr = "HTTP/1.0 400 Bad Request\r\n";
00209 }
00210
00211 if(!reshdr.IsEmpty())
00212 {
00213
00214 {
00215 POSITION pos = m_cookie.GetStartPosition();
00216 while(pos)
00217 {
00218 CString key, value;
00219 m_cookie.GetNextAssoc(pos, key, value);
00220 reshdr += "Set-Cookie: " + key + "=" + value;
00221 POSITION pos2 = m_cookieattribs.GetStartPosition();
00222 while(pos2)
00223 {
00224 CString key;
00225 cookie_attribs value;
00226 m_cookieattribs.GetNextAssoc(pos2, key, value);
00227 if(!value.path.IsEmpty()) reshdr += " path=" + value.path;
00228 if(!value.expire.IsEmpty()) reshdr += " expire=" + value.expire;
00229 if(!value.domain.IsEmpty()) reshdr += " domain=" + value.domain;
00230 }
00231 reshdr += "\r\n";
00232 }
00233 }
00234
00235 reshdr +=
00236 "Server: MPC WebServer\r\n"
00237 "Connection: close\r\n"
00238 "\r\n";
00239
00240 Send(reshdr, reshdr.GetLength());
00241
00242 if(m_cmd != _T("HEAD") && reshdr.Find("HTTP/1.0 200 OK") == 0 && !resbody.IsEmpty())
00243 {
00244 Send(resbody, resbody.GetLength());
00245 }
00246
00247 CString connection = _T("close");
00248 m_hdrlines.Lookup(_T("connection"), connection);
00249
00250 Clear();
00251
00252
00253
00254 OnClose(0);
00255 }
00256 }
00257
00258
00259
00260 void CWebClientSocket::OnReceive(int nErrorCode)
00261 {
00262 if(nErrorCode == 0)
00263 {
00264 char c;
00265 while(Receive(&c, 1) > 0)
00266 {
00267 if(c == '\r') continue;
00268 else m_hdr += c;
00269
00270 int len = m_hdr.GetLength();
00271 if(len >= 2 && m_hdr[len-2] == '\n' && m_hdr[len-1] == '\n')
00272 {
00273 Header();
00274 return;
00275 }
00276 }
00277 }
00278
00279 __super::OnReceive(nErrorCode);
00280 }
00281
00282 void CWebClientSocket::OnClose(int nErrorCode)
00283 {
00284
00285 m_pWebServer->OnClose(this);
00286 __super::OnClose(nErrorCode);
00287 }
00288
00290
00291 bool CWebClientSocket::OnCommand(CStringA& hdr, CStringA& body, CStringA& mime)
00292 {
00293 CString arg;
00294 if(m_request.Lookup(_T("wm_command"), arg))
00295 {
00296 int id = _ttol(arg);
00297
00298 if(id > 0)
00299 {
00300 if(id == ID_FILE_EXIT) m_pMainFrame->PostMessage(WM_COMMAND, id);
00301 else m_pMainFrame->SendMessage(WM_COMMAND, id);
00302 }
00303 else
00304 {
00305 if(arg == CMD_SETPOS && m_request.Lookup(_T("position"), arg))
00306 {
00307 int h, m, s, ms = 0;
00308 TCHAR c;
00309 if(_stscanf(arg, _T("%d%c%d%c%d%c%d"), &h, &c, &m, &c, &s, &c, &ms) >= 5)
00310 {
00311 REFERENCE_TIME rtPos = 10000i64*(((h*60+m)*60+s)*1000+ms);
00312 m_pMainFrame->SeekTo(rtPos);
00313 for(int retries = 20; retries-- > 0; Sleep(50))
00314 {
00315 if(abs((int)((rtPos - m_pMainFrame->GetPos())/10000)) < 100)
00316 break;
00317 }
00318 }
00319 }
00320 else if(arg == CMD_SETPOS && m_request.Lookup(_T("percent"), arg))
00321 {
00322 float percent = 0;
00323 if(_stscanf(arg, _T("%f"), &percent) == 1)
00324 m_pMainFrame->SeekTo((REFERENCE_TIME)(percent / 100 * m_pMainFrame->GetDur()));
00325 }
00326 else if(arg == CMD_SETVOLUME && m_request.Lookup(_T("volume"), arg))
00327 {
00328 int volume = _tcstol(arg, NULL, 10);
00329 m_pMainFrame->m_wndToolBar.Volume = min(max(volume, 1), 100);
00330 m_pMainFrame->OnPlayVolume(0);
00331 }
00332 }
00333 }
00334
00335 CString ref;
00336 if(!m_hdrlines.Lookup(_T("referer"), ref))
00337 return true;
00338
00339 hdr =
00340 "HTTP/1.0 302 Found\r\n"
00341 "Location: " + CStringA(ref) + "\r\n";
00342
00343 return true;
00344 }
00345
00346 bool CWebClientSocket::OnIndex(CStringA& hdr, CStringA& body, CStringA& mime)
00347 {
00348 CStringA wmcoptions;
00349
00350
00351
00352 AppSettings& s = AfxGetAppSettings();
00353 POSITION pos = s.wmcmds.GetHeadPosition();
00354 while(pos)
00355 {
00356 wmcmd& wc = s.wmcmds.GetNext(pos);
00357 CStringA str;
00358 str.Format("%d", wc.cmd);
00359 wmcoptions += "<option value=\"" + str + "\">"
00360 + CStringA(wc.name) + "\r\n";
00361 }
00362
00363 m_pWebServer->LoadPage(IDR_HTML_INDEX, body, m_path);
00364 body.Replace("[wmcoptions]", wmcoptions);
00365
00366 return true;
00367 }
00368
00369 bool CWebClientSocket::OnBrowser(CStringA& hdr, CStringA& body, CStringA& mime)
00370 {
00371 CList<CStringA> rootdrives;
00372 for(TCHAR drive[] = _T("A:"); drive[0] <= 'Z'; drive[0]++)
00373 if(GetDriveType(drive) != DRIVE_NO_ROOT_DIR)
00374 rootdrives.AddTail(CStringA(drive) + '\\');
00375
00376
00377
00378 CString path;
00379 CFileStatus fs;
00380 if(m_get.Lookup(_T("path"), path))
00381 {
00382 path = WToT(UTF8To16(TToA(path)));
00383
00384 if(CFileGetStatus(path, fs) && !(fs.m_attribute&CFile::directory))
00385 {
00386
00387
00388 CList<CString> cmdln;
00389
00390 cmdln.AddTail(path);
00391
00392 CString focus;
00393 if(m_get.Lookup(_T("focus"), focus) && !focus.CompareNoCase(_T("no")))
00394 cmdln.AddTail(_T("/nofocus"));
00395
00396 int len = 0;
00397
00398 POSITION pos = cmdln.GetHeadPosition();
00399 while(pos)
00400 {
00401 CString& str = cmdln.GetNext(pos);
00402 len += (str.GetLength()+1)*sizeof(TCHAR);
00403 }
00404
00405 CAutoVectorPtr<BYTE> buff;
00406 if(buff.Allocate(4+len))
00407 {
00408 BYTE* p = buff;
00409 *(DWORD*)p = cmdln.GetCount();
00410 p += sizeof(DWORD);
00411
00412 POSITION pos = cmdln.GetHeadPosition();
00413 while(pos)
00414 {
00415 CString& str = cmdln.GetNext(pos);
00416 len = (str.GetLength()+1)*sizeof(TCHAR);
00417 memcpy(p, (LPCTSTR)str, len);
00418 p += len;
00419 }
00420
00421 COPYDATASTRUCT cds;
00422 cds.dwData = 0x6ABE51;
00423 cds.cbData = p - buff;
00424 cds.lpData = (void*)(BYTE*)buff;
00425 m_pMainFrame->SendMessage(WM_COPYDATA, (WPARAM)NULL, (LPARAM)&cds);
00426 }
00427
00428 CPath p(path);
00429 p.RemoveFileSpec();
00430 path = (LPCTSTR)p;
00431 }
00432 }
00433 else
00434 {
00435 path = m_pMainFrame->m_wndPlaylistBar.GetCur();
00436
00437 if(CFileGetStatus(path, fs) && !(fs.m_attribute&CFile::directory))
00438 {
00439 CPath p(path);
00440 p.RemoveFileSpec();
00441 path = (LPCTSTR)p;
00442 }
00443 }
00444
00445 if(path.Find(_T("://")) >= 0)
00446 path.Empty();
00447
00448 if(CFileGetStatus(path, fs) && (fs.m_attribute&CFile::directory)
00449 || path.Find(_T("\\")) == 0)
00450 {
00451 CPath p(path);
00452 p.Canonicalize();
00453 p.MakePretty();
00454 p.AddBackslash();
00455 path = (LPCTSTR)p;
00456 }
00457
00458 CStringA files;
00459
00460 if(path.IsEmpty())
00461 {
00462 POSITION pos = rootdrives.GetHeadPosition();
00463 while(pos)
00464 {
00465 CStringA& drive = rootdrives.GetNext(pos);
00466
00467 files += "<tr>\r\n";
00468 files +=
00469 "<td><a href=\"[path]?path=" + UrlEncode(drive) + "\">" + drive + "</a></td>"
00470 "<td>Directory</td>"
00471 "<td> </td>\r\n"
00472 "<td> </td>";
00473 files += "</tr>\r\n";
00474 }
00475
00476 path = "Root";
00477 }
00478 else
00479 {
00480 CString parent;
00481
00482 if(path.GetLength() > 3)
00483 {
00484 CPath p(path + "..");
00485 p.Canonicalize();
00486 p.AddBackslash();
00487 parent = (LPCTSTR)p;
00488 }
00489
00490 files += "<tr>\r\n";
00491 files +=
00492 "<td><a href=\"[path]?path=" + parent + "\">..</a></td>"
00493 "<td>Directory</td>"
00494 "<td> </td>\r\n"
00495 "<td> </td>";
00496 files += "</tr>\r\n";
00497
00498 WIN32_FIND_DATA fd = {0};
00499
00500 HANDLE hFind = FindFirstFile(path + "*.*", &fd);
00501 if(hFind != INVALID_HANDLE_VALUE)
00502 {
00503 do
00504 {
00505 if(!(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY) || fd.cFileName[0] == '.')
00506 continue;
00507
00508 CString fullpath = path + fd.cFileName;
00509
00510 files += "<tr>\r\n";
00511 files +=
00512 "<td><a href=\"[path]?path=" + UTF8Arg(fullpath) + "\">" + UTF8(fd.cFileName) + "</a></td>"
00513 "<td>Directory</td>"
00514 "<td> </td>\r\n"
00515 "<td><nobr>" + CStringA(CTime(fd.ftLastWriteTime).Format(_T("%Y.%m.%d %H:%M"))) + "</nobr></td>";
00516 files += "</tr>\r\n";
00517 }
00518 while(FindNextFile(hFind, &fd));
00519
00520 FindClose(hFind);
00521 }
00522
00523 hFind = FindFirstFile(path + "*.*", &fd);
00524 if(hFind != INVALID_HANDLE_VALUE)
00525 {
00526 do
00527 {
00528 if(fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
00529 continue;
00530
00531 CString fullpath = path + fd.cFileName;
00532
00533 CStringA size;
00534 size.Format("%I64dK", ((UINT64)fd.nFileSizeHigh<<22)|(fd.nFileSizeLow>>10));
00535
00536 CString type(_T(" "));
00537 LoadType(fullpath, type);
00538
00539 files += "<tr>\r\n";
00540 files +=
00541 "<td><a href=\"[path]?path=" + UTF8Arg(fullpath) + "\">" + UTF8(fd.cFileName) + "</a></td>"
00542 "<td><nobr>" + UTF8(type) + "</nobr></td>"
00543 "<td align=\"right\"><nobr>" + size + "</nobr></td>\r\n"
00544 "<td><nobr>" + CStringA(CTime(fd.ftLastWriteTime).Format(_T("%Y.%m.%d %H:%M"))) + "</nobr></td>";
00545 files += "</tr>\r\n";
00546 }
00547 while(FindNextFile(hFind, &fd));
00548
00549 FindClose(hFind);
00550 }
00551 }
00552
00553 m_pWebServer->LoadPage(IDR_HTML_BROWSER, body, m_path);
00554 body.Replace("[charset]", "UTF-8");
00555 body.Replace("[currentdir]", UTF8(path));
00556 body.Replace("[currentfiles]", files);
00557
00558 return true;
00559 }
00560
00561 bool CWebClientSocket::OnControls(CStringA& hdr, CStringA& body, CStringA& mime)
00562 {
00563 CString path = m_pMainFrame->m_wndPlaylistBar.GetCur();
00564 CString dir;
00565
00566 if(!path.IsEmpty())
00567 {
00568 CPath p(path);
00569 p.RemoveFileSpec();
00570 dir = (LPCTSTR)p;
00571 }
00572
00573 OAFilterState fs = m_pMainFrame->GetMediaState();
00574 CString state;
00575 state.Format(_T("%d"), fs);
00576 CString statestring;
00577 switch(fs)
00578 {
00579 case State_Stopped: statestring = _T("Stopped"); break;
00580 case State_Paused: statestring = _T("Paused"); break;
00581 case State_Running: statestring = _T("Playing"); break;
00582 default: statestring = _T("n/a"); break;
00583 }
00584
00585 int pos = (int)(m_pMainFrame->GetPos()/10000);
00586 int dur = (int)(m_pMainFrame->GetDur()/10000);
00587
00588 CString position, duration;
00589 position.Format(_T("%d"), pos);
00590 duration.Format(_T("%d"), dur);
00591
00592 CString positionstring, durationstring, playbackrate;
00593
00594
00595 positionstring.Format(_T("%02d:%02d:%02d"), (pos/3600000), (pos/60000)%60, (pos/1000)%60);
00596 durationstring.Format(_T("%02d:%02d:%02d"), (dur/3600000), (dur/60000)%60, (dur/1000)%60);
00597 playbackrate = _T("1");
00598
00599 CString volumelevel, muted;
00600 volumelevel.Format(_T("%d"), m_pMainFrame->m_wndToolBar.m_volctrl.GetPos());
00601 muted.Format(_T("%d"), m_pMainFrame->m_wndToolBar.Volume == -10000 ? 1 : 0);
00602
00603 CString reloadtime(_T("0"));
00604
00605 m_pWebServer->LoadPage(IDR_HTML_CONTROLS, body, m_path);
00606 body.Replace("[charset]", "UTF-8");
00607 body.Replace("[filepatharg]", UTF8Arg(path));
00608 body.Replace("[filepath]", UTF8(path));
00609 body.Replace("[filedirarg]", UTF8Arg(dir));
00610 body.Replace("[filedir]", UTF8(dir));
00611 body.Replace("[state]", UTF8(state));
00612 body.Replace("[statestring]", UTF8(statestring));
00613 body.Replace("[position]", UTF8(position));
00614 body.Replace("[positionstring]", UTF8(positionstring));
00615 body.Replace("[duration]", UTF8(duration));
00616 body.Replace("[durationstring]", UTF8(durationstring));
00617 body.Replace("[volumelevel]", UTF8(volumelevel));
00618 body.Replace("[muted]", UTF8(muted));
00619 body.Replace("[playbackrate]", UTF8(playbackrate));
00620 body.Replace("[reloadtime]", UTF8(reloadtime));
00621
00622 return true;
00623 }
00624
00625 bool CWebClientSocket::OnStatus(CStringA& hdr, CStringA& body, CStringA& mime)
00626 {
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639 CString title;
00640 m_pMainFrame->GetWindowText(title);
00641
00642 CString status = m_pMainFrame->GetStatusMessage();
00643
00644 int pos = (int)(m_pMainFrame->GetPos()/10000);
00645 int dur = (int)(m_pMainFrame->GetDur()/10000);
00646
00647 CString posstr, durstr;
00648 posstr.Format(_T("%02d:%02d:%02d"), (pos/3600000), (pos/60000)%60, (pos/1000)%60);
00649 durstr.Format(_T("%02d:%02d:%02d"), (dur/3600000), (dur/60000)%60, (dur/1000)%60);
00650
00651 title.Replace(_T("'"), _T("\\'"));
00652 status.Replace(_T("'"), _T("\\'"));
00653
00654 body.Format("OnStatus('%s', '%s', %d, '%s', %d, '%s', %d, %d)",
00655 UTF8(title), UTF8(status),
00656 pos, UTF8(posstr), dur, UTF8(durstr),
00657 m_pMainFrame->IsMuted(), m_pMainFrame->GetVolume()
00658 );
00659
00660 return true;
00661 }
00662
00663 bool CWebClientSocket::OnError404(CStringA& hdr, CStringA& body, CStringA& mime)
00664 {
00665 m_pWebServer->LoadPage(IDR_HTML_404, body, m_path);
00666 return true;
00667 }
00668
00669 bool CWebClientSocket::OnPlayer(CStringA& hdr, CStringA& body, CStringA& mime)
00670 {
00671 m_pWebServer->LoadPage(IDR_HTML_PLAYER, body, m_path);
00672 return true;
00673 }
00674
00675 #include "jpeg.h"
00676
00677 bool CWebClientSocket::OnSnapShotJpeg(CStringA& hdr, CStringA& body, CStringA& mime)
00678 {
00679
00680
00681 bool fRet = false;
00682
00683 BYTE* pData = NULL;
00684 long size = 0;
00685 CArray<BYTE> jpeg;
00686 if(m_pMainFrame->GetDIB(&pData, size, true))
00687 {
00688 if(CJpegEncoderMem().Encode(pData, jpeg))
00689 {
00690 hdr +=
00691 "Expires: Thu, 19 Nov 1981 08:52:00 GMT\r\n"
00692 "Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0\r\n"
00693 "Pragma: no-cache\r\n";
00694 body = CStringA((char*)jpeg.GetData(), jpeg.GetSize());
00695 mime = "image/jpeg";
00696 fRet = true;
00697 }
00698
00699 delete [] pData;
00700 }
00701
00702 return fRet;
00703 }
00704
00705 #include "ConvertDlg.h"
00706
00707 bool CWebClientSocket::OnConvRes(CStringA& hdr, CStringA& body, CStringA& mime)
00708 {
00709 CString id;
00710 if(!m_get.Lookup(_T("id"), id))
00711 return false;
00712
00713 DWORD key = 0;
00714 if(1 != _stscanf(id, _T("%x"), &key) || key == 0)
00715 return false;
00716
00717 CAutoLock cAutoLock(&CDSMResource::m_csResources);
00718
00719 CDSMResource* res = NULL;
00720 if(!CDSMResource::m_resources.Lookup(key, res) || !res)
00721 return false;
00722
00723 body = CStringA((const char*)res->data.GetData(), res->data.GetSize());
00724 mime = CString(res->mime);
00725
00726 return true;
00727 }