FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

GitHub Viewer

/* This file is part of libhttpserver Copyright (C) 2011 Sebastiano Merlino This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "string_utilities.hpp" #include "http_utils.hpp" #pragma GCC diagnostic ignored "-Warray-bounds" #define CHECK_BIT(var,pos) ((var) & (1sin_port; case AF_INET6: return ((struct sockaddr_in *)sa)->sin_port; default: return 0; } } size_t http_unescape (char *val) { char *rpos = val; char *wpos = val; unsigned int num; while ('\0' != *rpos) { switch (*rpos) { case '+': *wpos = ' '; wpos++; rpos++; break; case '%': if ( (1 == sscanf (&rpos[1], "%2x", &num)) || (1 == sscanf (&rpos[1], "%2X", &num)) ) { *wpos = (unsigned char) num; wpos++; rpos += 3; break; } /* intentional fall through! */ default: *wpos = *rpos; wpos++; rpos++; } } *wpos = '\0'; /* add 0-terminator */ return wpos - val; /* = strlen(val) */ } ip_representation::ip_representation(const struct sockaddr* ip) { std::fill(pieces, pieces + 16, 0); if(ip->sa_family == AF_INET) { ip_version = http_utils::IPV4; for(int i=0;isin_addr))[i]; } } else { ip_version = http_utils::IPV6; for(int i=0;isin6_addr))[i] + 16 * ((u_char*)&(((struct sockaddr_in6 *)ip)->sin6_addr))[i+1]; } } mask = DEFAULT_MASK_VALUE; } ip_representation::ip_representation(const std::string& ip) { std::vector parts; mask = DEFAULT_MASK_VALUE; std::fill(pieces, pieces + 16, 0); if(ip.find(':') != std::string::npos) //IPV6 { ip_version = http_utils::IPV6; string_utilities::string_split(ip, parts, ':', false); int y = 0; for(unsigned int i = 0; i < parts.size(); i++) { if(parts[i] != "*" && parts[i] != "") { if(parts[i].size() < 4) { stringstream ss; ss pieces[i] < b.pieces[i]) { return true; } } return false; } size_t load_file (const char* filename, char** content) { ifstream fp(filename, ios::in | ios::binary | ios::ate); if(fp.is_open()) { int size = fp.tellg(); *content = (char*) malloc(size * sizeof(char)); fp.seekg(0, ios::beg); fp.read(*content, size); fp.close(); return size; } return 0; } char* load_file (const char *filename) { char* content = NULL; load_file(filename, &content); return content; } }; };

Back | FazBrowse Home | New Git URL