Exemplo n.º 1
0
void extract_from_meta(SmlPcdataPtr_t metaP,
                       char ** formatP,
                       char ** typeP)
{
    SmlMetInfMetInfPtr_t metInfP;

    if (formatP) *formatP = NULL;
    if (typeP) *typeP = NULL;
    if (!metaP
     || metaP->contentType != SML_PCDATA_EXTENSION
     || metaP->extension != SML_EXT_METINF)
    {
        return;
    }

    metInfP = (SmlMetInfMetInfPtr_t) metaP->content;

    if(formatP)
    {
        *formatP = smlPcdata2String(metInfP->format);
    }
    if (typeP)
    {
        *typeP = smlPcdata2String(metInfP->type);
    }
}
Exemplo n.º 2
0
int copy_node(internals_t * internP,
              SmlItemPtr_t itemP)
{
    int code;
    char * src_uri;
    char * dst_uri;

    dst_uri = smlPcdata2String(itemP->target->locURI);
    if (!dst_uri) return OMADM_SYNCML_ERROR_NOT_FOUND;

    src_uri = smlPcdata2String(itemP->source->locURI);
    if (!src_uri)
    {
        free(dst_uri);
        return OMADM_SYNCML_ERROR_NOT_FOUND;
    }

    code = dmtree_copy(internP->dmtreeH, src_uri, dst_uri);
    PRV_CONVERT_CODE(code);

    free(dst_uri);
    free(src_uri);

    return code;
}
Exemplo n.º 3
0
int exec_node(internals_t * internP,
              SmlItemPtr_t itemP,
              SmlPcdataPtr_t correlatorP)
{
    int code;
    char * uri;
    char * data;
    char * correlator;

    uri = smlPcdata2String(itemP->target->locURI);
    if (!uri) return OMADM_SYNCML_ERROR_NOT_FOUND;

    data = smlPcdata2String(itemP->data);
    correlator = smlPcdata2String(correlatorP);

    code = dmtree_exec(internP->dmtreeH,
                       uri,
                       data,
                       correlator);
    PRV_CONVERT_CODE(code);

    free(uri);
    if (data != NULL) free(data);
    if (correlator != NULL) free(correlator);
    return code;
}
Exemplo n.º 4
0
void prv_get_alert_choices(dmclt_ui_t * alertP,
                           SmlItemListPtr_t itemCell)
{
    SmlItemListPtr_t cellP;
    int count;

    count = 0;
    cellP = itemCell;
    while (cellP)
    {
        cellP = cellP->next;
        count++;
    }
    if (0 == count) return;

    alertP->choices = (char**)malloc((count + 1)*sizeof(char*));
    if (!alertP->choices) goto error;

    count = 0;
    while (itemCell)
    {
        if (!itemCell->item) goto error;
        alertP->choices[count] = smlPcdata2String(itemCell->item->data);
        count++;
        itemCell =itemCell->next;
    }
    alertP->choices[count] = NULL;

    return;

error:
    alertP->type = 0;
}
Exemplo n.º 5
0
elemCell_t * retrieve_element(internals_t * internP,
                              char * cmdRef,
                              char * msgRef)
{
    elemCell_t * cellP;
    elemCell_t * prevCellP;
    int iMsgRef;
    int notFound;

    iMsgRef = -1;
    if (strlen(msgRef) != 0)
    {
        int tmp;
        if (1 == sscanf(msgRef, "%d", &tmp))
        {
            iMsgRef = tmp;
        }
    }

    cellP = internP->old_elem;
    prevCellP = NULL;
    notFound = 1;
    while (cellP && notFound)
    {
        if ((cellP->msg_id == iMsgRef) || (iMsgRef == -1))
        {
            char * elemId = smlPcdata2String(cellP->element->cmdID);
            if (elemId)
            {
                notFound = strcmp(elemId, cmdRef);
            }
        }
        if (notFound)
        {
            prevCellP = cellP;
            cellP = cellP->next;
        }
    }

    if (cellP)
    {
        if (prevCellP)
        {
            prevCellP->next = cellP->next;
        }
        else
        {
            internP->old_elem = cellP->next;
        }
        cellP->next = NULL;
    }

    return cellP;
}
Exemplo n.º 6
0
static Ret_t prv_start_message_cb(InstanceID_t id,
                                  VoidPtr_t userData,
                                  SmlSyncHdrPtr_t headerP)
{
    internals_t * internP = (internals_t *)userData;
    SmlStatusPtr_t statusP;
    SmlChalPtr_t challengeP = NULL;
    char * dataStr;

    if (internP->reply_ref)
    {
        free(internP->reply_ref);
    }
    internP->sequence = NULL;
    internP->seq_code = 0;

    internP->reply_ref = smlPcdata2String(headerP->msgID);

    if (headerP->cred)
    {
        internP->srv_auth = check_credentials(headerP->cred, internP->account->toClientCred);
        challengeP= get_challenge(internP->account->toClientCred);
        store_nonce(internP->dmtreeH->MOs, internP->account, false);
    }

    dataStr = smlPcdata2String(headerP->respURI);
    if (dataStr)
    {
        set_new_uri(internP, dataStr);
        free(dataStr);
    }

    statusP = create_status(internP, internP->srv_auth, NULL);
    statusP->chal = challengeP;
    add_target_ref(statusP, headerP->target);
    add_source_ref(statusP, headerP->source);

    add_element(internP, (basicElement_t *)statusP);

    return SML_ERR_OK;
}
Exemplo n.º 7
0
dmclt_authType_t get_from_chal_meta(SmlPcdataPtr_t metaP,
                                    buffer_t * nonceP)
{
    dmclt_authType_t type;
    SmlMetInfMetInfPtr_t metInfP;
    char * item;

    type = DMCLT_AUTH_TYPE_UNKNOWN;
    if (nonceP)
    {
        nonceP->buffer = NULL;
        nonceP->len = 0;
    }

    if (metaP->contentType != SML_PCDATA_EXTENSION
     || metaP->extension != SML_EXT_METINF)
    {
        return type;
    }

    metInfP = (SmlMetInfMetInfPtr_t) metaP->content;

    item = smlPcdata2String(metInfP->type);
    if (item)
    {
        type = auth_string_as_type(item);
        free(item);
    }

    if (nonceP)
    {
        item = smlPcdata2String(metInfP->nextnonce);
        if (item)
        {
            decode_b64(item, nonceP);
            free(item);
        }
    }

    return type;
}
Exemplo n.º 8
0
int pcdata_to_int(SmlPcdataPtr_t dataP)
{
    int result = 0;
    char * asString;

    asString = smlPcdata2String(dataP);
    if (asString)
    {
        sscanf(asString, "%d", &result);
        free(asString);
    }

    return result;
}
Exemplo n.º 9
0
int delete_node(internals_t * internP,
                SmlItemPtr_t itemP)
{
    int code;
    char * uri;

    uri = smlPcdata2String(itemP->target->locURI);
    if (!uri) return OMADM_SYNCML_ERROR_NOT_FOUND;

    code = dmtree_delete(internP->dmtreeH, uri);
    PRV_CONVERT_CODE(code);

    free(uri);
    return code;
}
Exemplo n.º 10
0
int get_node(internals_t * internP,
             SmlItemPtr_t itemP,
             SmlItemPtr_t resultP)
{
    int code;
    char * uri;

    uri = smlPcdata2String(itemP->target->locURI);
    if (!uri) return OMADM_SYNCML_ERROR_NOT_FOUND;

    code = prv_get(internP, uri, resultP);

    free(uri);
    return code;
}
Exemplo n.º 11
0
int check_credentials(SmlCredPtr_t credP,
                      authDesc_t * authP)
{
    int status = OMADM_SYNCML_ERROR_INVALID_CREDENTIALS;
    authType_t credType;
    char * data = smlPcdata2String(credP->data);

    if (!data) goto error; //smlPcdata2String() returns null only in case of allocation error

    credType = get_from_chal_meta(credP->meta, NULL);

    switch (authP->type)
    {
    case AUTH_TYPE_BASIC:
        {
            if (credType == AUTH_TYPE_BASIC)
            {
                char * digest = prv_get_digest_basic(authP);
                if (!strcmp(digest, data))
                {
                    status = OMADM_SYNCML_ERROR_AUTHENTICATION_ACCEPTED;
                }
            }
        }
        break;
    case AUTH_TYPE_DIGEST:
        {
            if (credType == AUTH_TYPE_DIGEST)
            {
                char * digest = prv_get_digest_md5(authP);
                if (!strcmp(digest, data))
                {
                    status = OMADM_SYNCML_ERROR_AUTHENTICATION_ACCEPTED;
                }
            }
        }
        break;

    default:
        break;
    }

    free(data);

error:
    return status;
}
Exemplo n.º 12
0
int replace_node(internals_t * internP,
                 SmlItemPtr_t itemP)
{
    int code;
    dmtree_node_t node;

    memset(&node, 0, sizeof(dmtree_node_t));
    node.uri = smlPcdata2String(itemP->target->locURI);
    extract_from_meta(itemP->meta, &(node.format), &(node.type));
    node.data_size = itemP->data->length;
    if (node.data_size)
    {
        node.data_buffer = itemP->data->content;
    }

    code = dmtree_replace(internP->dmtreeH, &node);
    PRV_CONVERT_CODE(code);

    dmtree_node_clean(&node, false);

    return code;
}
Exemplo n.º 13
0
dmclt_ui_t * get_ui_from_sml(SmlAlertPtr_t smlAlertP)
{
    dmclt_ui_t * alertP;
    char * dataStr;
    SmlItemListPtr_t itemCell;

    if (!smlAlertP || !smlAlertP->data) return NULL;

    alertP = (dmclt_ui_t *)malloc(sizeof(dmclt_ui_t));
    if (!alertP) return NULL;
    memset(alertP, 0, sizeof(dmclt_ui_t));

    itemCell = smlAlertP->itemList;
    if (!itemCell) goto end;

    // first item contains options
    if (NULL == itemCell->item) goto end;
    dataStr = smlPcdata2String(itemCell->item->data);
    prv_fill_alert_options(alertP, dataStr);

    // second item contains display message
    itemCell = itemCell->next;
    if (NULL == itemCell || NULL == itemCell->item) goto end;
    alertP->disp_msg = smlPcdata2String(itemCell->item->data);
    itemCell = itemCell->next;

    dataStr = smlPcdata2String(smlAlertP->data);
    if (NULL == dataStr)
    {
        goto end;
    }
    if (0 == strcmp(dataStr, PRV_ALERT_STRING_DISPLAY))
    {
        alertP->type = DMCLT_UI_TYPE_DISPLAY;
    }
    else if (0 == strcmp(dataStr, PRV_ALERT_STRING_CONFIRM))
    {
        alertP->type = DMCLT_UI_TYPE_CONFIRM;
    }
    else if (0 == strcmp(dataStr, PRV_ALERT_STRING_USER_INPUT))
    {
        alertP->type = DMCLT_UI_TYPE_USER_INPUT;
        alertP->max_resp_len = alertP->max_resp_len?alertP->max_resp_len:PRV_USER_RESP_MAX_LEN;
    }
    else if (0 == strcmp(dataStr, PRV_ALERT_STRING_USER_CHOICE))
    {
        alertP->type = DMCLT_UI_TYPE_USER_CHOICE;
        prv_get_alert_choices(alertP, itemCell);
        alertP->max_resp_len = alertP->max_resp_len?alertP->max_resp_len:PRV_USER_RESP_MAX_LEN;
    }
    else if (0 == strcmp(dataStr, PRV_ALERT_STRING_USER_MULTICHOICE))
    {
        alertP->type = DMCLT_UI_TYPE_USER_MULTICHOICE;
        prv_get_alert_choices(alertP, itemCell);
        alertP->max_resp_len = alertP->max_resp_len?alertP->max_resp_len:PRV_USER_RESP_MAX_LEN;
    }
    else
    {
        goto end;
    }

end:
    if (0 == alertP->type)
    {
        free_dmclt_alert(alertP);
        alertP = NULL;
    }
    return alertP;
}