src/siri/admin/client.c
/*
 * Initializes a request for a new pool or replica and returns 0 when
 * successful. In case of an error, err_msg will be set and a value other than
 * 0 is returned. (a signal can be raised.) When successful and only when
 * successful, a response will be send to the provided client using the given
 * pid.
 */
Initializes a request for a new pool or replica and returns 0 when
successful. In case of an error, err_msg will be set and a value other than
0 is returned. (a signal can be raised.) When successful and only when
successful, a response will be send to the provided client using the given
pid.
Initializes a request for a new pool or replica and returns 0 when successful . In case of an error err_msg will be set and a value other than 0 is returned . ( a signal can be raised . ) When successful and only when successful a response will be send to the provided client using the given pid .
int siri_admin_client_request(
        uint16_t pid,
        uint16_t port,
        int pool,
        uuid_t * uuid,
        qp_obj_t * host,
        qp_obj_t * username,
        qp_obj_t * password,
        qp_obj_t * dbname,
        const char * dbpath,
        uv_stream_t * client,
        char * err_msg)
{
    sirinet_socket_t * ssocket;
    siri_admin_client_t * adm_client;
    struct in_addr sa;
    struct in6_addr sa6;
    if (siri.socket != NULL)
    {
        sprintf(err_msg, "manage socket already in use");
        return -1;
    }
    siri.socket = sirinet_socket_new(SOCKET_MANAGE, &CLIENT_on_data);
    if (siri.socket == NULL)
    {
        sprintf(err_msg, "memory allocation error");
        return -1;
    }
    uv_tcp_init(siri.loop, siri.socket);
    adm_client = (siri_admin_client_t *) malloc(sizeof(siri_admin_client_t));
    if (adm_client == NULL)
    {
        sirinet_socket_decref(siri.socket);
        sprintf(err_msg, "memory allocation error");
        return -1;
    }
    adm_client->pid = pid;
    adm_client->port = port;
    adm_client->host = strndup(
            (const char *) host->via.raw, host->len);
    adm_client->username = strndup(
            (const char *) username->via.raw, username->len);
    adm_client->password = strndup(
            (const char *) password->via.raw, password->len);
    adm_client->dbname = strndup(
            (const char *) dbname->via.raw, dbname->len);
    adm_client->dbpath = strdup(dbpath);
    adm_client->client = client;
    adm_client->request = CLIENT_REQUEST_INIT;
    adm_client->flags = 0;
    adm_client->pool = pool;
    memcpy(&adm_client->uuid, uuid, 16);
    ssocket = (sirinet_socket_t *) siri.socket->data;
    ssocket->origin = (void *) adm_client;
    sirinet_socket_incref(adm_client->client);
    if (adm_client->host == NULL ||
        adm_client->username == NULL ||
        adm_client->password == NULL ||
        adm_client->dbname == NULL ||
        adm_client->dbpath == NULL)
    {
        sirinet_socket_decref(siri.socket);
        sprintf(err_msg, "memory allocation error");
        return -1;
    }
    if (inet_pton(AF_INET, adm_client->host, &sa))
    {
        struct sockaddr_in dest;
        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
        if (req == NULL)
        {
            sirinet_socket_decref(siri.socket);
            sprintf(err_msg, "memory allocation error");
            return -1;
        }
        log_debug(
                "Trying to connect to '%s:%u'...",
                adm_client->host,
                adm_client->port);
        uv_ip4_addr(adm_client->host, adm_client->port, &dest);
        uv_tcp_connect(
                req,
                siri.socket,
                (const struct sockaddr *) &dest,
                CLIENT_on_connect);
    }
    else if (inet_pton(AF_INET6, adm_client->host, &sa6))
    {
        struct sockaddr_in6 dest6;
        uv_connect_t * req = (uv_connect_t *) malloc(sizeof(uv_connect_t));
        if (req == NULL)
        {
            sirinet_socket_decref(siri.socket);
            sprintf(err_msg, "memory allocation error");
            return -1;
        }
        log_debug(
                "Trying to connect to '%s:%u'...",
                adm_client->host,
                adm_client->port);
        uv_ip6_addr(adm_client->host, adm_client->port, &dest6);
        uv_tcp_connect(
                req,
                siri.socket,
                (const struct sockaddr *) &dest6,
                CLIENT_on_connect);
    }
    else
    {
        if (CLIENT_resolve_dns(
                adm_client,
                dns_req_family_map[siri.cfg->ip_support],
                err_msg))
        {
            sirinet_socket_decref(siri.socket);
            return -1;  
        }
    }
    uv_timer_init(siri.loop, &siri.timer);
    return 0;
}
int siri_admin_client_request ( uint16_t pid , uint16_t port , int pool , uuid_t * uuid , qp_obj_t * host , qp_obj_t * username , qp_obj_t * password , qp_obj_t * dbname , const char * dbpath , uv_stream_t * client , char * err_msg ) { sirinet_socket_t * ssocket ; siri_admin_client_t * adm_client ; struct in_addr sa ; struct in6_addr sa6 ; if ( siri . socket != NULL ) { sprintf ( err_msg , " " ) ; return -1 ; } siri . socket = sirinet_socket_new ( SOCKET_MANAGE , & CLIENT_on_data ) ; if ( siri . socket == NULL ) { sprintf ( err_msg , " " ) ; return -1 ; } uv_tcp_init ( siri . loop , siri . socket ) ; adm_client = ( siri_admin_client_t * ) malloc ( sizeof ( siri_admin_client_t ) ) ; if ( adm_client == NULL ) { sirinet_socket_decref ( siri . socket ) ; sprintf ( err_msg , " " ) ; return -1 ; } adm_client -> pid = pid ; adm_client -> port = port ; adm_client -> host = strndup ( ( const char * ) host -> via . raw , host -> len ) ; adm_client -> username = strndup ( ( const char * ) username -> via . raw , username -> len ) ; adm_client -> password = strndup ( ( const char * ) password -> via . raw , password -> len ) ; adm_client -> dbname = strndup ( ( const char * ) dbname -> via . raw , dbname -> len ) ; adm_client -> dbpath = strdup ( dbpath ) ; adm_client -> client = client ; adm_client -> request = CLIENT_REQUEST_INIT ; adm_client -> flags = 0 ; adm_client -> pool = pool ; memcpy ( & adm_client -> uuid , uuid , 16 ) ; ssocket = ( sirinet_socket_t * ) siri . socket -> data ; ssocket -> origin = ( void * ) adm_client ; sirinet_socket_incref ( adm_client -> client ) ; if ( adm_client -> host == NULL || adm_client -> username == NULL || adm_client -> password == NULL || adm_client -> dbname == NULL || adm_client -> dbpath == NULL ) { sirinet_socket_decref ( siri . socket ) ; sprintf ( err_msg , " " ) ; return -1 ; } if ( inet_pton ( AF_INET , adm_client -> host , & sa ) ) { struct sockaddr_in dest ; uv_connect_t * req = ( uv_connect_t * ) malloc ( sizeof ( uv_connect_t ) ) ; if ( req == NULL ) { sirinet_socket_decref ( siri . socket ) ; sprintf ( err_msg , " " ) ; return -1 ; } log_debug ( " " , adm_client -> host , adm_client -> port ) ; uv_ip4_addr ( adm_client -> host , adm_client -> port , & dest ) ; uv_tcp_connect ( req , siri . socket , ( const struct sockaddr * ) & dest , CLIENT_on_connect ) ; } else if ( inet_pton ( AF_INET6 , adm_client -> host , & sa6 ) ) { struct sockaddr_in6 dest6 ; uv_connect_t * req = ( uv_connect_t * ) malloc ( sizeof ( uv_connect_t ) ) ; if ( req == NULL ) { sirinet_socket_decref ( siri . socket ) ; sprintf ( err_msg , " " ) ; return -1 ; } log_debug ( " " , adm_client -> host , adm_client -> port ) ; uv_ip6_addr ( adm_client -> host , adm_client -> port , & dest6 ) ; uv_tcp_connect ( req , siri . socket , ( const struct sockaddr * ) & dest6 , CLIENT_on_connect ) ; } else { if ( CLIENT_resolve_dns ( adm_client , dns_req_family_map [ siri . cfg -> ip_support ] , err_msg ) ) { sirinet_socket_decref ( siri . socket ) ; return -1 ; } } uv_timer_init ( siri . loop , & siri . timer ) ; return 0 ; }
Initializes a request for a new pool or replica and returns 0 when
 successful.
Initializes a request for a new pool or replica and returns 0 when successful .
/* IPv4 */ /* IPv6 */ /* err_msg is set */