line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
/* |
2
|
|
|
|
|
|
|
* Copyright (C) the libgit2 contributors. All rights reserved. |
3
|
|
|
|
|
|
|
* |
4
|
|
|
|
|
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with |
5
|
|
|
|
|
|
|
* a Linking Exception. For full terms see the included COPYING file. |
6
|
|
|
|
|
|
|
*/ |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#include "netops.h" |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
#include |
11
|
|
|
|
|
|
|
#include "git2/errors.h" |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#include "posix.h" |
14
|
|
|
|
|
|
|
#include "buffer.h" |
15
|
|
|
|
|
|
|
#include "http_parser.h" |
16
|
|
|
|
|
|
|
#include "global.h" |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
int gitno_recv(gitno_buffer *buf) |
19
|
|
|
|
|
|
|
{ |
20
|
0
|
|
|
|
|
|
return buf->recv(buf); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
void gitno_buffer_setup_callback( |
24
|
|
|
|
|
|
|
gitno_buffer *buf, |
25
|
|
|
|
|
|
|
char *data, |
26
|
|
|
|
|
|
|
size_t len, |
27
|
|
|
|
|
|
|
int (*recv)(gitno_buffer *buf), void *cb_data) |
28
|
|
|
|
|
|
|
{ |
29
|
0
|
|
|
|
|
|
memset(data, 0x0, len); |
30
|
0
|
|
|
|
|
|
buf->data = data; |
31
|
0
|
|
|
|
|
|
buf->len = len; |
32
|
0
|
|
|
|
|
|
buf->offset = 0; |
33
|
0
|
|
|
|
|
|
buf->recv = recv; |
34
|
0
|
|
|
|
|
|
buf->cb_data = cb_data; |
35
|
0
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
static int recv_stream(gitno_buffer *buf) |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
|
|
|
git_stream *io = (git_stream *) buf->cb_data; |
40
|
0
|
|
|
|
|
|
size_t readlen = buf->len - buf->offset; |
41
|
|
|
|
|
|
|
ssize_t ret; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
readlen = min(readlen, INT_MAX); |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
ret = git_stream_read(io, buf->data + buf->offset, (int)readlen); |
46
|
0
|
0
|
|
|
|
|
if (ret < 0) |
47
|
0
|
|
|
|
|
|
return -1; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
buf->offset += ret; |
50
|
0
|
|
|
|
|
|
return (int)ret; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
void gitno_buffer_setup_fromstream(git_stream *st, gitno_buffer *buf, char *data, size_t len) |
54
|
|
|
|
|
|
|
{ |
55
|
0
|
|
|
|
|
|
memset(data, 0x0, len); |
56
|
0
|
|
|
|
|
|
buf->data = data; |
57
|
0
|
|
|
|
|
|
buf->len = len; |
58
|
0
|
|
|
|
|
|
buf->offset = 0; |
59
|
0
|
|
|
|
|
|
buf->recv = recv_stream; |
60
|
0
|
|
|
|
|
|
buf->cb_data = st; |
61
|
0
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
/* Consume up to ptr and move the rest of the buffer to the beginning */ |
64
|
0
|
|
|
|
|
|
void gitno_consume(gitno_buffer *buf, const char *ptr) |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
size_t consumed; |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
assert(ptr - buf->data >= 0); |
69
|
0
|
0
|
|
|
|
|
assert(ptr - buf->data <= (int) buf->len); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
consumed = ptr - buf->data; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
memmove(buf->data, ptr, buf->offset - consumed); |
74
|
0
|
|
|
|
|
|
memset(buf->data + buf->offset, 0x0, buf->len - buf->offset); |
75
|
0
|
|
|
|
|
|
buf->offset -= consumed; |
76
|
0
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
/* Consume const bytes and move the rest of the buffer to the beginning */ |
79
|
0
|
|
|
|
|
|
void gitno_consume_n(gitno_buffer *buf, size_t cons) |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
|
|
|
memmove(buf->data, buf->data + cons, buf->len - buf->offset); |
82
|
0
|
|
|
|
|
|
memset(buf->data + cons, 0x0, buf->len - buf->offset); |
83
|
0
|
|
|
|
|
|
buf->offset -= cons; |
84
|
0
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
/* Match host names according to RFC 2818 rules */ |
87
|
0
|
|
|
|
|
|
int gitno__match_host(const char *pattern, const char *host) |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
for (;;) { |
90
|
0
|
|
|
|
|
|
char c = git__tolower(*pattern++); |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if (c == '\0') |
93
|
0
|
0
|
|
|
|
|
return *host ? -1 : 0; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
if (c == '*') { |
96
|
0
|
|
|
|
|
|
c = *pattern; |
97
|
|
|
|
|
|
|
/* '*' at the end matches everything left */ |
98
|
0
|
0
|
|
|
|
|
if (c == '\0') |
99
|
0
|
|
|
|
|
|
return 0; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
/* |
102
|
|
|
|
|
|
|
* We've found a pattern, so move towards the next matching |
103
|
|
|
|
|
|
|
* char. The '.' is handled specially because wildcards aren't |
104
|
|
|
|
|
|
|
* allowed to cross subdomains. |
105
|
|
|
|
|
|
|
*/ |
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
while(*host) { |
108
|
0
|
|
|
|
|
|
char h = git__tolower(*host); |
109
|
0
|
0
|
|
|
|
|
if (c == h) |
110
|
0
|
|
|
|
|
|
return gitno__match_host(pattern, host++); |
111
|
0
|
0
|
|
|
|
|
if (h == '.') |
112
|
0
|
|
|
|
|
|
return gitno__match_host(pattern, host); |
113
|
0
|
|
|
|
|
|
host++; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
return -1; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
0
|
0
|
|
|
|
|
if (c != git__tolower(*host++)) |
119
|
0
|
|
|
|
|
|
return -1; |
120
|
0
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
return -1; |
123
|
|
|
|
|
|
|
} |