static int get_header(const char *header, const char *data, size_t data_len, char **value) { size_t len, header_len; header_len = strlen(header); /* loop through headers stopping at first blank line */ while ((len = next_header(&data, &data_len)) != 0) if (len > header_len && strncasecmp(header, data, header_len) == 0) { /* Eat leading whitespace */ while (header_len < len && isblank(data[header_len])) header_len++; *value = malloc(len - header_len + 1); if (*value == NULL) return -4; strncpy(*value, data + header_len, len - header_len); (*value)[len - header_len] = '\0'; return len - header_len; } /* If there is no data left after reading all the headers then we do not * have a complete HTTP request, there must be a blank line */ if (data_len == 0) return -1; return -2; }
/* find a header */ const char *find_header(const char *name) { /* remember the name length */ size_t namelen = strlen(name); /* scan the headers */ for (const char *p = hdrs ; p != 0 ; p = next_header(p)) { /* skip spaces */ for ( ; *p != '\0' && is_space(*p) ; ++p) ; /* check for a match */ if (memicmp(p, name, namelen) == 0) { /* skip the name and any subsequent spaces */ for (p += namelen ; *p != '\0' && is_space(*p) ; ++p) ; /* make sure we have a ':' */ if (*p == ':') { /* skip the ':' and subsequent spaces */ for (p += 1 ; *p != '\0' && is_space(*p) ; ++p) ; /* this is the start of the header value */ return p; } } } /* didn't find it */ return 0; }
static int get_header(const char *header, const char *data, int data_len, char **value) { int len, header_len; header_len = strlen(header); /* loop through headers stopping at first blank line */ while ((len = next_header(&data, &data_len)) != 0) if (len > header_len && strncasecmp(header, data, header_len) == 0) { /* Eat leading whitespace */ while (header_len < len && isblank(data[header_len])) header_len++; *value = malloc(len - header_len + 1); if (*value == NULL) return -4; strncpy(*value, data + header_len, len - header_len); (*value)[len - header_len] = '\0'; return len - header_len; } return -2; }
void IPSecAH::write_serialization(uint8_t* buffer, uint32_t total_sz) { if (inner_pdu()) { next_header(Internals::pdu_flag_to_ip_type(inner_pdu()->pdu_type())); } length(header_size() / sizeof(uint32_t) - 2); OutputMemoryStream output(buffer, total_sz); output.write(header_); output.write(icv_.begin(), icv_.end()); }
IPSecAH::IPSecAH(const uint8_t* buffer, uint32_t total_sz) { InputMemoryStream stream(buffer, total_sz); stream.read(header_); const uint32_t ah_len = 4 * (static_cast<uint16_t>(length()) + 2); if (ah_len < sizeof(header_)) { throw malformed_packet(); } const uint32_t icv_length = ah_len - sizeof(header_); if (!stream.can_read(icv_length)) { throw malformed_packet(); } stream.read(icv_, icv_length); if (stream) { inner_pdu( Internals::pdu_from_flag( static_cast<Constants::IP::e>(next_header()), stream.pointer(), stream.size(), true ) ); } }