]> Nishi Git Mirror - mandshurica.git/commitdiff
authentication is pain
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 01:21:44 +0000 (01:21 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Sat, 20 Apr 2024 01:21:44 +0000 (01:21 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@48 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Module/cookie.c
Module/http.c
Webroot/index.html.tmpl

index 629a718070571040798b652f871f2bbe4b44b58c..a07312bde846441c6c0a0be00271af4724bfbb2d 100644 (file)
@@ -39,6 +39,8 @@ const char mod_type[] = MS_MOD_AUTH;
 
 const char mod_auth_type[] = "Cookie";
 
+const char mod_http_path[] = "/cookie-login";
+
 struct mandshurica_config* config;
 
 int mod_init(struct mandshurica_config* _config) {
index f8d2413ec299c0bcf754fb0e7412f069f09fb3f6..28aa4165af9e1d32fc555a719d8e40943049bf16 100644 (file)
@@ -153,12 +153,19 @@ void http_handler(int sock) {
                        free(headers);
                        headers = NULL;
                }
+               unsigned long long conlen = 0;
                while(true) {
                        int len = recv(sock, buf, BUFFER_SIZE, 0);
                        if(len <= 0) goto goquit;
                        int i;
                        for(i = 0; i < len; i++) {
                                cbuf[0] = buf[i];
+                               if(conlen > 0){
+                                       conlen--;
+                                       printf("%c", cbuf[0]);
+                                       fflush(stdout);
+                                       continue;
+                               }
                                if(state == 0) {
                                        if(buf[i] == ' ') {
                                                state = 1;
@@ -185,7 +192,30 @@ void http_handler(int sock) {
                                        } else if(buf[i] == '\n') {
                                                count++;
                                                if(count == 2) {
-                                                       if(strcmp(method, "GET") == 0) {
+                                                       if(strcmp(method, "POST") == 0) {
+                                                               if(headers != NULL){
+                                                                       int j;
+                                                                       bool haslen = false;
+                                                                       for(j = 0; headers[j] != NULL; j += 2){
+                                                                               if(mandshurica_strcaseequ(headers[j], "Content-Length")){
+                                                                                       haslen = true;
+                                                                                       conlen = atoll(headers[j + 1]);
+                                                                                       break;
+                                                                               }
+                                                                       }
+                                                                       if(!haslen){
+                                                                               send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0);
+                                                                               send(sock, "Connection: keep-alive\r\n", 24, 0);
+                                                                               send(sock, "Content-Length: 0\r\n", 19, 0);
+                                                                               send(sock, "\r\n", 2, 0);
+                                                                       }
+                                                               }else{
+                                                                       send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0);
+                                                                       send(sock, "Connection: keep-alive\r\n", 24, 0);
+                                                                       send(sock, "Content-Length: 0\r\n", 19, 0);
+                                                                       send(sock, "\r\n", 2, 0);
+                                                               }
+                                                       }else if(strcmp(method, "GET") == 0) {
                                                                char* chpath = mandshurica_strcat(webroot, path);
                                                                struct stat st2;
                                                                if(stat(chpath, &st2) != 0) {
index f16732ba721ec5ea05920f2383e486ce1b1a7838..531ecbb6af8e672d51cbfb8fd1e07e7cf50cbea4 100644 (file)
@@ -1,13 +1,9 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
 <!--@chdir_webroot@
 vim: syntax=html
 -->
-<html>
-       <head>
-       </head>
-       <body>
-               <img src="/mandshurica.gif">
-               <h1>Mandshurica</h1>
-               <hr>
-       </body>
-</html>
+@include head-start.html@
+<title>Mandshurica</title>
+@include body-start.html@
+<h1>Mandshurica</h1>
+@include bar.html@
+@include end.html@