gdi32: Always use biClrUsed for the number of colors of internal BITMAPINFO structures.
[wine/multimedia.git] / dlls / inetcomm / pop3transport.c
blobaf7d1bf91c5f60b17c24675f34662526cf7ca9e0
1 /*
2 * POP3 Transport
4 * Copyright 2008 Hans Leidekker for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #define NONAMELESSUNION
24 #include <stdarg.h>
25 #include <stdio.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winnt.h"
30 #include "winuser.h"
31 #include "objbase.h"
32 #include "mimeole.h"
33 #include "wine/debug.h"
35 #include "inetcomm_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(inetcomm);
39 enum parse_state
41 STATE_NONE,
42 STATE_OK,
43 STATE_MULTILINE,
44 STATE_DONE
47 typedef struct
49 InternetTransport InetTransport;
50 ULONG refs;
51 POP3COMMAND command;
52 POP3CMDTYPE type;
53 char *response;
54 char *ptr;
55 enum parse_state state;
56 BOOL valid_info;
57 DWORD msgid;
58 DWORD preview_lines;
59 } POP3Transport;
61 static HRESULT parse_response(POP3Transport *This)
63 switch (This->state)
65 case STATE_NONE:
66 if (strlen(This->response) < 3)
68 WARN("parse error\n");
69 This->state = STATE_DONE;
70 return S_FALSE;
72 if (!memcmp(This->response, "+OK", 3))
74 This->ptr = This->response + 3;
75 This->state = STATE_OK;
76 return S_OK;
78 This->state = STATE_DONE;
79 return S_FALSE;
81 default: return S_OK;
85 static HRESULT parse_uidl_response(POP3Transport *This, POP3UIDL *uidl)
87 char *p;
89 uidl->dwPopId = 0;
90 uidl->pszUidl = NULL;
91 switch (This->state)
93 case STATE_OK:
94 if (This->type == POP3CMD_GET_POPID)
96 if ((p = strchr(This->ptr, ' ')))
98 while (*p == ' ') p++;
99 sscanf(p, "%u", &uidl->dwPopId);
100 if ((p = strchr(p, ' ')))
102 while (*p == ' ') p++;
103 uidl->pszUidl = p;
104 This->valid_info = TRUE;
107 This->state = STATE_DONE;
108 return S_OK;
110 This->state = STATE_MULTILINE;
111 return S_OK;
113 case STATE_MULTILINE:
114 if (This->response[0] == '.' && !This->response[1])
116 This->valid_info = FALSE;
117 This->state = STATE_DONE;
118 return S_OK;
120 sscanf(This->response, "%u", &uidl->dwPopId);
121 if ((p = strchr(This->response, ' ')))
123 while (*p == ' ') p++;
124 uidl->pszUidl = p;
125 This->valid_info = TRUE;
126 return S_OK;
129 default:
130 WARN("parse error\n");
131 This->state = STATE_DONE;
132 return S_FALSE;
136 static HRESULT parse_stat_response(POP3Transport *This, POP3STAT *stat)
138 char *p;
140 stat->cMessages = 0;
141 stat->cbMessages = 0;
142 switch (This->state)
144 case STATE_OK:
145 if ((p = strchr(This->ptr, ' ')))
147 while (*p == ' ') p++;
148 sscanf(p, "%u %u", &stat->cMessages, &stat->cbMessages);
149 This->valid_info = TRUE;
150 This->state = STATE_DONE;
151 return S_OK;
154 default:
155 WARN("parse error\n");
156 This->state = STATE_DONE;
157 return S_FALSE;
161 static HRESULT parse_list_response(POP3Transport *This, POP3LIST *list)
163 char *p;
165 list->dwPopId = 0;
166 list->cbSize = 0;
167 switch (This->state)
169 case STATE_OK:
170 if (This->type == POP3CMD_GET_POPID)
172 if ((p = strchr(This->ptr, ' ')))
174 while (*p == ' ') p++;
175 sscanf(p, "%u %u", &list->dwPopId, &list->cbSize);
176 This->valid_info = TRUE;
178 This->state = STATE_DONE;
179 return S_OK;
181 This->state = STATE_MULTILINE;
182 return S_OK;
184 case STATE_MULTILINE:
185 if (This->response[0] == '.' && !This->response[1])
187 This->valid_info = FALSE;
188 This->state = STATE_DONE;
189 return S_OK;
191 sscanf(This->response, "%u", &list->dwPopId);
192 if ((p = strchr(This->response, ' ')))
194 while (*p == ' ') p++;
195 sscanf(p, "%u", &list->cbSize);
196 This->valid_info = TRUE;
197 return S_OK;
200 default:
201 WARN("parse error\n");
202 This->state = STATE_DONE;
203 return S_FALSE;
207 static HRESULT parse_dele_response(POP3Transport *This, DWORD *dwPopId)
209 switch (This->state)
211 case STATE_OK:
212 *dwPopId = 0; /* FIXME */
213 This->state = STATE_DONE;
214 return S_OK;
216 default:
217 WARN("parse error\n");
218 This->state = STATE_DONE;
219 return S_FALSE;
223 static HRESULT parse_retr_response(POP3Transport *This, POP3RETR *retr)
225 switch (This->state)
227 case STATE_OK:
228 retr->fHeader = FALSE;
229 retr->fBody = FALSE;
230 retr->dwPopId = This->msgid;
231 retr->cbSoFar = 0;
232 retr->pszLines = This->response;
233 retr->cbLines = 0;
235 This->state = STATE_MULTILINE;
236 This->valid_info = FALSE;
237 return S_OK;
239 case STATE_MULTILINE:
241 int len;
243 if (This->response[0] == '.' && !This->response[1])
245 retr->cbLines = retr->cbSoFar;
246 This->state = STATE_DONE;
247 return S_OK;
249 retr->fHeader = TRUE;
250 if (!This->response[0]) retr->fBody = TRUE;
252 len = strlen(This->response);
253 retr->cbSoFar += len;
254 retr->pszLines = This->response;
255 retr->cbLines = len;
257 This->valid_info = TRUE;
258 return S_OK;
261 default:
262 WARN("parse error\n");
263 This->state = STATE_DONE;
264 return S_FALSE;
268 static HRESULT parse_top_response(POP3Transport *This, POP3TOP *top)
270 switch (This->state)
272 case STATE_OK:
273 top->fHeader = FALSE;
274 top->fBody = FALSE;
275 top->dwPopId = This->msgid;
276 top->cPreviewLines = This->preview_lines;
277 top->cbSoFar = 0;
278 top->pszLines = This->response;
279 top->cbLines = 0;
281 This->state = STATE_MULTILINE;
282 This->valid_info = FALSE;
283 return S_OK;
285 case STATE_MULTILINE:
287 int len;
289 if (This->response[0] == '.' && !This->response[1])
291 top->cbLines = top->cbSoFar;
292 This->state = STATE_DONE;
293 return S_OK;
295 top->fHeader = TRUE;
296 if (!This->response[0]) top->fBody = TRUE;
298 len = strlen(This->response);
299 top->cbSoFar += len;
300 top->pszLines = This->response;
301 top->cbLines = len;
303 This->valid_info = TRUE;
304 return S_OK;
307 default:
308 WARN("parse error\n");
309 This->state = STATE_DONE;
310 return S_FALSE;
314 static void init_parser(POP3Transport *This, POP3COMMAND command, POP3CMDTYPE type)
316 This->state = STATE_NONE;
317 This->command = command;
318 This->type = type;
321 static HRESULT POP3Transport_ParseResponse(POP3Transport *This, char *pszResponse, POP3RESPONSE *pResponse)
323 HRESULT hr;
325 TRACE("response: %s\n", debugstr_a(pszResponse));
327 This->response = pszResponse;
328 This->valid_info = FALSE;
329 TRACE("state %u\n", This->state);
331 if (SUCCEEDED((hr = parse_response(This))))
333 switch (This->command)
335 case POP3_UIDL: hr = parse_uidl_response(This, &pResponse->u.rUidlInfo); break;
336 case POP3_STAT: hr = parse_stat_response(This, &pResponse->u.rStatInfo); break;
337 case POP3_LIST: hr = parse_list_response(This, &pResponse->u.rListInfo); break;
338 case POP3_DELE: hr = parse_dele_response(This, &pResponse->u.dwPopId); break;
339 case POP3_RETR: hr = parse_retr_response(This, &pResponse->u.rRetrInfo); break;
340 case POP3_TOP: hr = parse_top_response(This, &pResponse->u.rTopInfo); break;
341 default:
342 This->state = STATE_DONE;
343 break;
346 pResponse->command = This->command;
347 pResponse->fDone = (This->state == STATE_DONE);
348 pResponse->fValidInfo = This->valid_info;
349 pResponse->rIxpResult.hrResult = hr;
350 pResponse->rIxpResult.pszResponse = pszResponse;
351 pResponse->rIxpResult.uiServerError = 0;
352 pResponse->rIxpResult.hrServerError = pResponse->rIxpResult.hrResult;
353 pResponse->rIxpResult.dwSocketError = WSAGetLastError();
354 pResponse->rIxpResult.pszProblem = NULL;
355 pResponse->pTransport = (IPOP3Transport *)&This->InetTransport.u.vtblPOP3;
357 if (This->InetTransport.pCallback && This->InetTransport.fCommandLogging)
359 ITransportCallback_OnCommand(This->InetTransport.pCallback, CMD_RESP,
360 pResponse->rIxpResult.pszResponse, pResponse->rIxpResult.hrServerError,
361 (IInternetTransport *)&This->InetTransport.u.vtbl);
363 return S_OK;
366 static void POP3Transport_CallbackProcessDELEResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
368 POP3Transport *This = (POP3Transport *)iface;
369 POP3RESPONSE response;
370 HRESULT hr;
372 TRACE("\n");
374 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
375 if (FAILED(hr))
377 /* FIXME: handle error */
378 return;
381 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
384 static void POP3Transport_CallbackRecvDELEResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
386 POP3Transport *This = (POP3Transport *)iface;
388 TRACE("\n");
389 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessDELEResp);
392 static void POP3Transport_CallbackProcessNOOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
394 POP3Transport *This = (POP3Transport *)iface;
395 POP3RESPONSE response;
396 HRESULT hr;
398 TRACE("\n");
400 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
401 if (FAILED(hr))
403 /* FIXME: handle error */
404 return;
407 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
410 static void POP3Transport_CallbackRecvNOOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
412 POP3Transport *This = (POP3Transport *)iface;
414 TRACE("\n");
415 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessNOOPResp);
418 static void POP3Transport_CallbackProcessRSETResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
420 POP3Transport *This = (POP3Transport *)iface;
421 POP3RESPONSE response;
422 HRESULT hr;
424 TRACE("\n");
426 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
427 if (FAILED(hr))
429 /* FIXME: handle error */
430 return;
433 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
436 static void POP3Transport_CallbackRecvRSETResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
438 POP3Transport *This = (POP3Transport *)iface;
440 TRACE("\n");
441 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessRSETResp);
444 static void POP3Transport_CallbackProcessRETRResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
446 POP3Transport *This = (POP3Transport *)iface;
447 POP3RESPONSE response;
448 HRESULT hr;
450 TRACE("\n");
452 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
453 if (FAILED(hr))
455 /* FIXME: handle error */
456 return;
459 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
461 if (!response.fDone)
463 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessRETRResp);
464 return;
467 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
470 static void POP3Transport_CallbackRecvRETRResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
472 POP3Transport *This = (POP3Transport *)iface;
474 TRACE("\n");
475 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessRETRResp);
478 static void POP3Transport_CallbackProcessTOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
480 POP3Transport *This = (POP3Transport *)iface;
481 POP3RESPONSE response;
482 HRESULT hr;
484 TRACE("\n");
486 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
487 if (FAILED(hr))
489 /* FIXME: handle error */
490 return;
493 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
495 if (!response.fDone)
497 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessTOPResp);
498 return;
501 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
504 static void POP3Transport_CallbackRecvTOPResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
506 POP3Transport *This = (POP3Transport *)iface;
508 TRACE("\n");
509 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessTOPResp);
512 static void POP3Transport_CallbackProcessLISTResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
514 POP3Transport *This = (POP3Transport *)iface;
515 POP3RESPONSE response;
516 HRESULT hr;
518 TRACE("\n");
520 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
521 if (FAILED(hr))
523 /* FIXME: handle error */
524 return;
527 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
529 if (!response.fDone)
531 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessLISTResp);
532 return;
535 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
538 static void POP3Transport_CallbackRecvLISTResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
540 POP3Transport *This = (POP3Transport *)iface;
542 TRACE("\n");
543 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessLISTResp);
546 static void POP3Transport_CallbackProcessUIDLResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
548 POP3Transport *This = (POP3Transport *)iface;
549 POP3RESPONSE response;
550 HRESULT hr;
552 TRACE("\n");
554 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
555 if (FAILED(hr))
557 /* FIXME: handle error */
558 return;
561 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
563 if (!response.fDone)
565 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessUIDLResp);
566 return;
569 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
572 static void POP3Transport_CallbackRecvUIDLResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
574 POP3Transport *This = (POP3Transport *)iface;
576 TRACE("\n");
577 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessUIDLResp);
580 static void POP3Transport_CallbackProcessSTATResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
582 POP3Transport *This = (POP3Transport *)iface;
583 POP3RESPONSE response;
584 HRESULT hr;
586 TRACE("\n");
588 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
589 if (FAILED(hr))
591 /* FIXME: handle error */
592 return;
595 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
598 static void POP3Transport_CallbackRecvSTATResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
600 POP3Transport *This = (POP3Transport *)iface;
602 TRACE("\n");
603 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessSTATResp);
606 static void POP3Transport_CallbackProcessPASSResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
608 POP3Transport *This = (POP3Transport *)iface;
609 POP3RESPONSE response;
610 HRESULT hr;
612 TRACE("\n");
614 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
615 if (FAILED(hr))
617 /* FIXME: handle error */
618 return;
621 InternetTransport_ChangeStatus(&This->InetTransport, IXP_AUTHORIZED);
622 InternetTransport_ChangeStatus(&This->InetTransport, IXP_CONNECTED);
624 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
627 static void POP3Transport_CallbackRecvPASSResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
629 POP3Transport *This = (POP3Transport *)iface;
631 TRACE("\n");
632 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessPASSResp);
635 static void POP3Transport_CallbackProcessUSERResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
637 static char pass[] = "PASS ";
638 POP3Transport *This = (POP3Transport *)iface;
639 POP3RESPONSE response;
640 char *command;
641 int len;
642 HRESULT hr;
644 TRACE("\n");
646 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
647 if (FAILED(hr))
649 /* FIXME: handle error */
650 return;
653 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
655 len = sizeof(pass) + strlen(This->InetTransport.ServerInfo.szPassword) + 2; /* "\r\n" */
656 command = HeapAlloc(GetProcessHeap(), 0, len);
658 strcpy(command, pass);
659 strcat(command, This->InetTransport.ServerInfo.szPassword);
660 strcat(command, "\r\n");
662 init_parser(This, POP3_PASS, POP3_NONE);
664 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvPASSResp);
665 HeapFree(GetProcessHeap(), 0, command);
668 static void POP3Transport_CallbackRecvUSERResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
670 POP3Transport *This = (POP3Transport *)iface;
672 TRACE("\n");
673 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessUSERResp);
676 static void POP3Transport_CallbackSendUSERCmd(IInternetTransport *iface, char *pBuffer, int cbBuffer)
678 static char user[] = "USER ";
679 POP3Transport *This = (POP3Transport *)iface;
680 char *command;
681 int len;
683 TRACE("\n");
685 len = sizeof(user) + strlen(This->InetTransport.ServerInfo.szUserName) + 2; /* "\r\n" */
686 command = HeapAlloc(GetProcessHeap(), 0, len);
688 strcpy(command, user);
689 strcat(command, This->InetTransport.ServerInfo.szUserName);
690 strcat(command, "\r\n");
691 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvUSERResp);
693 HeapFree(GetProcessHeap(), 0, command);
696 static void POP3Transport_CallbackProcessQUITResponse(IInternetTransport *iface, char *pBuffer, int cbBuffer)
698 POP3Transport *This = (POP3Transport *)iface;
699 POP3RESPONSE response;
700 HRESULT hr;
702 TRACE("%s\n", debugstr_an(pBuffer, cbBuffer));
704 hr = POP3Transport_ParseResponse(This, pBuffer, &response);
705 if (FAILED(hr))
707 /* FIXME: handle error */
708 return;
711 IPOP3Callback_OnResponse((IPOP3Callback *)This->InetTransport.pCallback, &response);
712 InternetTransport_DropConnection(&This->InetTransport);
715 static void POP3Transport_CallbackRecvQUITResp(IInternetTransport *iface, char *pBuffer, int cbBuffer)
717 POP3Transport *This = (POP3Transport *)iface;
719 TRACE("\n");
720 InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackProcessQUITResponse);
723 static HRESULT WINAPI POP3Transport_QueryInterface(IPOP3Transport *iface, REFIID riid, void **ppv)
725 TRACE("(%s, %p)\n", debugstr_guid(riid), ppv);
727 if (IsEqualIID(riid, &IID_IUnknown) ||
728 IsEqualIID(riid, &IID_IInternetTransport) ||
729 IsEqualIID(riid, &IID_IPOP3Transport))
731 *ppv = iface;
732 IUnknown_AddRef(iface);
733 return S_OK;
735 *ppv = NULL;
736 FIXME("no interface for %s\n", debugstr_guid(riid));
737 return E_NOINTERFACE;
740 static ULONG WINAPI POP3Transport_AddRef(IPOP3Transport *iface)
742 POP3Transport *This = (POP3Transport *)iface;
743 return InterlockedIncrement((LONG *)&This->refs);
746 static ULONG WINAPI POP3Transport_Release(IPOP3Transport *iface)
748 POP3Transport *This = (POP3Transport *)iface;
749 ULONG refs = InterlockedDecrement((LONG *)&This->refs);
750 if (!refs)
752 TRACE("destroying %p\n", This);
753 if (This->InetTransport.Status != IXP_DISCONNECTED)
754 InternetTransport_DropConnection(&This->InetTransport);
755 if (This->InetTransport.pCallback) ITransportCallback_Release(This->InetTransport.pCallback);
756 HeapFree(GetProcessHeap(), 0, This);
758 return refs;
761 static HRESULT WINAPI POP3Transport_GetServerInfo(IPOP3Transport *iface,
762 LPINETSERVER pInetServer)
764 POP3Transport *This = (POP3Transport *)iface;
766 TRACE("(%p)\n", pInetServer);
767 return InternetTransport_GetServerInfo(&This->InetTransport, pInetServer);
770 static IXPTYPE WINAPI POP3Transport_GetIXPType(IPOP3Transport *iface)
772 TRACE("()\n");
773 return IXP_POP3;
776 static HRESULT WINAPI POP3Transport_IsState(IPOP3Transport *iface, IXPISSTATE isstate)
778 FIXME("(%u)\n", isstate);
779 return E_NOTIMPL;
782 static HRESULT WINAPI POP3Transport_InetServerFromAccount(
783 IPOP3Transport *iface, IImnAccount *pAccount, LPINETSERVER pInetServer)
785 POP3Transport *This = (POP3Transport *)iface;
787 TRACE("(%p, %p)\n", pAccount, pInetServer);
788 return InternetTransport_InetServerFromAccount(&This->InetTransport, pAccount, pInetServer);
791 static HRESULT WINAPI POP3Transport_Connect(IPOP3Transport *iface,
792 LPINETSERVER pInetServer, boolean fAuthenticate, boolean fCommandLogging)
794 POP3Transport *This = (POP3Transport *)iface;
795 HRESULT hr;
797 TRACE("(%p, %s, %s)\n", pInetServer, fAuthenticate ? "TRUE" : "FALSE", fCommandLogging ? "TRUE" : "FALSE");
799 hr = InternetTransport_Connect(&This->InetTransport, pInetServer, fAuthenticate, fCommandLogging);
800 if (FAILED(hr))
801 return hr;
803 init_parser(This, POP3_USER, POP3_NONE);
804 return InternetTransport_ReadLine(&This->InetTransport, POP3Transport_CallbackSendUSERCmd);
807 static HRESULT WINAPI POP3Transport_HandsOffCallback(IPOP3Transport *iface)
809 POP3Transport *This = (POP3Transport *)iface;
811 TRACE("()\n");
812 return InternetTransport_HandsOffCallback(&This->InetTransport);
815 static HRESULT WINAPI POP3Transport_Disconnect(IPOP3Transport *iface)
817 TRACE("()\n");
818 return IPOP3Transport_CommandQUIT(iface);
821 static HRESULT WINAPI POP3Transport_DropConnection(IPOP3Transport *iface)
823 POP3Transport *This = (POP3Transport *)iface;
825 TRACE("()\n");
826 return InternetTransport_DropConnection(&This->InetTransport);
829 static HRESULT WINAPI POP3Transport_GetStatus(IPOP3Transport *iface,
830 IXPSTATUS *pCurrentStatus)
832 POP3Transport *This = (POP3Transport *)iface;
834 TRACE("()\n");
835 return InternetTransport_GetStatus(&This->InetTransport, pCurrentStatus);
838 static HRESULT WINAPI POP3Transport_InitNew(IPOP3Transport *iface,
839 LPSTR pszLogFilePath, IPOP3Callback *pCallback)
841 POP3Transport *This = (POP3Transport *)iface;
843 TRACE("(%s, %p)\n", debugstr_a(pszLogFilePath), pCallback);
845 if (!pCallback)
846 return E_INVALIDARG;
848 if (pszLogFilePath)
849 FIXME("not using log file of %s, use Wine debug logging instead\n",
850 debugstr_a(pszLogFilePath));
852 IPOP3Callback_AddRef(pCallback);
853 This->InetTransport.pCallback = (ITransportCallback *)pCallback;
854 This->InetTransport.fInitialised = TRUE;
856 return S_OK;
859 static HRESULT WINAPI POP3Transport_MarkItem(IPOP3Transport *iface, POP3MARKTYPE marktype,
860 DWORD dwPopId, boolean fMarked)
862 FIXME("(%u, %u, %d)\n", marktype, dwPopId, fMarked);
863 return E_NOTIMPL;
866 static HRESULT WINAPI POP3Transport_CommandAUTH(IPOP3Transport *iface, LPSTR pszAuthType)
868 FIXME("(%s)\n", pszAuthType);
869 return E_NOTIMPL;
872 static HRESULT WINAPI POP3Transport_CommandUSER(IPOP3Transport *iface, LPSTR username)
874 static char user[] = "USER ";
875 POP3Transport *This = (POP3Transport *)iface;
876 char *command;
877 int len;
879 TRACE("(%s)\n", username);
881 len = sizeof(user) + strlen(username) + 2; /* "\r\n" */
882 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
884 strcpy(command, user);
885 strcat(command, username);
886 strcat(command, "\r\n");
888 init_parser(This, POP3_USER, POP3_NONE);
889 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvUSERResp);
891 HeapFree(GetProcessHeap(), 0, command);
892 return S_OK;
895 static HRESULT WINAPI POP3Transport_CommandPASS(IPOP3Transport *iface, LPSTR password)
897 static char pass[] = "PASS ";
898 POP3Transport *This = (POP3Transport *)iface;
899 char *command;
900 int len;
902 TRACE("(%p)\n", password);
904 len = sizeof(pass) + strlen(password) + 2; /* "\r\n" */
905 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
907 strcpy(command, pass);
908 strcat(command, password);
909 strcat(command, "\r\n");
911 init_parser(This, POP3_PASS, POP3_NONE);
912 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvPASSResp);
914 HeapFree(GetProcessHeap(), 0, command);
915 return S_OK;
918 static HRESULT WINAPI POP3Transport_CommandLIST(
919 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
921 static char list[] = "LIST %u\r\n";
922 static char list_all[] = "LIST\r\n";
923 POP3Transport *This = (POP3Transport *)iface;
924 char *command;
925 int len;
927 TRACE("(%u, %u)\n", cmdtype, dwPopId);
929 if (dwPopId)
931 len = sizeof(list) + 10 + 2; /* "4294967296" + "\r\n" */
932 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
933 sprintf(command, list, dwPopId);
935 else command = list_all;
937 init_parser(This, POP3_LIST, cmdtype);
938 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvLISTResp);
940 if (dwPopId) HeapFree(GetProcessHeap(), 0, command);
941 return S_OK;
944 static HRESULT WINAPI POP3Transport_CommandTOP(
945 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId, DWORD cPreviewLines)
947 static char top[] = "TOP %u %u\r\n";
948 POP3Transport *This = (POP3Transport *)iface;
949 char *command;
950 int len;
952 TRACE("(%u, %u, %u)\n", cmdtype, dwPopId, cPreviewLines);
954 len = sizeof(top) + 20 + 2; /* 2 * "4294967296" + "\r\n" */
955 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
956 sprintf(command, top, dwPopId, cPreviewLines);
958 This->preview_lines = cPreviewLines;
959 init_parser(This, POP3_TOP, cmdtype);
960 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvTOPResp);
962 HeapFree(GetProcessHeap(), 0, command);
963 return S_OK;
966 static HRESULT WINAPI POP3Transport_CommandQUIT(IPOP3Transport *iface)
968 static char command[] = "QUIT\r\n";
969 POP3Transport *This = (POP3Transport *)iface;
971 TRACE("()\n");
973 InternetTransport_ChangeStatus(&This->InetTransport, IXP_DISCONNECTING);
975 init_parser(This, POP3_QUIT, POP3_NONE);
976 return InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvQUITResp);
979 static HRESULT WINAPI POP3Transport_CommandSTAT(IPOP3Transport *iface)
981 static char stat[] = "STAT\r\n";
982 POP3Transport *This = (POP3Transport *)iface;
984 TRACE("\n");
986 init_parser(This, POP3_STAT, POP3_NONE);
987 InternetTransport_DoCommand(&This->InetTransport, stat, POP3Transport_CallbackRecvSTATResp);
988 return S_OK;
991 static HRESULT WINAPI POP3Transport_CommandNOOP(IPOP3Transport *iface)
993 static char noop[] = "NOOP\r\n";
994 POP3Transport *This = (POP3Transport *)iface;
996 TRACE("\n");
998 init_parser(This, POP3_NOOP, POP3_NONE);
999 InternetTransport_DoCommand(&This->InetTransport, noop, POP3Transport_CallbackRecvNOOPResp);
1000 return S_OK;
1003 static HRESULT WINAPI POP3Transport_CommandRSET(IPOP3Transport *iface)
1005 static char rset[] = "RSET\r\n";
1006 POP3Transport *This = (POP3Transport *)iface;
1008 TRACE("\n");
1010 init_parser(This, POP3_RSET, POP3_NONE);
1011 InternetTransport_DoCommand(&This->InetTransport, rset, POP3Transport_CallbackRecvRSETResp);
1012 return S_OK;
1015 static HRESULT WINAPI POP3Transport_CommandUIDL(
1016 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
1018 static char uidl[] = "UIDL %u\r\n";
1019 static char uidl_all[] = "UIDL\r\n";
1020 POP3Transport *This = (POP3Transport *)iface;
1021 char *command;
1022 int len;
1024 TRACE("(%u, %u)\n", cmdtype, dwPopId);
1026 if (dwPopId)
1028 len = sizeof(uidl) + 10 + 2; /* "4294967296" + "\r\n" */
1029 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
1030 sprintf(command, uidl, dwPopId);
1032 else command = uidl_all;
1034 init_parser(This, POP3_UIDL, cmdtype);
1035 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvUIDLResp);
1037 if (dwPopId) HeapFree(GetProcessHeap(), 0, command);
1038 return S_OK;
1041 static HRESULT WINAPI POP3Transport_CommandDELE(
1042 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
1044 static char dele[] = "DELE %u\r\n";
1045 POP3Transport *This = (POP3Transport *)iface;
1046 char *command;
1047 int len;
1049 TRACE("(%u, %u)\n", cmdtype, dwPopId);
1051 len = sizeof(dele) + 10 + 2; /* "4294967296" + "\r\n" */
1052 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
1053 sprintf(command, dele, dwPopId);
1055 init_parser(This, POP3_DELE, cmdtype);
1056 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvDELEResp);
1058 HeapFree(GetProcessHeap(), 0, command);
1059 return S_OK;
1062 static HRESULT WINAPI POP3Transport_CommandRETR(
1063 IPOP3Transport *iface, POP3CMDTYPE cmdtype, DWORD dwPopId)
1065 static char retr[] = "RETR %u\r\n";
1066 POP3Transport *This = (POP3Transport *)iface;
1067 char *command;
1068 int len;
1070 TRACE("(%u, %u)\n", cmdtype, dwPopId);
1072 len = sizeof(retr) + 10 + 2; /* "4294967296" + "\r\n" */
1073 if (!(command = HeapAlloc(GetProcessHeap(), 0, len))) return S_FALSE;
1074 sprintf(command, retr, dwPopId);
1076 init_parser(This, POP3_RETR, cmdtype);
1077 InternetTransport_DoCommand(&This->InetTransport, command, POP3Transport_CallbackRecvRETRResp);
1079 HeapFree(GetProcessHeap(), 0, command);
1080 return S_OK;
1083 static const IPOP3TransportVtbl POP3TransportVtbl =
1085 POP3Transport_QueryInterface,
1086 POP3Transport_AddRef,
1087 POP3Transport_Release,
1088 POP3Transport_GetServerInfo,
1089 POP3Transport_GetIXPType,
1090 POP3Transport_IsState,
1091 POP3Transport_InetServerFromAccount,
1092 POP3Transport_Connect,
1093 POP3Transport_HandsOffCallback,
1094 POP3Transport_Disconnect,
1095 POP3Transport_DropConnection,
1096 POP3Transport_GetStatus,
1097 POP3Transport_InitNew,
1098 POP3Transport_MarkItem,
1099 POP3Transport_CommandAUTH,
1100 POP3Transport_CommandUSER,
1101 POP3Transport_CommandPASS,
1102 POP3Transport_CommandLIST,
1103 POP3Transport_CommandTOP,
1104 POP3Transport_CommandQUIT,
1105 POP3Transport_CommandSTAT,
1106 POP3Transport_CommandNOOP,
1107 POP3Transport_CommandRSET,
1108 POP3Transport_CommandUIDL,
1109 POP3Transport_CommandDELE,
1110 POP3Transport_CommandRETR
1113 HRESULT WINAPI CreatePOP3Transport(IPOP3Transport **ppTransport)
1115 HRESULT hr;
1116 POP3Transport *This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
1117 if (!This)
1118 return E_OUTOFMEMORY;
1120 This->InetTransport.u.vtblPOP3 = &POP3TransportVtbl;
1121 This->refs = 0;
1122 hr = InternetTransport_Init(&This->InetTransport);
1123 if (FAILED(hr))
1125 HeapFree(GetProcessHeap(), 0, This);
1126 return hr;
1129 *ppTransport = (IPOP3Transport *)&This->InetTransport.u.vtblPOP3;
1130 IPOP3Transport_AddRef(*ppTransport);
1132 return S_OK;
1135 static HRESULT WINAPI POP3TransportCF_QueryInterface(LPCLASSFACTORY iface,
1136 REFIID riid, LPVOID *ppv)
1138 *ppv = NULL;
1139 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IClassFactory))
1141 *ppv = iface;
1142 IUnknown_AddRef(iface);
1143 return S_OK;
1145 return E_NOINTERFACE;
1148 static ULONG WINAPI POP3TransportCF_AddRef(LPCLASSFACTORY iface)
1150 return 2; /* non-heap based object */
1153 static ULONG WINAPI POP3TransportCF_Release(LPCLASSFACTORY iface)
1155 return 1; /* non-heap based object */
1158 static HRESULT WINAPI POP3TransportCF_CreateInstance(LPCLASSFACTORY iface,
1159 LPUNKNOWN pUnk, REFIID riid, LPVOID *ppv)
1161 HRESULT hr;
1162 IPOP3Transport *pPop3Transport;
1164 TRACE("(%p, %s, %p)\n", pUnk, debugstr_guid(riid), ppv);
1166 *ppv = NULL;
1168 if (pUnk)
1169 return CLASS_E_NOAGGREGATION;
1171 hr = CreatePOP3Transport(&pPop3Transport);
1172 if (FAILED(hr))
1173 return hr;
1175 hr = IPOP3Transport_QueryInterface(pPop3Transport, riid, ppv);
1176 IPOP3Transport_Release(pPop3Transport);
1178 return hr;
1181 static HRESULT WINAPI POP3TransportCF_LockServer(LPCLASSFACTORY iface, BOOL fLock)
1183 FIXME("(%d)\n",fLock);
1184 return S_OK;
1187 static const IClassFactoryVtbl POP3TransportCFVtbl =
1189 POP3TransportCF_QueryInterface,
1190 POP3TransportCF_AddRef,
1191 POP3TransportCF_Release,
1192 POP3TransportCF_CreateInstance,
1193 POP3TransportCF_LockServer
1195 static const IClassFactoryVtbl *POP3TransportCF = &POP3TransportCFVtbl;
1197 HRESULT POP3TransportCF_Create(REFIID riid, LPVOID *ppv)
1199 return IClassFactory_QueryInterface((IClassFactory *)&POP3TransportCF, riid, ppv);