Subversion Repositories RepoView

Rev

Rev 5 | Rev 7 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line 1... Line 1...
1
/* $Id: cookie.c 5 2024-08-20 22:43:56Z nishi $ */
1
/* $Id: cookie.c 6 2024-08-21 00:44:17Z nishi $ */
2
 
2
 
3
#include "rv_auth.h"
3
#include "rv_auth.h"
4
 
4
 
5
#include "rv_util.h"
5
#include "rv_util.h"
6
#include "rv_db.h"
6
#include "rv_db.h"
Line 71... Line 71...
71
 
71
 
72
char* rv_logged_in(void) {
72
char* rv_logged_in(void) {
73
	int i;
73
	int i;
74
	for(i = 0; cookie_entries[i] != NULL; i++) {
74
	for(i = 0; cookie_entries[i] != NULL; i++) {
75
		if(strcmp(cookie_entries[i]->key, "token") == 0) {
75
		if(strcmp(cookie_entries[i]->key, "token") == 0) {
76
			return rv_who_has_token(cookie_entries[i]->value);
76
			char* who = rv_who_has_token(cookie_entries[i]->value);
-
 
77
			if(who == NULL) {
-
 
78
				printf("Set-Cookie: token=; HttpOnly; Expires=0; SameSite=Strict\r\n");
-
 
79
			}
-
 
80
			return who;
77
			break;
81
			break;
78
		}
82
		}
79
	}
83
	}
80
	return NULL;
84
	return NULL;
81
}
85
}
82
 
86
 
83
void rv_save_login(const char* username) {
87
void rv_save_login(const char* username) {
84
	char* token = rv_new_token(username);
88
	char* token = rv_new_token(username);
85
	printf("Set-Cookie: token=%s; HttpOnly\r\n", token);
89
	printf("Set-Cookie: token=%s; HttpOnly; SameSite=Strict\r\n", token);
86
	free(token);
90
	free(token);
87
}
91
}
88
 
92
 
89
void rv_init_auth(void) { parse_cookie(); }
93
void rv_init_auth(void) { parse_cookie(); }
90
 
94