19#if defined(_WIN32) || defined(_WIN64)
21#define strncasecmp _strnicmp
31#define NTRIP_VER_AUTO 0
39#define CHUNK_HDR_MAX 16
40#define CHUNK_SIZE_MAX 0xFFFFFF
75 const uint8_t* in = *pin;
79 while (nin > 0 && dec->
state != 3) {
91 unsigned long size = 0;
92 int i, nhex, ndigits = 0;
95 nhex = (dec->
nhdr >= 0) ? dec->
nhdr : (int)strlen(dec->
hdr);
96 for (i = 0; i < nhex; i++) {
99 if (h >=
'0' && h <=
'9') {
101 }
else if (h >=
'a' && h <=
'f') {
103 }
else if (h >=
'A' && h <=
'F') {
108 size = (size << 4) | d;
132 if (dec->
nhdr >= 0) {
133 if ((c >=
'0' && c <=
'9') || (c >=
'a' && c <=
'f') || (c >=
'A' && c <=
'F')) {
142 }
else if (c !=
'\r') {
154 int space = nout - nw;
155 int copy = avail < space ? avail : space;
158 memcpy(out + nw, in, copy);
175 char c = (char)*in++;
190 while (nin > 0 && dec->
state != 3) {
191 char c = (char)*in++;
225static int chunk_encode(uint8_t* out,
int nout,
const uint8_t* data,
int ndata) {
227 int hlen = snprintf(hdr,
sizeof(hdr),
"%x\r\n", ndata);
229 if (hlen <= 0 || hlen >= (
int)
sizeof(hdr)) {
232 if (hlen + ndata + 2 > nout) {
235 memcpy(out, hdr, hlen);
237 memcpy(out + hlen, data, ndata);
239 out[hlen + ndata] =
'\r';
240 out[hlen + ndata + 1] =
'\n';
241 return hlen + ndata + 2;
249static const char*
stristr(
const char* haystack,
const char* needle) {
250 int nlen = (int)strlen(needle);
254 for (; *haystack; haystack++) {
255 if (strncasecmp(haystack, needle, nlen) == 0) {
269 for (i = 0; i <= nb - 4; i++) {
270 if (buff[i] ==
'\r' && buff[i + 1] ==
'\n' && buff[i + 2] ==
'\r' && buff[i + 3] ==
'\n') {
284 if (strncmp((
const char*)buff,
"HTTP/", 5) != 0) {
288 for (i = 5; i < nb; i++) {
289 if (buff[i] ==
' ') {
293 if (buff[i + 1] >=
'0' && buff[i + 1] <=
'9' && buff[i + 2] >=
'0' && buff[i + 2] <=
'9' &&
294 buff[i + 3] >=
'0' && buff[i + 3] <=
'9') {
295 return (buff[i + 1] -
'0') * 100 + (buff[i + 2] -
'0') * 10 + (buff[i + 3] -
'0');
305static int http_find_header(
const uint8_t* buff,
int nb,
const char* name,
char* val,
int vmax) {
306 int nlen = (int)strlen(name);
307 const char* p = (
const char*)buff;
308 const char* end = p + nb;
312 if (p + nlen + 1 <= end && strncasecmp(p, name, nlen) == 0 && p[nlen] ==
':') {
313 const char* v = p + nlen + 1;
316 while (v < end && (*v ==
' ' || *v ==
'\t')) {
320 while (v < end && *v !=
'\r' && *v !=
'\n' && i < vmax - 1) {
327 while (p < end && *p !=
'\n') {
static int chunk_decode(chunk_dec_t *dec, const uint8_t **pin, int *pnin, uint8_t *out, int nout)
static int http_find_header(const uint8_t *buff, int nb, const char *name, char *val, int vmax)
static const char * stristr(const char *haystack, const char *needle)
static int http_header_end(const uint8_t *buff, int nb)
static int chunk_encode(uint8_t *out, int nout, const uint8_t *data, int ndata)
static void chunk_dec_init(chunk_dec_t *dec)
static int http_status_code(const uint8_t *buff, int nb)