]> Nishi Git Mirror - mandshurica.git/commitdiff
add token system
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Wed, 8 May 2024 03:25:55 +0000 (03:25 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Wed, 8 May 2024 03:25:55 +0000 (03:25 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@63 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Module/cookie.c
Module/http.c

index edf145dd2b03bbac64a4cf73344475e10c616306..7888a611fd47a76df320b58e2437851e71b86ff9 100644 (file)
@@ -62,7 +62,7 @@ int mod_init(struct mandshurica_config* _config) {
        return 0;
 }
 
-int mod_auth(const char* username, const char* password, void** ptr) {
+int mod_auth(const char* username, const char* password, char** ptr) {
        *ptr = NULL;
        struct ms_db* db = mandshurica_db_open(config->mandshurica_get_param("CookieDB"));
        if(db != NULL) {
@@ -74,6 +74,7 @@ int mod_auth(const char* username, const char* password, void** ptr) {
                        char* sh = config->mandshurica_sha512(password);
                        if(strcmp(sh, pwd) == 0) {
                                free(sh);
+                               *ptr = mandshurica_strdup("what");
                                return MS_AUTH_OK;
                        }
                        free(sh);
index 222547d192e894def7fe4eda005bcdf6ecb9d310..fd24422e8013a2f7ede3cd90b3ff553d85ece830 100644 (file)
@@ -195,14 +195,13 @@ void http_handler(int sock) {
                                                                                const char* httppath = (const char*)dlsym((*config->libs)[j]->lib, "mod_http_path");
                                                                                if(httppath != NULL) {
                                                                                        if(strcmp(httppath, path) == 0) {
-                                                                                               int (*mod_auth)(const char*, const char*, void**) = (int (*)(const char*, const char*, void**))dlsym((*config->libs)[j]->lib, "mod_auth");
+                                                                                               int (*mod_auth)(const char*, const char*, char**) = (int (*)(const char*, const char*, char**))dlsym((*config->libs)[j]->lib, "mod_auth");
                                                                                                char* usr = mandshurica_parse_form(postbuf, "username");
                                                                                                char* pwd = mandshurica_parse_form(postbuf, "password");
                                                                                                if(usr != NULL && pwd != NULL) {
-                                                                                                       void* ptr;
+                                                                                                       char* ptr;
                                                                                                        int res = mod_auth(usr, pwd, &ptr);
                                                                                                        if(res == MS_AUTH_OK) {
-                                                                                                               printf("%llx\n", ptr);
                                                                                                                char* type;
                                                                                                                uint64_t len;
                                                                                                                char* data = NULL;
@@ -256,6 +255,7 @@ void http_handler(int sock) {
                                                                                                                        send(sock, "Content-Length: 0\r\n", 19, 0);
                                                                                                                        send(sock, "\r\n", 2, 0);
                                                                                                                }
+                                                                                                               free(ptr);
                                                                                                        } else if(res == MS_AUTH_ERROR) {
                                                                                                                send(sock, "HTTP/1.1 400 Bad Request\r\n", 17 + 9, 0);
                                                                                                                send(sock, "Connection: keep-alive\r\n", 24, 0);