static SmlSyncHdrPtr_t prvGetHeader(internals_t * internP) { SmlSyncHdrPtr_t headerP; headerP = smlAllocSyncHdr(); if (headerP) { set_pcdata_string(headerP->version, "1.2"); set_pcdata_string(headerP->proto, "DM/1.2"); set_pcdata_hex(headerP->sessionID, internP->session_id); set_pcdata_int(headerP->msgID, internP->message_id); set_pcdata_int(headerP->msgID, internP->message_id); set_pcdata_string(headerP->target->locURI, internP->account->server_uri); set_pcdata_string(headerP->source->locURI, internP->account->id); if (OMADM_SYNCML_ERROR_AUTHENTICATION_ACCEPTED != internP->clt_auth) { headerP->cred = get_credentials(internP->account->toServerCred); } headerP->meta = smlAllocPcdata(); if (headerP->meta) { SmlMetInfMetInfPtr_t metInfP; metInfP = smlAllocMetInfMetInf(); if (metInfP) { metInfP->maxmsgsize = smlString2Pcdata(PRV_MAX_MESSAGE_SIZE); headerP->meta->contentType = SML_PCDATA_EXTENSION; headerP->meta->extension = SML_EXT_METINF; headerP->meta->length = 0; headerP->meta->content = metInfP; } else { smlFreePcdata(headerP->meta); headerP->meta = NULL; } } } return headerP; }
SmlStatusPtr_t create_status(internals_t * internP, int code, SmlGenericCmdPtr_t pContent) { SmlStatusPtr_t statusP; statusP = smlAllocStatus(); // if pContent is nil, we are replying to an header if (pContent) { set_pcdata_pcdata(statusP->cmdRef, pContent->cmdID); } else { set_pcdata_string(statusP->cmdRef, "0"); } set_pcdata_string(statusP->msgRef, internP->reply_ref); set_pcdata_string(statusP->cmd, proto_as_string(pContent?pContent->elementType:SML_PE_HEADER)); set_pcdata_int(statusP->data, code); return statusP; }
static int prvComposeMessage(internals_t * internP) { int toSend = -1; Ret_t result; SmlSyncHdrPtr_t syncHdrP; elemCell_t * cell; internP->message_id++; internP->command_id = 1; syncHdrP = prvGetHeader(internP); result = smlStartMessageExt(internP->smlH, syncHdrP, SML_VERS_1_2); cell = internP->elem_first; while(cell && result == SML_ERR_OK) { set_pcdata_int(cell->element->cmdID, internP->command_id++); cell->msg_id = internP->message_id; switch (cell->element->elementType) { case SML_PE_ALERT: result = smlAlertCmd(internP->smlH, (SmlAlertPtr_t)(cell->element)); toSend = 1; break; case SML_PE_REPLACE: result = smlReplaceCmd(internP->smlH, (SmlReplacePtr_t)(cell->element)); toSend = 1; break; case SML_PE_RESULTS: result = smlResultsCmd(internP->smlH, (SmlResultsPtr_t)(cell->element)); toSend = 1; break; case SML_PE_STATUS: result = smlStatusCmd(internP->smlH, (SmlStatusPtr_t)(cell->element)); toSend++; break; default: // should not happen break; } cell = cell->next; } if (result != SML_ERR_OK) { return DMCLT_ERR_INTERNAL; } PRV_CHECK_SML_CALL(smlEndMessage(internP->smlH, SmlFinal_f)); refresh_elements(internP); if (toSend <= 0) { return DMCLT_ERR_END; } return DMCLT_ERR_NONE; }