Debian Codegraph @

Contrib/NSISdl/httpget.h

raw
1 /*
2 ** JNetLib
3 ** Copyright (C) 2000-2001 Nullsoft, Inc.
4 ** Author: Justin Frankel
5 ** File: httpget.h - JNL interface for doing HTTP GETs.
6 ** License: see License.txt
7 **
8 ** Usage:
9 ** 1. Create a JNL_HTTPGet object, optionally specifying a JNL_AsyncDNS
10 ** object to use (or NULL for none, or JNL_CONNECTION_AUTODNS for auto),
11 ** and the receive buffer size, and a string specifying proxy (or NULL
12 ** for none). See note on proxy string below.
13 ** 2. call addheader() to add whatever headers you want. It is recommended to
14 ** add at least the following two:
15 ** addheader("User-Agent:MyApp (Mozilla)");
16 */// addheader("Accept:*/*");
17 /* ( the comment weirdness is there so I Can do the star-slash :)
18 ** 3. Call connect() with the URL you wish to GET (see URL string note below)
19 ** 4. Call run() once in a while, checking to see if it returns -1
20 ** (if it does return -1, call geterrorstr() to see what the error is).
21 ** (if it returns 1, no big deal, the connection has closed).
22 ** 5. While you're at it, you can call bytes_available() to see if any data
23 ** from the http stream is available, or getheader() to see if any headers
24 ** are available, or getreply() to see the HTTP reply, or getallheaders()
25 ** to get a double null terminated, null delimited list of headers returned.
26 ** 6. If you want to read from the stream, call get_bytes (which returns how much
27 ** was actually read).
28 ** 7. content_length() is a helper function that uses getheader() to check the
29 ** content-length header.
30 ** 8. Delete ye' ol' object when done.
31 **
32 ** Proxy String:
33 ** should be in the format of host:port, or user@host:port, or
34 ** user:password@host:port. if port is not specified, 80 is assumed.
35 ** URL String:
36 ** should be in the format of http://user:pass@host:port/requestwhatever
37 ** note that user, pass, port, and /requestwhatever are all optional :)
38 ** note that also, http:// is really not important. if you do poo://
39 ** or even leave out the http:// altogether, it will still work.
40 **
41 ** Reviewed for Unicode support by Jim Park -- 08/24/2004
42 ** Everything remains ANSI. Made sure all TCHAR style functions were
43 ** changed to strictly ANSI.
44 **
45 ** Notes:
46 ** We used to have a fork of JNetLib in MakeNSISw that was slightly different,
47 ** you can see it @ http://sf.net/p/nsis/code/6603/tree/NSIS/trunk/Contrib/Makensisw/jnetlib/
48 */
49
50 #ifndef _HTTPGET_H_
51 #define _HTTPGET_H_
52
53 #include "connection.h"
54
55 class JNL_HTTPGet
56 {
57 public:
58 JNL_HTTPGet(JNL_AsyncDNS *dns=JNL_CONNECTION_AUTODNS, int recvbufsize=16384, char *proxy=NULL);
59 ~JNL_HTTPGet();
60
61 void addheader(const char *header);
62
63 void connect(const char *url);
64
65 int run(); // returns: 0 if all is OK. -1 if error (call geterrorstr()). 1 if connection closed.
66
67 int get_status(); // returns 0 if connecting, 1 if reading headers,
68 // 2 if reading content, -1 if error.
69
70 const char *getallheaders(); // double null terminated, null delimited list
71 const char *getheader(const char *headername);
72 char *getreply() { return m_reply; }
73 int getreplycode(); // returns 0 if none yet, otherwise returns http reply code.
74
75 const char *geterrorstr() { return m_errstr;}
76
77 int bytes_available();
78 int get_bytes(char *buf, int len);
79 int peek_bytes(char *buf, int len);
80
81 __int64 content_length();
82
83 JNL_Connection *get_con() { return m_con; }
84
85 public:
86 void reinit();
87 void deinit();
88 void seterrstr(const CHAR *str) { if (m_errstr) free(m_errstr); m_errstr=(char*)malloc(strlen(str)+1); strcpy(m_errstr,str); }
89
90 void do_parse_url(char *url, char **host, int *port, char **req, char **lp);
91 void do_encode_mimestr(char *in, char *out);
92
93 JNL_AsyncDNS *m_dns;
94 JNL_Connection *m_con;
95 int m_recvbufsize;
96
97 int m_http_state;
98
99 int m_http_port;
100 char *m_http_url;
101 char *m_http_host;
102 char *m_http_lpinfo;
103 char *m_http_request;
104
105 char *m_http_proxylpinfo;
106 char *m_http_proxyhost;
107 int m_http_proxyport;
108
109 char *m_sendheaders;
110 char *m_recvheaders;
111 int m_recvheaders_size;
112 char *m_reply;
113
114 char *m_errstr;
115 };
116
117 #endif // _HTTPGET_H_