-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparse_http_status.c
More file actions
53 lines (45 loc) · 1.26 KB
/
parse_http_status.c
File metadata and controls
53 lines (45 loc) · 1.26 KB
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
48
49
50
51
52
53
#include <string.h>
#include "cli-sub.h"
struct http_status_response *parse_http_status( char *line)
{
int code, err = 0;
char *st = 0, *delim = 0, *pos = 0;
struct http_status_response *resp = 0;
resp = (struct http_status_response *) malloc( sizeof *resp);
if( resp)
{
resp->code = 0;
resp->version = 0;
resp->reason = 0;
delim = index( line, BLANK_CH);
st = dup_memory( line, delim - 1);
if( st)
{
resp->version = st;
pos = delim + 1;
delim = index( pos, BLANK_CH);
st = dup_memory( pos, delim - 1);
if( st)
{
code = strtol( st, &pos, 10);
if( !pos) err = 1;
else if( *pos) err = 1;
else
{
resp->code = code;
pos = strdup( delim + 1);
if( pos) resp->reason = pos;
}
free( st);
}
}
if( !resp->version || !resp->reason || err)
{
if( resp->version) free( resp->version);
if( resp->reason) free( resp->reason);
free( resp);
resp = 0;
}
}
return( resp);
}