Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_cookies.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
27#ifndef __NILOREA_COOKIES_HEADER
28#define __NILOREA_COOKIES_HEADER
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#include "nilorea/n_list.h"
35#include "nilorea/n_str.h"
36
37#include <pthread.h>
38
45typedef struct N_COOKIE {
46 char* name;
47 char* value;
48 char* domain;
49 char* path;
50 int secure;
52 long expires;
53} N_COOKIE;
54
56typedef struct N_COOKIE_JAR {
58 pthread_rwlock_t lock;
60
66void n_cookiejar_add_from_header(N_COOKIE_JAR* jar, const char* set_cookie_value, const char* request_domain);
68N_STR* n_cookiejar_build_header(N_COOKIE_JAR* jar, const char* domain, const char* path, int is_secure);
73
78#ifdef __cplusplus
79}
80#endif
81
82#endif /* __NILOREA_COOKIES_HEADER */
Structure of a generic LIST container.
Definition n_list.h:59
long expires
unix expiry timestamp, 0 = session cookie
Definition n_cookies.h:52
char * path
path prefix (e.g.
Definition n_cookies.h:49
char * domain
domain (e.g.
Definition n_cookies.h:48
char * value
cookie value
Definition n_cookies.h:47
int http_only
1 = HttpOnly flag was set
Definition n_cookies.h:51
LIST * cookies
list of N_COOKIE*
Definition n_cookies.h:57
int secure
1 = only sent over HTTPS
Definition n_cookies.h:50
char * name
cookie name
Definition n_cookies.h:46
pthread_rwlock_t lock
guards cookies for concurrent use
Definition n_cookies.h:58
void n_cookiejar_free(N_COOKIE_JAR **jar)
free a cookie jar and all its cookies, then NULL the pointer
Definition n_cookies.c:63
void n_cookiejar_add_from_header(N_COOKIE_JAR *jar, const char *set_cookie_value, const char *request_domain)
parse one Set-Cookie value (without the "Set-Cookie:" name) and store it; request_domain/path supply ...
Definition n_cookies.c:97
N_STR * n_cookiejar_build_header(N_COOKIE_JAR *jar, const char *domain, const char *path, int is_secure)
build a "name=value; name2=value2" Cookie header value for a request (domain/path/secure/expiry match...
Definition n_cookies.c:181
N_COOKIE_JAR * n_cookiejar_new(void)
create an empty cookie jar; free with n_cookiejar_free.
Definition n_cookies.c:49
void n_cookiejar_clear(N_COOKIE_JAR *jar)
drop every stored cookie
Definition n_cookies.c:229
size_t n_cookiejar_count(N_COOKIE_JAR *jar)
number of cookies currently stored
Definition n_cookies.c:219
a single stored cookie
Definition n_cookies.h:45
a thread-safe cookie jar
Definition n_cookies.h:56
A box including a string and his lenght.
Definition n_str.h:61
List structures and definitions.
N_STR and string function declaration.