GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ hide ]

public
Description: a tiny graphical app kit for ruby
Homepage: http://code.whytheluckystiff.net/shoes
Clone URL: git://github.com/why/shoes.git
 * shoes/http/winhttp.c: various compiler errors and bugs in the header 
 parsing and error handling.
why (author)
Tue Jul 22 09:51:14 -0700 2008
commit  8480109d1e4fa9fc7ac3ff17d2cf37c2f4c63f6c
tree    4b6f88ae6fa6567f13c25daebbf533737852f2ea
parent  4dde9749e3ac7b5f4ce10214cf912416501947d5
...
66
67
68
69
 
70
71
72
 
73
74
75
...
83
84
85
86
 
87
88
89
...
124
125
126
 
 
127
128
129
130
131
132
133
 
134
135
136
...
149
150
151
152
 
153
154
155
156
157
 
 
158
159
 
 
 
 
 
 
 
 
160
161
162
...
170
171
172
 
 
 
 
 
173
...
66
67
68
 
69
70
71
 
72
73
74
75
...
83
84
85
 
86
87
88
89
...
124
125
126
127
128
129
130
131
132
133
134
 
135
136
137
138
...
151
152
153
 
154
155
156
157
158
 
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
...
181
182
183
184
185
186
187
188
189
0
@@ -66,10 +66,10 @@ shoes_winhttp_headers(HINTERNET req, shoes_download_handler handler, void *data)
0
     CHAR hdr[MAX_PATH];
0
     LPCWSTR hdrs = new WCHAR[size/sizeof(WCHAR)], whdr;
0
     BOOL res = WinHttpQueryHeaders(req, WINHTTP_QUERY_RAW_HEADERS,
0
- WINHTTP_HEADER_NAME_BY_INDEX, hdrs, &size, WINHTTP_NO_HEADER_INDEX);
0
+ WINHTTP_HEADER_NAME_BY_INDEX, (LPVOID)hdrs, &size, WINHTTP_NO_HEADER_INDEX);
0
     if (!res) return;
0
 
0
- for (whdr = hdrs; whdr < hdrs + size; whdr += whdrlen)
0
+ for (whdr = hdrs; whdr - hdrs < size / sizeof(WCHAR); whdr += whdrlen)
0
     {
0
       WideCharToMultiByte(CP_UTF8, 0, whdr, -1, hdr, MAX_PATH, NULL, NULL);
0
       hdrlen = strlen(hdr);
0
@@ -83,7 +83,7 @@ void
0
 shoes_winhttp(LPCWSTR host, INTERNET_PORT port, LPCWSTR path, TCHAR *mem, HANDLE file,
0
   LPDWORD size, shoes_download_handler handler, void *data)
0
 {
0
- DWORD len = 0, rlen = 0, status = 0;
0
+ DWORD len = 0, rlen = 0, status = 0, complete = 0;
0
   TCHAR buf[SHOES_BUFSIZE];
0
   WCHAR uagent[SHOES_BUFSIZE];
0
   HINTERNET sess = NULL, conn = NULL, req = NULL;
0
@@ -124,13 +124,15 @@ shoes_winhttp(LPCWSTR host, INTERNET_PORT port, LPCWSTR path, TCHAR *mem, HANDLE
0
     if (handler != NULL) handler(&event, data);
0
   }
0
 
0
+ shoes_winhttp_headers(req, handler, data);
0
+
0
   len = sizeof(buf);
0
   if (!WinHttpQueryHeaders(req, WINHTTP_QUERY_CONTENT_LENGTH,
0
     NULL, buf, &len, NULL))
0
     goto done;
0
 
0
   *size = _wtoi((wchar_t *)buf);
0
- HTTP_EVENT(handler, SHOES_HTTP_CONNECTED, last, 0, 0, *size, data, goto done);
0
+ HTTP_EVENT(handler, SHOES_HTTP_CONNECTED, last, 0, 0, *size, data, NULL, goto done);
0
 
0
   if (mem != NULL)
0
   {
0
@@ -149,14 +151,23 @@ shoes_winhttp(LPCWSTR host, INTERNET_PORT port, LPCWSTR path, TCHAR *mem, HANDLE
0
       WriteFile(file, (LPBYTE)fbuf, len, &flen, NULL);
0
 
0
       HTTP_EVENT(handler, SHOES_HTTP_TRANSFER, last, (int)((total - (rlen * 100)) / *size),
0
- *size - rlen, *size, data, break);
0
+ *size - rlen, *size, data, NULL, break);
0
       rlen -= len;
0
     }
0
   }
0
 
0
- HTTP_EVENT(handler, SHOES_HTTP_COMPLETED, last, 100, *size, *size, data, goto done);
0
+ HTTP_EVENT(handler, SHOES_HTTP_COMPLETED, last, 100, *size, *size, data, mem, goto done);
0
+ complete = 1;
0
 
0
 done:
0
+ if (!complete)
0
+ {
0
+ shoes_download_event event;
0
+ event.stage = SHOES_HTTP_ERROR;
0
+ event.error = GetLastError();
0
+ if (handler != NULL) handler(&event, data);
0
+ }
0
+
0
   if (req)
0
     WinHttpCloseHandle(req);
0
 
0
@@ -170,4 +181,9 @@ done:
0
 VALUE
0
 shoes_http_error(SHOES_DOWNLOAD_ERROR code)
0
 {
0
+ TCHAR msg[1024];
0
+ DWORD msglen = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
0
+ NULL, code, 0, msg, sizeof(msg), NULL);
0
+ msg[msglen] = '\0';
0
+ return rb_str_new2(msg);
0
 }

Comments

    No one has commented yet.