From a06b78f6b47c6e5287ea9a5c935afea4ded6e0b8 Mon Sep 17 00:00:00 2001 From: Chip Black Date: Thu, 10 Jul 2014 01:55:49 -0500 Subject: [PATCH] Add a function for parsing combined auth cookies --- common/app.c | 23 +++++++++++++++++++++++ common/app.h | 8 +++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/common/app.c b/common/app.c index 55ec75a..2fad96e 100644 --- a/common/app.c +++ b/common/app.c @@ -41,6 +41,29 @@ int parse_url_info(const char *url, struct url_info *info) { return info->contents; } +int parse_auth_cookie(const char *str, struct auth_cookie *cookie) { + char *token_begin = strchr(str, '/'); + if (token_begin == NULL) { + return 0; + } + int len = token_begin - str; + if (len > MAX_TAG_LENGTH || len == 0) { + return 0; + } + memcpy(cookie->name, str, len); + cookie->name[len] = 0; + + token_begin++; + len = strlen(token_begin); + if (len != TOKEN_SIZE * 2) { + return 0; + } + memcpy(cookie->token, token_begin, TOKEN_SIZE * 2); + cookie->token[TOKEN_SIZE * 2] = 0; + + return 1; +} + uint64_t *make_sequential_list(uint64_t from, uint64_t to) { uint64_t len = to - from + 1; uint64_t *list = malloc(len * sizeof(uint64_t)); diff --git a/common/app.h b/common/app.h index 8156274..04d8fa5 100644 --- a/common/app.h +++ b/common/app.h @@ -4,9 +4,9 @@ #ifndef _APP_H #define _APP_H -#include #include "database.h" #include "config.h" +#include "auth.h" #define REALM "Blerg" @@ -29,7 +29,13 @@ struct url_info { uint64_t record_to; }; +struct auth_cookie { + char name[MAX_TAG_LENGTH + 1]; + char token[TOKEN_SIZE * 2 + 1]; +}; + int parse_url_info(const char *url, struct url_info *info); +int parse_auth_cookie(const char *str, struct auth_cookie *cookie); uint64_t *make_sequential_list(uint64_t from, uint64_t to); #endif /* _APP_H */ -- 2.25.1