Beispiel #1
0
/* wrapper function for auth thread to authenticate new listener
 * connection details
 */
static void auth_new_listener (auth_client *auth_user)
{
    client_t *client = auth_user->client;

    /* make sure there is still a client at this point, a slow backend request
     * can be avoided if client has disconnected */
    if (allow_auth == 0 || client_connected (client) == 0)
    {
        DEBUG0 ("dropping listener connection");
        client->respcode = 400;
        return;
    }
    if (auth_user->auth->authenticate)
    {
        switch (auth_user->auth->authenticate (auth_user))
        {
            case AUTH_OK:
            case AUTH_FAILED:
                break;
            default:
                return;
        }
    }
    auth_postprocess_listener (auth_user);
}
Beispiel #2
0
void client_outmessage (enum outmsg_type msgtype, char *str)
{
    char buf[1024];
    GTET_O_STRCPY(buf, outmsg_translate (msgtype));
    if (str) {
        GTET_O_STRCAT(buf, " ");
        GTET_O_STRCAT(buf, str);
    }
    switch (msgtype)
    {
      case OUT_DISCONNECT : client_disconnect (); break;
      case OUT_CONNECTED : client_connected (); break;
      default : client_sendmsg (buf);
    }
}
/**
	@brief Read and process available transport_messages for a transport_client.
	@param client Pointer to the transport_client whose socket is to be read.
	@param timeout How many seconds to wait for the first message.
	@param msg_received A pointer through which to report whether a message was received.
	@return 0 upon success (even if a timeout occurs), or -1 upon failure.

	Read and process all available transport_messages from the socket of the specified
	transport_client.  Pass each one through osrf_stack_transport().

	The timeout applies only to the first message.  Any subsequent messages must be
	available immediately.  Don't wait for them, even if the timeout has not expired.  In
	theory, a sufficiently large backlog of input messages could keep you working past the
	nominal expiration of the timeout.

	The @a msg_received parameter points to an int owned by the calling code and used as
	a boolean.  Set it to true if you receive at least one transport_message, or to false
	if you don't.  A timeout is not treated as an error; it just means you must set that
	boolean to false.
*/
int osrf_stack_process( transport_client* client, int timeout, int* msg_received ) {
	if( !client ) return -1;
	transport_message* msg = NULL;
	if(msg_received) *msg_received = 0;

	// Loop through the available input messages
	while( (msg = client_recv( client, timeout )) ) {
		if(msg_received) *msg_received = 1;
		osrfLogDebug( OSRF_LOG_MARK, "Received message from transport code from %s", msg->sender );
		osrf_stack_transport_handler( msg, NULL );
		timeout = 0;
	}

	if( client->error ) {
		osrfLogWarning(OSRF_LOG_MARK, "transport_client had trouble reading from the socket..");
		return -1;
	}

	if( ! client_connected( client ) ) return -1;

	return 0;
}
Beispiel #4
0
void Server::check_for_new_connections() {
	if (m_state != STARTED) {
		printf("Trying to call check_new_connections() while the server isn't ready. STATE was %d\n", m_state);
		return;
	}

	SOCKET client_socket;
	client_socket = INVALID_SOCKET;
	// Accept a client socket
	client_socket = accept(m_listen_socket, NULL, NULL);
	if (client_socket == INVALID_SOCKET) {
		int error_code = WSAGetLastError();
		if (error_code == WSAEWOULDBLOCK) {
					
			return;
		} else {
			printf("accept failed: %d\n", error_code);
			m_state = IN_ERROR_STATE;
			return;
		}
	} else {
		client_connected(client_socket);
	}
}
Beispiel #5
0
void client_destroy(client_t *client)
{
    if (client == NULL)
        return;

    if (client->worker)
    {
        WARN0 ("client still on worker thread");
        return;
    }
    /* release the buffer now, as the buffer could be on the source queue
     * and may of disappeared after auth completes */
    if (client->refbuf)
    {
        refbuf_release (client->refbuf);
        client->refbuf = NULL;
    }

    if (client->flags & CLIENT_AUTHENTICATED)
        DEBUG1 ("client still in auth \"%s\"", httpp_getvar (client->parser, HTTPP_VAR_URI));

    /* write log entry if ip is set (some things don't set it, like outgoing 
     * slave requests
     */
    if (client->respcode > 0 && client->parser)
        logging_access(client);

    if (client->flags & CLIENT_IP_BAN_LIFT)
    {
        INFO1 ("lifting IP ban on client at %s", client->connection.ip);
        connection_release_banned_ip (client->connection.ip);
        client->flags &= ~CLIENT_IP_BAN_LIFT;
    }

    if (client->parser)
        httpp_destroy (client->parser);

    /* we need to free client specific format data (if any) */
    if (client->free_client_data)
        client->free_client_data (client);

    free(client->username);
    free(client->password);
    client->username = NULL;
    client->password = NULL;
    client->parser = NULL;
    client->respcode = 0;
    client->free_client_data = NULL;

    global_lock ();
    if (global.running != ICE_RUNNING || client->connection.error ||
            (client->flags & CLIENT_KEEPALIVE) == 0 || client_connected (client) == 0)
    {
        global.clients--;
        stats_event_args (NULL, "clients", "%d", global.clients);
        config_clear_listener (client->server_conn);
        global_unlock ();
        connection_close (&client->connection);

        free(client);
        return;
    }
    global_unlock ();
    DEBUG0 ("keepalive detected, placing back onto worker");
    client->counter = client->schedule_ms = timing_get_time();
    client->connection.con_time = client->schedule_ms/1000;
    client->connection.discon.time = client->connection.con_time + 7;
    client->ops = &http_request_ops;
    client->flags = CLIENT_ACTIVE;
    client->shared_data = NULL;
    client->refbuf = NULL;
    client->pos = 0;
    client->intro_offset = client->connection.sent_bytes = 0;
    client_add_worker (client);
}