6 n__cookies_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_cookies.h

Domain-aware HTTP cookie jar: Set-Cookie parsing and Cookie header building. More...

Structures

Name
struct N_COOKIE_JAR
a thread-safe cookie jar
struct N_COOKIE
a single stored cookie

Detailed Description

Domain-aware HTTP cookie jar: Set-Cookie parsing and Cookie header building.

Author: Castagnier Mickael

Version: 1.0

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __NILOREA_COOKIES_HEADER
#define __NILOREA_COOKIES_HEADER

#ifdef __cplusplus
extern "C" {
#endif

#include "nilorea/n_list.h"
#include "nilorea/n_str.h"

#include <pthread.h>


typedef struct N_COOKIE {
    char* name;    
    char* value;   
    char* domain;  
    char* path;    
    int secure;    
    int http_only; 
    long expires;  
} N_COOKIE;

typedef struct N_COOKIE_JAR {
    LIST* cookies;         
    pthread_rwlock_t lock; 
} N_COOKIE_JAR;

N_COOKIE_JAR* n_cookiejar_new(void);
void n_cookiejar_free(N_COOKIE_JAR** jar);
void n_cookiejar_add_from_header(N_COOKIE_JAR* jar, const char* set_cookie_value, const char* request_domain);
N_STR* n_cookiejar_build_header(N_COOKIE_JAR* jar, const char* domain, const char* path, int is_secure);
size_t n_cookiejar_count(N_COOKIE_JAR* jar);
size_t n_cookiejar_remove(N_COOKIE_JAR* jar, const char* name, const char* domain, const char* path);
void n_cookiejar_clear(N_COOKIE_JAR* jar);


#ifdef __cplusplus
}
#endif

#endif /* __NILOREA_COOKIES_HEADER */