forked from cory/tildefriends
Move the auth handler out of JS. #7
This commit is contained in:
45
src/http.c
45
src/http.c
@ -1030,3 +1030,48 @@ void* tf_http_get_user_data(tf_http_t* http)
|
||||
{
|
||||
return http->user_data;
|
||||
}
|
||||
|
||||
const char* tf_http_get_cookie(const char* cookie_header, const char* name)
|
||||
{
|
||||
if (!cookie_header)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int name_start = 0;
|
||||
int equals = 0;
|
||||
for (int i = 0; ; i++)
|
||||
{
|
||||
if (cookie_header[i] == '=')
|
||||
{
|
||||
equals = i;
|
||||
}
|
||||
else if (cookie_header[i] == ',' || cookie_header[i] == ';' || cookie_header[i] == '\0')
|
||||
{
|
||||
if (equals > name_start &&
|
||||
strncmp(cookie_header + name_start, name, equals - name_start) == 0 &&
|
||||
(int)strlen(name) == equals - name_start)
|
||||
{
|
||||
int length = i - equals - 1;
|
||||
char* result = tf_malloc(length + 1);
|
||||
memcpy(result, cookie_header + equals + 1, length);
|
||||
result[length] = '\0';
|
||||
return result;
|
||||
}
|
||||
|
||||
if (cookie_header[i] == '\0')
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
name_start = i + 1;
|
||||
while (cookie_header[name_start] == ' ')
|
||||
{
|
||||
name_start++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user