Example #1
0
static int prv_process_child(const char *new_child, dmc_ptr_array *children,
                             char **child_copy)
{
    DMC_ERR_MANAGE;
    const char *child;
    uintptr_t name_length;

    if ((child = strchr(new_child, '/')))
        name_length = child - new_child;
    else
        name_length = strlen(new_child);

    if (*child_copy)
    {
        if (strncmp(new_child, *child_copy, name_length))
        {
            DMC_FAIL(dmc_ptr_array_append(children, *child_copy));
            DMC_FAIL_NULL(*child_copy, strndup(new_child,
                                               name_length),
                          DMC_ERR_OOM);
        }
    }
    else
        DMC_FAIL_NULL(*child_copy, strndup(new_child, name_length),
                      DMC_ERR_OOM);

DMC_ON_ERR:

    return DMC_ERR;
}
Example #2
0
int dmsettings_get_meta(dmsettings *handle, const char *key, const char *prop,
                        char **value)
{
    DMC_ERR_MANAGE;
    const char *text_sqlite3;
    char *text_copy;

    DMC_FAIL(prv_bind_double_query(handle->stmt_get_meta, key, prop));

    text_sqlite3 = (const char*) sqlite3_column_text(handle->stmt_get_meta,
                   0);

    if (text_sqlite3)
        DMC_FAIL_NULL(text_copy, strdup(text_sqlite3), DMC_ERR_OOM);
    else
        DMC_FAIL_FORCE(DMC_ERR_NOT_FOUND);

    *value = text_copy;

DMC_ON_ERR:

    sqlite3_reset(handle->stmt_get_meta);
    sqlite3_clear_bindings(handle->stmt_get_meta);

    return DMC_ERR;
}
Example #3
0
static int prv_open_database(const char *datastore, int flags,
                             dmsettings **handle)
{
    DMC_ERR_MANAGE;
    dmsettings *settings;
    int sqlerr;

    DMC_FAIL_NULL(settings, malloc(sizeof(*settings)), DMC_ERR_OOM);

    memset(settings, 0, sizeof(*settings));

    sqlerr = sqlite3_open_v2(datastore, &settings->db_handle, flags, NULL);

    DMC_FAIL(map_sqlite3_error(sqlerr));

    sqlerr = sqlite3_busy_timeout(settings->db_handle,
                                  DMSETTINGS_BUSY_TIMEOUT);

    DMC_FAIL(map_sqlite3_error(sqlerr));

    *handle = settings;

    return DMC_ERR_NONE;

DMC_ON_ERR:

    free(settings);

    return DMC_ERR;
}
Example #4
0
int dmsettings_delete(dmsettings *handle, const char *key)
{
    DMC_ERR_MANAGE;
    char *parent = NULL;
    const char *parent_path = NULL;
    char *tok;

    if (!key)
        DMC_FAIL_FORCE(DMC_ERR_BAD_ARGS);

    if (!handle->can_write)
        DMC_FAIL_FORCE(DMC_ERR_DENIED);

    DMC_FAIL_NULL(parent, strdup(key), DMC_ERR_OOM);

    tok = strrchr(parent,'/');

    if (tok) {
        *tok = 0;
        if (strchr(parent,'/'))
            parent_path = parent;
    }

    /*
     * If parent_path is not NULL then we need to ensure that this node
     * exists in the explicit table.  Otherwise the act of deleting a node
     * will delete some of its ancestors as well.
     */

    if (handle->transaction_in_progress)
        DMC_FAIL(prv_delete_in_transaction(handle, key, parent_path));
    else
        DMC_FAIL(prv_delete_out_transaction(handle, key, parent_path));

DMC_ON_ERR:

    free(parent);

    return DMC_ERR;
}
Example #5
0
int get_server_account(mo_mgr_t * iMgr,
                       char * serverID,
                       accountDesc_t ** accountP)
{
    DMC_ERR_MANAGE;

    char * accMoUri = NULL;
    char * accountUri = NULL;
    char * uri = NULL;
    char * subUri = NULL;
    dmtree_node_t node;
    int code;

    memset(&node, 0, sizeof(dmtree_node_t));

    DMC_FAIL(momgr_find_subtree(iMgr, NULL, DMACC_MO_URN, "ServerID", serverID, &accountUri));

    DMC_FAIL_NULL(*accountP, malloc(sizeof(accountDesc_t)), OMADM_SYNCML_ERROR_DEVICE_FULL);
    memset(*accountP, 0, sizeof(accountDesc_t));
    (*accountP)->dmtree_uri = accountUri;
    accountUri = NULL;

    DMC_FAIL_NULL(node.uri, strdup("./DevInfo/DevId"), OMADM_SYNCML_ERROR_DEVICE_FULL);
    DMC_FAIL(momgr_get_value(iMgr, &node));
    (*accountP)->id = dmtree_node_as_string(&node);
    dmtree_node_clean(&node, true);

    // TODO handle IPv4 and IPv6 cases
    DMC_FAIL_NULL(uri, str_cat_2((*accountP)->dmtree_uri, "/AppAddr"), OMADM_SYNCML_ERROR_DEVICE_FULL);
    DMC_FAIL(momgr_find_subtree(iMgr, uri, NULL, "AddrType", "URI", &subUri));
    free(uri);
    uri = NULL;
    DMC_FAIL_NULL(node.uri, str_cat_2(subUri, "/Addr"), OMADM_SYNCML_ERROR_DEVICE_FULL);
    DMC_FAIL(momgr_get_value(iMgr, &node));
    (*accountP)->server_uri = dmtree_node_as_string(&node);
    dmtree_node_clean(&node, true);
    free(subUri);
    subUri = NULL;

    // TODO handle OBEX and HTTP authentification levels
    DMC_FAIL_NULL(uri, str_cat_2((*accountP)->dmtree_uri, "/AppAuth"), OMADM_SYNCML_ERROR_DEVICE_FULL);
    code = momgr_find_subtree(iMgr, uri, NULL, "AAuthLevel", "CLCRED", &subUri);
    switch (code)
    {
    case OMADM_SYNCML_ERROR_NONE:
        DMC_FAIL_NULL((*accountP)->toServerCred, malloc(sizeof(authDesc_t)), OMADM_SYNCML_ERROR_DEVICE_FULL);
        DMC_FAIL(prv_fill_credentials(iMgr, subUri, (*accountP)->toServerCred));
        break;
    case OMADM_SYNCML_ERROR_NOT_FOUND:
        break;
    default:
        DMC_FAIL(code);
    }
    free(subUri);
    subUri = NULL;

    code = momgr_find_subtree(iMgr, uri, NULL, "AAuthLevel", "SRVCRED", &subUri);
    switch (code)
    {
    case OMADM_SYNCML_ERROR_NONE:
        DMC_FAIL_NULL((*accountP)->toClientCred, malloc(sizeof(authDesc_t)), OMADM_SYNCML_ERROR_DEVICE_FULL);
        DMC_FAIL(prv_fill_credentials(iMgr, subUri, (*accountP)->toClientCred));
        break;
    case OMADM_SYNCML_ERROR_NOT_FOUND:
        break;
    default:
        DMC_FAIL(code);
    }
    free(subUri);
    subUri = NULL;

DMC_ON_ERR:

    if (accMoUri) free(accMoUri);
    if (accountUri) free(accountUri);
    if (uri) free(uri);
    if (subUri) free(subUri);
    dmtree_node_clean(&node, true);

    return DMC_ERR;
}