src/siri/admin/client.c
/*
 * Called when 'list servers ...' response is received.
 * This function will check if each current server has status running.
 * (this is a pre-check, the final register call does check for all servers
 * to have the running status once more)
 */
Called when 'list servers ...' response is received.
This function will check if each current server has status running.
(this is a pre-check, the final register call does check for all servers
to have the running status once more)
Called when ' list servers ... ' response is received . This function will check if each current server has status running . ( this is a pre - check the final register call does check for all servers to have the running status once more )
static void CLIENT_on_request_status(
        siri_admin_client_t * adm_client,
        sirinet_pkg_t * pkg)
{
    qp_unpacker_t unpacker;
    qp_unpacker_init(&unpacker, pkg->data, pkg->len);
    qp_obj_t qp_val;
    qp_obj_t qp_name;
    qp_obj_t qp_status;
    qp_obj_t qp_version;
    int columns_found = 0;
    int servers_found = 0;
    char version[MAX_VERSION_LEN];
    if (!qp_is_map(qp_next(&unpacker, NULL)))
    {
        CLIENT_err(adm_client, "invalid server status response");
        return;
    }
    qp_next(&unpacker, &qp_val);
    while (qp_val.tp == QP_RAW)
    {
        if (    strncmp(
                    (const char *) qp_val.via.raw,
                    "columns",
                    qp_val.len) == 0 &&
                qp_is_array(qp_next(&unpacker, NULL)) &&
                qp_next(&unpacker, &qp_val) == QP_RAW &&
                strncmp(
                    (const char *) qp_val.via.raw, "name", qp_val.len) == 0 &&
                qp_next(&unpacker, &qp_val) == QP_RAW &&
                strncmp(
                    (const char *) qp_val.via.raw,
                    "status",
                    qp_val.len) == 0 &&
                qp_next(&unpacker, &qp_val) == QP_RAW &&
                strncmp(
                    (const char *) qp_val.via.raw, "version", qp_val.len) == 0)
        {
            if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
            {
                qp_next(&unpacker, &qp_val);
            }
            columns_found = 1;
            continue;
        }
        if (    strncmp(
                    (const char *) qp_val.via.raw,
                    "servers",
                    qp_val.len) == 0 &&
                qp_is_array(qp_next(&unpacker, NULL)))
        {
            qp_next(&unpacker, &qp_val);
            while (qp_is_array(qp_val.tp))
            {
                if (qp_next(&unpacker, &qp_name) == QP_RAW &&
                    qp_next(&unpacker, &qp_status) == QP_RAW &&
                    qp_next(&unpacker, &qp_version) == QP_RAW &&
                    qp_version.len < MAX_VERSION_LEN)
                {
                    memcpy(version, qp_version.via.raw, qp_version.len);
                    version[qp_version.len] = '\0';
                    if (siri_version_cmp(version, SIRIDB_VERSION))
                    {
                        CLIENT_err(
                                adm_client,
                                "server '%.*s' is running on version %s "
                                "while version %s is expected. (all SiriBD "
                                "servers should run the same version)",
                                (int) qp_name.len,
                                qp_name.via.raw,
                                version,
                                SIRIDB_VERSION);
                        return;
                    }
                    if (strncmp(
                            (const char *) qp_status.via.raw,
                            "running",
                            qp_status.len) != 0)
                    {
                        CLIENT_err(
                                adm_client,
                                "server '%.*s' has status: '%.*s'",
                                (int) qp_name.len,
                                qp_name.via.raw,
                                (int) qp_status.len,
                                qp_status.via.raw);
                        return;
                    }
                    servers_found++;
                }
                else
                {
                    CLIENT_err(adm_client, "invalid server status response");
                    return;
                }
                if (qp_next(&unpacker, &qp_val) == QP_ARRAY_CLOSE)
                {
                    qp_next(&unpacker, &qp_val);
                }
            }
            if (qp_val.tp == QP_ARRAY_CLOSE)
            {
                qp_next(&unpacker, &qp_val);
            }
            continue;
        }
        CLIENT_err(adm_client, "invalid server status response");
        return;
    }
    if (!servers_found || !columns_found)
    {
        CLIENT_err(adm_client, "invalid server status response");
    }
    else
    {
        sirinet_pkg_t * package;
        qp_packer_t * packer = sirinet_packer_new(512);
        if (packer == NULL)
        {
            CLIENT_err(adm_client, "memory allocation error");
        }
        else
        {
            adm_client->request = CLIENT_REQUEST_POOLS;
            qp_add_type(packer, QP_ARRAY1);
            qp_add_string(packer, "list pools pool, servers");
            package = sirinet_packer2pkg(packer, 0, CPROTO_REQ_QUERY);
            CLIENT_send_pkg(adm_client, package);
        }
    }
}
static void CLIENT_on_request_status ( siri_admin_client_t * adm_client , sirinet_pkg_t * pkg ) { qp_unpacker_t unpacker ; qp_unpacker_init ( & unpacker , pkg -> data , pkg -> len ) ; qp_obj_t qp_val ; qp_obj_t qp_name ; qp_obj_t qp_status ; qp_obj_t qp_version ; int columns_found = 0 ; int servers_found = 0 ; char version [ MAX_VERSION_LEN ] ; if ( ! qp_is_map ( qp_next ( & unpacker , NULL ) ) ) { CLIENT_err ( adm_client , " " ) ; return ; } qp_next ( & unpacker , & qp_val ) ; while ( qp_val . tp == QP_RAW ) { if ( strncmp ( ( const char * ) qp_val . via . raw , " " , qp_val . len ) == 0 && qp_is_array ( qp_next ( & unpacker , NULL ) ) && qp_next ( & unpacker , & qp_val ) == QP_RAW && strncmp ( ( const char * ) qp_val . via . raw , " " , qp_val . len ) == 0 && qp_next ( & unpacker , & qp_val ) == QP_RAW && strncmp ( ( const char * ) qp_val . via . raw , " " , qp_val . len ) == 0 && qp_next ( & unpacker , & qp_val ) == QP_RAW && strncmp ( ( const char * ) qp_val . via . raw , " " , qp_val . len ) == 0 ) { if ( qp_next ( & unpacker , & qp_val ) == QP_ARRAY_CLOSE ) { qp_next ( & unpacker , & qp_val ) ; } columns_found = 1 ; continue ; } if ( strncmp ( ( const char * ) qp_val . via . raw , " " , qp_val . len ) == 0 && qp_is_array ( qp_next ( & unpacker , NULL ) ) ) { qp_next ( & unpacker , & qp_val ) ; while ( qp_is_array ( qp_val . tp ) ) { if ( qp_next ( & unpacker , & qp_name ) == QP_RAW && qp_next ( & unpacker , & qp_status ) == QP_RAW && qp_next ( & unpacker , & qp_version ) == QP_RAW && qp_version . len < MAX_VERSION_LEN ) { memcpy ( version , qp_version . via . raw , qp_version . len ) ; version [ qp_version . len ] = ' \0 ' ; if ( siri_version_cmp ( version , SIRIDB_VERSION ) ) { CLIENT_err ( adm_client , " " " " " " , ( int ) qp_name . len , qp_name . via . raw , version , SIRIDB_VERSION ) ; return ; } if ( strncmp ( ( const char * ) qp_status . via . raw , " " , qp_status . len ) != 0 ) { CLIENT_err ( adm_client , " " , ( int ) qp_name . len , qp_name . via . raw , ( int ) qp_status . len , qp_status . via . raw ) ; return ; } servers_found ++ ; } else { CLIENT_err ( adm_client , " " ) ; return ; } if ( qp_next ( & unpacker , & qp_val ) == QP_ARRAY_CLOSE ) { qp_next ( & unpacker , & qp_val ) ; } } if ( qp_val . tp == QP_ARRAY_CLOSE ) { qp_next ( & unpacker , & qp_val ) ; } continue ; } CLIENT_err ( adm_client , " " ) ; return ; } if ( ! servers_found || ! columns_found ) { CLIENT_err ( adm_client , " " ) ; } else { sirinet_pkg_t * package ; qp_packer_t * packer = sirinet_packer_new ( 512 ) ; if ( packer == NULL ) { CLIENT_err ( adm_client , " " ) ; } else { adm_client -> request = CLIENT_REQUEST_POOLS ; qp_add_type ( packer , QP_ARRAY1 ) ; qp_add_string ( packer , " " ) ; package = sirinet_packer2pkg ( packer , 0 , CPROTO_REQ_QUERY ) ; CLIENT_send_pkg ( adm_client , package ) ; } } }
Called when 'list servers ...' response is received.
Called when ' list servers ... ' response is received .
/* copy and null terminate version */ /* no need to check since this will always fit */