deps/libgit2/src/libgit2/netops.c

filter: Statementstmt 0.0% 0 / 59 Branchbran 0.0% 0 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 81 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« deps/libgit2/src/libgit2/fetchhead.c ↑ Summary deps/libgit2/src/libgit2/reader.c »
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 <ctype.h>
11 #include "git2/errors.h"
12  
13 #include "posix.h"
14 #include "str.h"
15 #include "runtime.h"
16  
17 0 int gitno_recv(gitno_buffer *buf)
18 {
19 0 return buf->recv(buf);
20 }
21  
22 0 void gitno_buffer_setup_callback(
23 gitno_buffer *buf,
24 char *data,
25 size_t len,
26 int (*recv)(gitno_buffer *buf), void *cb_data)
27 {
28 0 memset(data, 0x0, len);
29 0 buf->data = data;
30 0 buf->len = len;
31 0 buf->offset = 0;
32 0 buf->recv = recv;
33 0 buf->cb_data = cb_data;
34 0 }
35  
36 0 static int recv_stream(gitno_buffer *buf)
37 {
38 0 git_stream *io = (git_stream *) buf->cb_data;
39 0 size_t readlen = buf->len - buf->offset;
40 ssize_t ret;
41  
42 0 readlen = min(readlen, INT_MAX);
43  
44 0 ret = git_stream_read(io, buf->data + buf->offset, (int)readlen);
45 0 ▶ if (ret < 0)
Branch: 1 branch
BranchTrueFalseTotal
if (ret < 0) 0 0 0
46 0 return -1;
47  
48 0 buf->offset += ret;
49 0 return (int)ret;
50 }
51  
52 0 void gitno_buffer_setup_fromstream(git_stream *st, gitno_buffer *buf, char *data, size_t len)
53 {
54 0 memset(data, 0x0, len);
55 0 buf->data = data;
56 0 buf->len = len;
57 0 buf->offset = 0;
58 0 buf->recv = recv_stream;
59 0 buf->cb_data = st;
60 0 }
61  
62 /* Consume up to ptr and move the rest of the buffer to the beginning */
63 0 int gitno_consume(gitno_buffer *buf, const char *ptr)
64 {
65 size_t consumed;
66  
67 0 ▶ GIT_ASSERT(ptr - buf->data >= 0);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT(ptr - buf->data >= 0); 0 0 0
68 0 ▶ GIT_ASSERT(ptr - buf->data <= (int) buf->len);
Branch: 1 branch
BranchTrueFalseTotal
GIT_ASSERT(ptr - buf->data <= (int) buf->len); 0 0 0
69  
70 0 consumed = ptr - buf->data;
71  
72 0 memmove(buf->data, ptr, buf->offset - consumed);
73 0 memset(buf->data + buf->offset, 0x0, buf->len - buf->offset);
74 0 buf->offset -= consumed;
75  
76 0 return 0;
77 }
78  
79 /* Consume const bytes and move the rest of the buffer to the beginning */
80 0 void gitno_consume_n(gitno_buffer *buf, size_t cons)
81 {
82 0 memmove(buf->data, buf->data + cons, buf->len - buf->offset);
83 0 memset(buf->data + cons, 0x0, buf->len - buf->offset);
84 0 buf->offset -= cons;
85 0 }
86  
87 /* Match host names according to RFC 2818 rules */
88 0 int gitno__match_host(const char *pattern, const char *host)
89 {
90 0 for (;;) {
91 0 char c = git__tolower(*pattern++);
92  
93 0 ▶ if (c == '\0')
Branch: 1 branch
BranchTrueFalseTotal
if (c == '\0') 0 0 0
94 0 ▶ return *host ? -1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
return *host ? -1 : 0; 0 0 0
95  
96 0 ▶ if (c == '*') {
Branch: 1 branch
BranchTrueFalseTotal
if (c == '*') { 0 0 0
97 0 c = *pattern;
98 /* '*' at the end matches everything left */
99 0 ▶ if (c == '\0')
Branch: 1 branch
BranchTrueFalseTotal
if (c == '\0') 0 0 0
100 0 return 0;
101  
102 /*
103 * We've found a pattern, so move towards the next matching
104 * char. The '.' is handled specially because wildcards aren't
105 * allowed to cross subdomains.
106 */
107  
108 0 ▶ while(*host) {
Branch: 1 branch
BranchTrueFalseTotal
while(*host) { 0 0 0
109 0 char h = git__tolower(*host);
110 0 ▶ if (c == h)
Branch: 1 branch
BranchTrueFalseTotal
if (c == h) 0 0 0
111 0 return gitno__match_host(pattern, host++);
112 0 ▶ if (h == '.')
Branch: 1 branch
BranchTrueFalseTotal
if (h == '.') 0 0 0
113 0 return gitno__match_host(pattern, host);
114 0 host++;
115 }
116 0 return -1;
117 }
118  
119 0 ▶ if (c != git__tolower(*host++))
Branch: 1 branch
BranchTrueFalseTotal
if (c != git__tolower(*host++)) 0 0 0
120 0 return -1;
121 }
122  
123 return -1;
124 }
« deps/libgit2/src/libgit2/fetchhead.c ↑ Summary deps/libgit2/src/libgit2/reader.c »