Lines 22-28
Link Here
|
22 |
* Author: Mladen Turk <mturk@apache.org> * |
22 |
* Author: Mladen Turk <mturk@apache.org> * |
23 |
* Author: Rainer Jung <rjung@apache.org> * |
23 |
* Author: Rainer Jung <rjung@apache.org> * |
24 |
* Based on: * |
24 |
* Based on: * |
25 |
* Version: $Revision: 562194 $ * |
25 |
* Version: $Revision: 1.6 $ * |
26 |
***************************************************************************/ |
26 |
***************************************************************************/ |
27 |
|
27 |
|
28 |
#include "jk_pool.h" |
28 |
#include "jk_pool.h" |
Lines 336-381
Link Here
|
336 |
} |
336 |
} |
337 |
|
337 |
|
338 |
/* Retrieve the cookie with the given name */ |
338 |
/* Retrieve the cookie with the given name */ |
339 |
static char *get_cookie(jk_ws_service_t *s, const char *name) |
339 |
static char *get_cookie(jk_ws_service_t *s, const char *name, jk_logger_t *l) |
340 |
{ |
340 |
{ |
341 |
unsigned i; |
341 |
char *result = NULL; |
342 |
char *result = NULL; |
342 |
char *id_start; |
|
|
343 |
char *id_end; |
344 |
unsigned i; |
345 |
size_t sz, osz; |
343 |
|
346 |
|
344 |
for (i = 0; i < s->num_headers; i++) { |
347 |
for (i = 0; i < s->num_headers; i++) { |
345 |
if (strcasecmp(s->headers_names[i], "cookie") == 0) { |
348 |
if (strcasecmp(s->headers_names[i], "cookie") == 0) { |
346 |
|
349 |
|
347 |
char *id_start; |
|
|
348 |
for (id_start = strstr(s->headers_values[i], name); |
350 |
for (id_start = strstr(s->headers_values[i], name); |
349 |
id_start; id_start = strstr(id_start + 1, name)) { |
351 |
id_start; id_start = strstr(id_start + 1, name)) { |
|
|
352 |
|
350 |
if (id_start == s->headers_values[i] || |
353 |
if (id_start == s->headers_values[i] || |
351 |
id_start[-1] == ';' || |
354 |
id_start[-1] == ';' || |
352 |
id_start[-1] == ',' || isspace((int)id_start[-1])) { |
355 |
id_start[-1] == ',' || isspace((int)id_start[-1])) { |
353 |
id_start += strlen(name); |
356 |
id_start += strlen(name); |
|
|
357 |
|
354 |
while (*id_start && isspace((int)(*id_start))) |
358 |
while (*id_start && isspace((int)(*id_start))) |
355 |
++id_start; |
359 |
++id_start; |
|
|
360 |
|
356 |
if (*id_start == '=' && id_start[1]) { |
361 |
if (*id_start == '=' && id_start[1]) { |
357 |
/* |
362 |
/* |
358 |
* Session cookie was found, get it's value |
363 |
* Session cookie was found, get it's value |
359 |
*/ |
364 |
*/ |
360 |
char *id_end; |
|
|
361 |
++id_start; |
365 |
++id_start; |
362 |
id_start = jk_pool_strdup(s->pool, id_start); |
366 |
|
363 |
if ((id_end = strchr(id_start, ';')) != NULL) { |
367 |
if ((id_end = strchr(id_start, ';')) != NULL || (id_end = strchr(id_start, ',')) != NULL) |
364 |
*id_end = '\0'; |
368 |
sz = id_end - id_start; |
365 |
} |
369 |
else |
366 |
if ((id_end = strchr(id_start, ',')) != NULL) { |
370 |
sz = strlen(id_start); |
367 |
*id_end = '\0'; |
371 |
|
368 |
} |
|
|
369 |
if (result == NULL) { |
372 |
if (result == NULL) { |
370 |
result = id_start; |
373 |
result = jk_pool_alloc(s->pool, sz + 1); |
|
|
374 |
if (!result) { |
375 |
jk_log(l, JK_LOG_ERROR, "Cannot allocate memory for %s", name); |
376 |
return result; |
377 |
} |
378 |
memcpy(result, id_start, sz); |
379 |
result[sz] = '\0'; |
371 |
} |
380 |
} |
372 |
else { |
381 |
else { |
373 |
size_t osz = strlen(result) + 1; |
382 |
osz = strlen(result) + 1; |
374 |
size_t sz = osz + strlen(id_start) + 1; |
383 |
result = jk_pool_realloc(s->pool, osz + sz + 1, result, osz); |
375 |
result = |
384 |
if (!result) { |
376 |
jk_pool_realloc(s->pool, sz, result, osz); |
385 |
jk_log(l, JK_LOG_ERROR, "Cannot reallocate memory for %s", name); |
377 |
strcat(result, ";"); |
386 |
return result; |
378 |
strcat(result, id_start); |
387 |
} |
|
|
388 |
strcat(result, ";"); |
389 |
strncat(result, id_start, sz); |
379 |
} |
390 |
} |
380 |
} |
391 |
} |
381 |
} |
392 |
} |
Lines 395-401
Link Here
|
395 |
char *val; |
406 |
char *val; |
396 |
val = get_path_param(s, JK_PATH_SESSION_IDENTIFIER); |
407 |
val = get_path_param(s, JK_PATH_SESSION_IDENTIFIER); |
397 |
if (!val) { |
408 |
if (!val) { |
398 |
val = get_cookie(s, JK_SESSION_IDENTIFIER); |
409 |
val = get_cookie(s, JK_SESSION_IDENTIFIER, l); |
399 |
} |
410 |
} |
400 |
if (val && !*val) { |
411 |
if (val && !*val) { |
401 |
/* TODO: For now only log the empty sessions. |
412 |
/* TODO: For now only log the empty sessions. |