Index: trunk/Server/http.c
===================================================================
--- trunk/Server/http.c	(revision 187)
+++ trunk/Server/http.c	(revision 212)
@@ -16,5 +16,5 @@
 #include <string.h>
 
-#ifdef __MINGW32__
+#if defined(__MINGW32__) || defined(_MSC_VER)
 #include <winsock2.h>
 #else
@@ -54,4 +54,6 @@
 	char cbuf[2];
 	int phase = 0;
+	char* header;
+	int nl;
 
 #ifdef USE_POLL
@@ -74,13 +76,16 @@
 	req->version = NULL;
 
-	char* header = malloc(1);
+	header = malloc(1);
 	header[0] = 0;
-	int nl = 0;
+	nl = 0;
 
 	while(1) {
+		int i;
+		int len;
+			int n;
 #ifndef USE_POLL
+		struct timeval tv;
 		FD_ZERO(&fds);
 		FD_SET(sock, &fds);
-		struct timeval tv;
 		tv.tv_sec = 5;
 		tv.tv_usec = 0;
@@ -90,10 +95,10 @@
 #endif
 #ifdef USE_POLL
-			int n = poll(pollfds, 1, 5000);
+			n = poll(pollfds, 1, 5000);
 #else
 #ifdef __HAIKU__
-		int n = select(32, &fds, NULL, NULL, &tv);
-#else
-		int n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
+		n = select(32, &fds, NULL, NULL, &tv);
+#else
+		n = select(FD_SETSIZE, &fds, NULL, NULL, &tv);
 #endif
 #endif
@@ -107,10 +112,9 @@
 		}
 #endif
-		int len = tw_read(ssl, sock, buffer, 512);
+		len = tw_read(ssl, sock, buffer, 512);
 		if(len <= 0) {
 			bad = true;
 			break;
 		}
-		int i;
 		for(i = 0; i < len; i++) {
 			char c = buffer[i];
@@ -125,4 +129,5 @@
 					}
 				} else {
+					char* tmp;
 					if(req->method == NULL) {
 						req->method = malloc(1);
@@ -130,5 +135,5 @@
 					}
 					cbuf[0] = c;
-					char* tmp = req->method;
+					tmp = req->method;
 					req->method = cm_strcat(tmp, cbuf);
 					free(tmp);
@@ -144,4 +149,5 @@
 					}
 				} else {
+					char* tmp;
 					if(req->path == NULL) {
 						req->path = malloc(1);
@@ -149,5 +155,5 @@
 					}
 					cbuf[0] = c;
-					char* tmp = req->path;
+					tmp = req->path;
 					req->path = cm_strcat(tmp, cbuf);
 					free(tmp);
@@ -161,5 +167,7 @@
 					} else {
 						/* We have Method, Path, Version now */
-
+						int j;
+						char* p;
+						int incr;
 						if(strcmp(req->version, "HTTP/1.1") != 0 && strcmp(req->version, "HTTP/1.0") != 0) {
 							cm_log("HTTP", "Bad HTTP Version");
@@ -168,8 +176,8 @@
 						}
 
-						int j;
-						char* p = malloc(1);
+						p = malloc(1);
 						p[0] = 0;
 						for(j = 0; req->path[j] != 0; j++) {
+							char* tmp;
 							if(req->path[j] == '/') {
 								cbuf[0] = '/';
@@ -180,5 +188,5 @@
 								cbuf[0] = req->path[j];
 							}
-							char* tmp = p;
+							tmp = p;
 							p = cm_strcat(tmp, cbuf);
 							free(tmp);
@@ -187,5 +195,5 @@
 						req->path = p;
 
-						int incr = 0;
+						incr = 0;
 						p = malloc(1);
 						p[0] = 0;
@@ -193,8 +201,9 @@
 							if(req->path[j] == '/' || req->path[j] == 0) {
 								char oldc = req->path[j];
+								char* pth;
 								cbuf[0] = oldc;
 								req->path[j] = 0;
 
-								char* pth = req->path + incr;
+								pth = req->path + incr;
 
 								if(strcmp(pth, "..") == 0) {
@@ -230,4 +239,5 @@
 					}
 				} else if(c != '\r') {
+					char* tmp;
 					if(req->version == NULL) {
 						req->version = malloc(1);
@@ -235,5 +245,5 @@
 					}
 					cbuf[0] = c;
-					char* tmp = req->version;
+					tmp = req->version;
 					req->version = cm_strcat(tmp, cbuf);
 					free(tmp);
@@ -246,20 +256,23 @@
 						goto getout;
 					} else {
+						int j;
 						if(req->headers == NULL) {
 							req->headers = malloc(sizeof(*req->headers));
 							req->headers[0] = NULL;
 						}
-						int j;
 						for(j = 0; header[j] != 0; j++) {
 							if(header[j] == ':') {
+								char* kv;
+								char* vv;
+								char** old;
+								int k;
 								header[j] = 0;
 								j++;
 								for(; header[j] != 0 && (header[j] == ' ' || header[j] == '\t'); j++)
 									;
-								char* kv = header;
-								char* vv = header + j;
-
-								char** old = req->headers;
-								int k;
+								kv = header;
+								vv = header + j;
+
+								old = req->headers;
 								for(k = 0; old[k] != NULL; k++)
 									;
@@ -281,7 +294,8 @@
 					}
 				} else if(c != '\r') {
+					char* tmp;
 					nl = 0;
 					cbuf[0] = c;
-					char* tmp = header;
+					tmp = header;
 					header = cm_strcat(tmp, cbuf);
 					free(tmp);
@@ -296,72 +310,78 @@
 		return 1;
 	}
-	char* result = malloc(1);
-	result[0] = 0;
-	int i;
-	for(i = 0; req->path[i] != 0; i++) {
-		if(req->path[i] == '?') {
-			req->path[i] = 0;
-			req->query = cm_strdup(req->path + i + 1);
-			break;
-		}
-	}
-	for(i = 0; req->path[i] != 0; i++) {
-		if(req->path[i] == '%') {
-			if(req->path[i + 1] == 0) continue;
-			cbuf[0] = cm_hex(req->path + i + 1, 2);
-			if(cbuf[0] != '\\') {
-				char* tmp = result;
+	{
+		char* result = malloc(1);
+		int i;
+		int j;
+		int incr;
+		char* p;
+		result[0] = 0;
+		for(i = 0; req->path[i] != 0; i++) {
+			if(req->path[i] == '?') {
+				req->path[i] = 0;
+				req->query = cm_strdup(req->path + i + 1);
+				break;
+			}
+		}
+		for(i = 0; req->path[i] != 0; i++) {
+			if(req->path[i] == '%') {
+				if(req->path[i + 1] == 0) continue;
+				cbuf[0] = cm_hex(req->path + i + 1, 2);
+				if(cbuf[0] != '\\') {
+					char* tmp = result;
+					result = cm_strcat(tmp, cbuf);
+					free(tmp);
+				}
+				i += 2;
+			} else if(req->path[i] != '\\') {
+				char* tmp;
+				cbuf[0] = req->path[i];
+				tmp = result;
 				result = cm_strcat(tmp, cbuf);
 				free(tmp);
 			}
-			i += 2;
-		} else if(req->path[i] != '\\') {
-			cbuf[0] = req->path[i];
-			char* tmp = result;
-			result = cm_strcat(tmp, cbuf);
-			free(tmp);
-		}
+		}
+		free(req->path);
+		req->path = result;
+	
+		incr = 0;
+		p = malloc(1);
+		p[0] = 0;
+		for(j = 0;; j++) {
+			if(req->path[j] == '/' || req->path[j] == 0) {
+				char oldc = req->path[j];
+				char* pth;
+				cbuf[0] = oldc;
+				req->path[j] = 0;
+	
+				pth = req->path + incr;
+	
+				if(strcmp(pth, "..") == 0) {
+					int k;
+					if(p[strlen(p) - 1] == '/') p[strlen(p) - 1] = 0;
+					for(k = strlen(p) - 1; k >= 0; k--) {
+						if(p[k] == '/') {
+							p[k + 1] = 0;
+							break;
+						}
+					}
+					if(strlen(p) == 0) {
+						free(p);
+						p = cm_strdup("/");
+					}
+				} else if(strcmp(pth, ".") == 0) {
+				} else {
+					char* tmp = p;
+					p = cm_strcat3(tmp, pth, cbuf);
+					free(tmp);
+				}
+	
+				incr = j + 1;
+				if(oldc == 0) break;
+			}
+		}
+		free(req->path);
+		req->path = p;
+		return 0;
 	}
-	free(req->path);
-	req->path = result;
-
-	int incr = 0;
-	char* p = malloc(1);
-	p[0] = 0;
-	int j;
-	for(j = 0;; j++) {
-		if(req->path[j] == '/' || req->path[j] == 0) {
-			char oldc = req->path[j];
-			cbuf[0] = oldc;
-			req->path[j] = 0;
-
-			char* pth = req->path + incr;
-
-			if(strcmp(pth, "..") == 0) {
-				int k;
-				if(p[strlen(p) - 1] == '/') p[strlen(p) - 1] = 0;
-				for(k = strlen(p) - 1; k >= 0; k--) {
-					if(p[k] == '/') {
-						p[k + 1] = 0;
-						break;
-					}
-				}
-				if(strlen(p) == 0) {
-					free(p);
-					p = cm_strdup("/");
-				}
-			} else if(strcmp(pth, ".") == 0) {
-			} else {
-				char* tmp = p;
-				p = cm_strcat3(tmp, pth, cbuf);
-				free(tmp);
-			}
-
-			incr = j + 1;
-			if(oldc == 0) break;
-		}
-	}
-	free(req->path);
-	req->path = p;
-	return 0;
 }
