-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
91 lines (73 loc) · 1.35 KB
/
Copy pathutils.c
File metadata and controls
91 lines (73 loc) · 1.35 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <memory.h>
#include <stdio.h>
#include "utils.h"
int method_to_code(char *str)
{
if (strcmp(str, "GET") == 0)
{
return HTTP_METHOD_GET;
}
if (strcmp(str, "POST") == 0)
{
return HTTP_METHOD_POST;
}
if (strcmp(str, "PUT") == 0)
{
return HTTP_METHOD_PUT;
}
if (strcmp(str, "PATCH") == 0)
{
return HTTP_METHOD_PATCH;
}
if (strcmp(str, "OPTIONS") == 0)
{
return HTTP_METHOD_OPTIONS;
}
if (strcmp(str, "HEAD") == 0)
{
return HTTP_METHOD_HEAD;
}
return -1;
}
char *code_to_method(int code)
{
if (code == HTTP_METHOD_GET)
{
return "GET";
}
if (code == HTTP_METHOD_POST)
{
return "POST";
}
if (code == HTTP_METHOD_PUT)
{
return "PUT";
}
if (code == HTTP_METHOD_PATCH)
{
return "PATCH";
}
if (code == HTTP_METHOD_OPTIONS)
{
return "OPTIONS";
}
if (code == HTTP_METHOD_HEAD)
{
return "HEAD";
}
return "[error method]";
}
int get_protocol_code(char *str)
{
if (strcmp(str, "HTTP/1.1") == 0)
{
return HTTP_PROTOCOL_HTTP_1;
}
return -1;
}
char *int_to_string(long int n, char *result, int result_length)
{
memset(result, 0, result_length);
sprintf(result, "%ld", n);
return result;
}