- return server_socket;
-}
-
-
-/* Parse HTTP CONNECT request string and save its parameters.
- *
- * The following format is expected: "CONNECT host:port HTTP/1.y".
- *
- * request and host must have the same size! port must be at least 6 bytes
- * long (5 + '\0').
- */
-static int parse_request(const char *request, char *host, char *port,
- int *version_minor) {
- int port_unused; /* just used to verify the port is numeric */
- char *position;
-
- /* scanf() doesn't check spaces. */
- if (0 != strncmp(request, "CONNECT ", 8)) {
- return -1;
- }
- /* Check request and extract data, "host:port" is not yet separated. */
- if (2 != sscanf(request, "CONNECT %s HTTP/1.%d",
- host, version_minor)) {
- return -1;
- }
- /* Make sure ":port" is there. */
- if (NULL == (position = strchr(host, ':'))) {
- return -1;
- }
- /* Make sure port is numeric. */
- if (1 != sscanf(position + 1, "%d", &port_unused)) {
- return -1;
- }
- /* Store it in *port. */
- strncpy(port, position + 1, 5);
- port[5] = '\0';
- /* And remove port from host. */
- *position = '\0';