]> Nishi Git Mirror - mandshurica.git/commitdiff
lock there too
authornishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Wed, 8 May 2024 03:22:26 +0000 (03:22 +0000)
committernishi <nishi@f982e544-4a7d-3444-ad1a-fde59a2a69f1>
Wed, 8 May 2024 03:22:26 +0000 (03:22 +0000)
git-svn-id: file:///raid/svn-main/nishi-mandshurica/trunk@62 f982e544-4a7d-3444-ad1a-fde59a2a69f1

Mandshurica/db.c
Module/cookie.c
Module/http.c

index 4a9300296e47f6c353a50f1008d93c3118d6207e..ddfce62eceb430f4397d650276e23c37162472b2 100644 (file)
@@ -37,7 +37,6 @@
 #include <string.h>
 
 struct ms_db* mandshurica_db_open(const char* path) {
-
        FILE* fp = fopen(path, "r+b");
        if(fp != NULL) {
                struct ms_db* db = malloc(sizeof(*db));
@@ -64,6 +63,7 @@ void mandshurica_db_write(struct ms_db* db, const char* key, const char* value)
 
 /* key:value */
 char* mandshurica_db_get(struct ms_db* db, const char* key) {
+       flockfile(db->fp);
        fseek(db->fp, 0, SEEK_SET);
        char cbuf[2];
        cbuf[1] = 0;
@@ -96,5 +96,6 @@ char* mandshurica_db_get(struct ms_db* db, const char* key) {
                }
        }
        free(line);
+       funlockfile(db->fp);
        return NULL;
 }
index 3aca1390a2ab5cb7aa9b8702d3e199ff1ef72dbf..edf145dd2b03bbac64a4cf73344475e10c616306 100644 (file)
@@ -62,7 +62,8 @@ int mod_init(struct mandshurica_config* _config) {
        return 0;
 }
 
-int mod_auth(const char* username, const char* password) {
+int mod_auth(const char* username, const char* password, void** ptr) {
+       *ptr = NULL;
        struct ms_db* db = mandshurica_db_open(config->mandshurica_get_param("CookieDB"));
        if(db != NULL) {
                char* pwd = mandshurica_db_get(db, username);
index de92abeeb46bd46a08741191dcb83f723d635c40..222547d192e894def7fe4eda005bcdf6ecb9d310 100644 (file)
@@ -195,12 +195,14 @@ 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*) = (int (*)(const char*, const char*))dlsym((*config->libs)[j]->lib, "mod_auth");
+                                                                                               int (*mod_auth)(const char*, const char*, void**) = (int (*)(const char*, const char*, void**))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) {
-                                                                                                       int res = mod_auth(usr, pwd);
+                                                                                                       void* 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;