forked from vrasneur/icapclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcicap_compat.c
47 lines (44 loc) · 1.6 KB
/
cicap_compat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* -*- Mode: C; c-basic-offset: 4 -*- */
/*
* Copyright 2015 Vincent Rasneur <[email protected]>
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
* NON INFRINGEMENT. See the GNU General Public License for
* more details.
*/
#include "cicap_compat.h"
// if the header iteration function is not defined
// just copy-paste the code from a recent C-ICAP version
#ifdef OLD_CICAP_VERSION
#define eoh(s) ((*s == '\r' && *(s+1) == '\n' && *(s+2) != '\t' && *(s+2) != ' ') || (*s == '\n' && *(s+1) != '\t' && *(s+1) != ' '))
int ci_headers_iterate(ci_headers_list_t * h, void *data, void (*fn)(void *, const char *head, const char *value))
{
char header[256];
char value[8124];
char *s;
size_t i, j;
for (i = 0; i < (size_t)h->used; i++) {
s = h->headers[i];
for (j = 0; j < sizeof(header)-1 && *s != ':' && *s != '\0' && *s != '\r' && *s!='\n'; s++, j++)
header[j] = *s;
header[j] = '\0';
j = 0;
if (*s == ':') {
s++;
while (*s == ' ') s++;
for (j = 0; j < sizeof(value)-1 && *s != '\0' && !eoh(s); s++, j++)
value[j] = *s;
}
value[j] = '\0';
fn(data, header, value);
}
return 1;
}
#endif