Skip to content
Jiri Hnidek edited this page Jul 8, 2014 · 8 revisions

New Verse API

C API is divided into four parts:

  • Basic Functions These functions are required for connection/disconnection to Verse server. Note: all functions from this section are already implemented.
  • Node Functions These functions are used for basic data organisation into nodes. Note: all functions from this section are already implemented.
  • Tag Functions These functions are used for basic data storage. Note: almost all functions from this section are already implemented.
  • Layer Functions These functions are used for large data storage. (WIP)

Note: Some parts of this new API was inspired by old Verse specification. The full Verse C API could be generated using Doxygen from source code.

Example

This is minimal terminal verse client that connect to the verse server running at localhost.

#include <verse.h>

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/* My session ID */
static uint8_t my_session_id = -1;

/* My callback function for user authentication */
void cb_receive_user_authenticate(const uint8_t session_id,
        const char *username,
        const uint8_t auth_methods_count,
        const uint8_t *methods)
{
    char name[64], *password;

    /* Get username, when it is requested */
    if(username == NULL) {
        printf("Username: ");
        scanf("%s", name);
        vrs_send_user_authenticate(session_id, name, 0, NULL);
    } else {
        /* We assume that VRS_UA_METHOD_PASSWORD is in methods array */
        strcpy(name, username);
        /* Get password from user */
        password = getpass("Password: ");
        vrs_send_user_authenticate(session_id, name, VRS_UA_METHOD_PASSWORD, password);
    }
}

/* My callback function for connect accept */
void cb_receive_connect_accept(const uint8_t session_id,
        const uint16_t user_id,
        const uint32_t avatar_id)
{
    /* TODO: Do something useful here */
}

/* My callback function for connect terminate */
void cb_receive_connect_terminate(const uint8_t session_id,
        const uint8_t error_num)
{
    /* TODO: Do something useful here */
}

int main(void)
{
    int error_num;

    /* Register basic callback functions */
    vrs_register_receive_user_authenticate(cb_receive_user_authenticate);
    vrs_register_receive_connect_accept(cb_receive_connect_accept);
    vrs_register_receive_connect_terminate(cb_receive_connect_terminate);

    /* Send connect request to the server */
    error_num = vrs_send_connect_request("localhost", "12345", 0, &my_session_id);
    if(error_num != VRS_SUCCESS) {
        printf("ERROR: %s\n", vrs_strerror(error_num));
        return EXIT_FAILURE;
    }

    /* Never ending loop */
    while(1) {
        vrs_callback_update(my_session_id);
        sleep(1);
    }

    return EXIT_SUCCESS;
}
Clone this wiki locally