Changeset 212 in Main for trunk/Server/http.c
- Timestamp:
- Oct 3, 2024, 2:44:55 AM (6 weeks ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Server/http.c
r187 r212 16 16 #include <string.h> 17 17 18 #if def __MINGW32__18 #if defined(__MINGW32__) || defined(_MSC_VER) 19 19 #include <winsock2.h> 20 20 #else … … 54 54 char cbuf[2]; 55 55 int phase = 0; 56 char* header; 57 int nl; 56 58 57 59 #ifdef USE_POLL … … 74 76 req->version = NULL; 75 77 76 char*header = malloc(1);78 header = malloc(1); 77 79 header[0] = 0; 78 intnl = 0;80 nl = 0; 79 81 80 82 while(1) { 83 int i; 84 int len; 85 int n; 81 86 #ifndef USE_POLL 87 struct timeval tv; 82 88 FD_ZERO(&fds); 83 89 FD_SET(sock, &fds); 84 struct timeval tv;85 90 tv.tv_sec = 5; 86 91 tv.tv_usec = 0; … … 90 95 #endif 91 96 #ifdef USE_POLL 92 intn = poll(pollfds, 1, 5000);97 n = poll(pollfds, 1, 5000); 93 98 #else 94 99 #ifdef __HAIKU__ 95 intn = select(32, &fds, NULL, NULL, &tv);96 #else 97 intn = select(FD_SETSIZE, &fds, NULL, NULL, &tv);100 n = select(32, &fds, NULL, NULL, &tv); 101 #else 102 n = select(FD_SETSIZE, &fds, NULL, NULL, &tv); 98 103 #endif 99 104 #endif … … 107 112 } 108 113 #endif 109 intlen = tw_read(ssl, sock, buffer, 512);114 len = tw_read(ssl, sock, buffer, 512); 110 115 if(len <= 0) { 111 116 bad = true; 112 117 break; 113 118 } 114 int i;115 119 for(i = 0; i < len; i++) { 116 120 char c = buffer[i]; … … 125 129 } 126 130 } else { 131 char* tmp; 127 132 if(req->method == NULL) { 128 133 req->method = malloc(1); … … 130 135 } 131 136 cbuf[0] = c; 132 char*tmp = req->method;137 tmp = req->method; 133 138 req->method = cm_strcat(tmp, cbuf); 134 139 free(tmp); … … 144 149 } 145 150 } else { 151 char* tmp; 146 152 if(req->path == NULL) { 147 153 req->path = malloc(1); … … 149 155 } 150 156 cbuf[0] = c; 151 char*tmp = req->path;157 tmp = req->path; 152 158 req->path = cm_strcat(tmp, cbuf); 153 159 free(tmp); … … 161 167 } else { 162 168 /* We have Method, Path, Version now */ 163 169 int j; 170 char* p; 171 int incr; 164 172 if(strcmp(req->version, "HTTP/1.1") != 0 && strcmp(req->version, "HTTP/1.0") != 0) { 165 173 cm_log("HTTP", "Bad HTTP Version"); … … 168 176 } 169 177 170 int j; 171 char* p = malloc(1); 178 p = malloc(1); 172 179 p[0] = 0; 173 180 for(j = 0; req->path[j] != 0; j++) { 181 char* tmp; 174 182 if(req->path[j] == '/') { 175 183 cbuf[0] = '/'; … … 180 188 cbuf[0] = req->path[j]; 181 189 } 182 char*tmp = p;190 tmp = p; 183 191 p = cm_strcat(tmp, cbuf); 184 192 free(tmp); … … 187 195 req->path = p; 188 196 189 in t incr = 0;197 incr = 0; 190 198 p = malloc(1); 191 199 p[0] = 0; … … 193 201 if(req->path[j] == '/' || req->path[j] == 0) { 194 202 char oldc = req->path[j]; 203 char* pth; 195 204 cbuf[0] = oldc; 196 205 req->path[j] = 0; 197 206 198 char*pth = req->path + incr;207 pth = req->path + incr; 199 208 200 209 if(strcmp(pth, "..") == 0) { … … 230 239 } 231 240 } else if(c != '\r') { 241 char* tmp; 232 242 if(req->version == NULL) { 233 243 req->version = malloc(1); … … 235 245 } 236 246 cbuf[0] = c; 237 char*tmp = req->version;247 tmp = req->version; 238 248 req->version = cm_strcat(tmp, cbuf); 239 249 free(tmp); … … 246 256 goto getout; 247 257 } else { 258 int j; 248 259 if(req->headers == NULL) { 249 260 req->headers = malloc(sizeof(*req->headers)); 250 261 req->headers[0] = NULL; 251 262 } 252 int j;253 263 for(j = 0; header[j] != 0; j++) { 254 264 if(header[j] == ':') { 265 char* kv; 266 char* vv; 267 char** old; 268 int k; 255 269 header[j] = 0; 256 270 j++; 257 271 for(; header[j] != 0 && (header[j] == ' ' || header[j] == '\t'); j++) 258 272 ; 259 char* kv = header; 260 char* vv = header + j; 261 262 char** old = req->headers; 263 int k; 273 kv = header; 274 vv = header + j; 275 276 old = req->headers; 264 277 for(k = 0; old[k] != NULL; k++) 265 278 ; … … 281 294 } 282 295 } else if(c != '\r') { 296 char* tmp; 283 297 nl = 0; 284 298 cbuf[0] = c; 285 char*tmp = header;299 tmp = header; 286 300 header = cm_strcat(tmp, cbuf); 287 301 free(tmp); … … 296 310 return 1; 297 311 } 298 char* result = malloc(1); 299 result[0] = 0; 300 int i; 301 for(i = 0; req->path[i] != 0; i++) { 302 if(req->path[i] == '?') { 303 req->path[i] = 0; 304 req->query = cm_strdup(req->path + i + 1); 305 break; 306 } 307 } 308 for(i = 0; req->path[i] != 0; i++) { 309 if(req->path[i] == '%') { 310 if(req->path[i + 1] == 0) continue; 311 cbuf[0] = cm_hex(req->path + i + 1, 2); 312 if(cbuf[0] != '\\') { 313 char* tmp = result; 312 { 313 char* result = malloc(1); 314 int i; 315 int j; 316 int incr; 317 char* p; 318 result[0] = 0; 319 for(i = 0; req->path[i] != 0; i++) { 320 if(req->path[i] == '?') { 321 req->path[i] = 0; 322 req->query = cm_strdup(req->path + i + 1); 323 break; 324 } 325 } 326 for(i = 0; req->path[i] != 0; i++) { 327 if(req->path[i] == '%') { 328 if(req->path[i + 1] == 0) continue; 329 cbuf[0] = cm_hex(req->path + i + 1, 2); 330 if(cbuf[0] != '\\') { 331 char* tmp = result; 332 result = cm_strcat(tmp, cbuf); 333 free(tmp); 334 } 335 i += 2; 336 } else if(req->path[i] != '\\') { 337 char* tmp; 338 cbuf[0] = req->path[i]; 339 tmp = result; 314 340 result = cm_strcat(tmp, cbuf); 315 341 free(tmp); 316 342 } 317 i += 2; 318 } else if(req->path[i] != '\\') { 319 cbuf[0] = req->path[i]; 320 char* tmp = result; 321 result = cm_strcat(tmp, cbuf); 322 free(tmp); 323 } 343 } 344 free(req->path); 345 req->path = result; 346 347 incr = 0; 348 p = malloc(1); 349 p[0] = 0; 350 for(j = 0;; j++) { 351 if(req->path[j] == '/' || req->path[j] == 0) { 352 char oldc = req->path[j]; 353 char* pth; 354 cbuf[0] = oldc; 355 req->path[j] = 0; 356 357 pth = req->path + incr; 358 359 if(strcmp(pth, "..") == 0) { 360 int k; 361 if(p[strlen(p) - 1] == '/') p[strlen(p) - 1] = 0; 362 for(k = strlen(p) - 1; k >= 0; k--) { 363 if(p[k] == '/') { 364 p[k + 1] = 0; 365 break; 366 } 367 } 368 if(strlen(p) == 0) { 369 free(p); 370 p = cm_strdup("/"); 371 } 372 } else if(strcmp(pth, ".") == 0) { 373 } else { 374 char* tmp = p; 375 p = cm_strcat3(tmp, pth, cbuf); 376 free(tmp); 377 } 378 379 incr = j + 1; 380 if(oldc == 0) break; 381 } 382 } 383 free(req->path); 384 req->path = p; 385 return 0; 324 386 } 325 free(req->path);326 req->path = result;327 328 int incr = 0;329 char* p = malloc(1);330 p[0] = 0;331 int j;332 for(j = 0;; j++) {333 if(req->path[j] == '/' || req->path[j] == 0) {334 char oldc = req->path[j];335 cbuf[0] = oldc;336 req->path[j] = 0;337 338 char* pth = req->path + incr;339 340 if(strcmp(pth, "..") == 0) {341 int k;342 if(p[strlen(p) - 1] == '/') p[strlen(p) - 1] = 0;343 for(k = strlen(p) - 1; k >= 0; k--) {344 if(p[k] == '/') {345 p[k + 1] = 0;346 break;347 }348 }349 if(strlen(p) == 0) {350 free(p);351 p = cm_strdup("/");352 }353 } else if(strcmp(pth, ".") == 0) {354 } else {355 char* tmp = p;356 p = cm_strcat3(tmp, pth, cbuf);357 free(tmp);358 }359 360 incr = j + 1;361 if(oldc == 0) break;362 }363 }364 free(req->path);365 req->path = p;366 return 0;367 387 }
Note:
See TracChangeset
for help on using the changeset viewer.