]>
git.proxmox.com Git - libgit2.git/blob - src/netops.c
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
11 #include "git2/errors.h"
15 #include "http_parser.h"
18 int gitno_recv(gitno_buffer
*buf
)
20 return buf
->recv(buf
);
23 void gitno_buffer_setup_callback(
27 int (*recv
)(gitno_buffer
*buf
), void *cb_data
)
29 memset(data
, 0x0, len
);
34 buf
->cb_data
= cb_data
;
37 static int recv_stream(gitno_buffer
*buf
)
39 git_stream
*io
= (git_stream
*) buf
->cb_data
;
40 size_t readlen
= buf
->len
- buf
->offset
;
43 readlen
= min(readlen
, INT_MAX
);
45 ret
= git_stream_read(io
, buf
->data
+ buf
->offset
, (int)readlen
);
53 void gitno_buffer_setup_fromstream(git_stream
*st
, gitno_buffer
*buf
, char *data
, size_t len
)
55 memset(data
, 0x0, len
);
59 buf
->recv
= recv_stream
;
63 /* Consume up to ptr and move the rest of the buffer to the beginning */
64 int gitno_consume(gitno_buffer
*buf
, const char *ptr
)
68 GIT_ASSERT(ptr
- buf
->data
>= 0);
69 GIT_ASSERT(ptr
- buf
->data
<= (int) buf
->len
);
71 consumed
= ptr
- buf
->data
;
73 memmove(buf
->data
, ptr
, buf
->offset
- consumed
);
74 memset(buf
->data
+ buf
->offset
, 0x0, buf
->len
- buf
->offset
);
75 buf
->offset
-= consumed
;
80 /* Consume const bytes and move the rest of the buffer to the beginning */
81 void gitno_consume_n(gitno_buffer
*buf
, size_t cons
)
83 memmove(buf
->data
, buf
->data
+ cons
, buf
->len
- buf
->offset
);
84 memset(buf
->data
+ cons
, 0x0, buf
->len
- buf
->offset
);
88 /* Match host names according to RFC 2818 rules */
89 int gitno__match_host(const char *pattern
, const char *host
)
92 char c
= git__tolower(*pattern
++);
95 return *host
? -1 : 0;
99 /* '*' at the end matches everything left */
104 * We've found a pattern, so move towards the next matching
105 * char. The '.' is handled specially because wildcards aren't
106 * allowed to cross subdomains.
110 char h
= git__tolower(*host
);
112 return gitno__match_host(pattern
, host
++);
114 return gitno__match_host(pattern
, host
);
120 if (c
!= git__tolower(*host
++))