static MI_Result WSBuf_CreateRequestHeader()

in Unix/wsman/wsbuf.c [3007:3214]


static MI_Result WSBuf_CreateRequestHeader(WSBuf *buf,
                                           const WsmanClient_Headers *cliHeaders,
                                           const MI_Instance *instance,
                                           const MI_Char *namespace,
                                           const ZChar *action,
                                           const MI_Char *className,
                                           const MI_Char *function)
{
    ZChar msgID[WS_MSG_ID_SIZE];
    WSBuf_GenerateMessageID(msgID);

    // Envelope
#ifndef DISABLE_SHELL
    if (MI_RESULT_OK != WSBuf_AddStartTagWithAttrs(buf,
                                                   LIT(ZT("s:Envelope")),
                                                   LIT(ZT("xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" ")
                                                       ZT("xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" ")
                                                       ZT("xmlns:n=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" ")
                                                       ZT("xmlns:w=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\" ")
                                                       ZT("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema\" ")
                                                       ZT("xmlns:h=\"http://schemas.microsoft.com/wbem/wsman/1/windows/shell\" ")
                                                       ZT("xmlns:p=\"http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd\" "))))
#else
    if (MI_RESULT_OK != WSBuf_AddStartTagWithAttrs(buf,
                                                   LIT(ZT("s:Envelope")),
                                                   LIT(ZT("xmlns:s=\"http://www.w3.org/2003/05/soap-envelope\" ")
                                                       ZT("xmlns:a=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" ")
                                                       ZT("xmlns:n=\"http://schemas.xmlsoap.org/ws/2004/09/enumeration\" ")
                                                       ZT("xmlns:w=\"http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd\" ")
                                                       ZT("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema\" ")
                                                       ZT("xmlns:p=\"http://schemas.microsoft.com/wbem/wsman/1/wsman.xsd\" "))))
#endif
    {
        goto failed;
    }


    // Header section
    if (MI_RESULT_OK != WSBuf_AddStartTag (buf, LIT(ZT("s:Header"))))
    {
        goto failed;
    }

    if ((className == NULL) && instance)
    {
        MI_Instance_GetClassName(instance, &className);
    }
    // To address
    if (MI_RESULT_OK != WSBuf_AddStartTag(buf, LIT(ZT("a:To"))) ||
        MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, cliHeaders->protocol) ||
        MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("://"))) ||
        MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, cliHeaders->hostname) ||
        MI_RESULT_OK != WSBuf_AddLit1(buf, ':') ||
        MI_RESULT_OK != WSBuf_AddUint32(buf, cliHeaders->port) ||
        (cliHeaders->httpUrl[0] != '/' && MI_RESULT_OK != WSBuf_AddLit1(buf, '/')) ||
        MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, cliHeaders->httpUrl) ||
        MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT( ZT("a:To"))))
    {
        goto failed;
    }

    // resource uri
    if (MI_RESULT_OK != WSBuf_CreateResourceUri(buf, cliHeaders, instance, namespace, className))
    {
        goto failed;
    }

    // replyto
    if (MI_RESULT_OK != WSBuf_AddStartTag(buf, LIT(ZT("a:ReplyTo"))) ||
        MI_RESULT_OK != WSBuf_AddStartTagMustUnderstand(buf, LIT(ZT("a:Address"))) ||
        MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous"))) ||
        MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT( ZT("a:Address"))) ||
        MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT(ZT("a:ReplyTo"))))
    {
        goto failed;
    }

    // action
    if (NULL == action)
    {
        if (NULL == className || NULL == function)
        {
            return MI_RESULT_FAILED;
        }

        if (MI_RESULT_OK != WSBuf_AddStartTag(buf, LIT(ZT("a:Action"))) ||
            MI_RESULT_OK != WSBuf_AddLit(buf, LIT(DEFAULTSCHEMA)) ||
            MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, className) ||
            MI_RESULT_OK != WSBuf_AddLit1(buf, '/') ||
            MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, function) ||
            MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT(ZT("a:Action"))))
        {
            return MI_RESULT_FAILED;
        }
    }
    else if (MI_RESULT_OK != WSBuf_AddStartTag(buf, LIT(ZT("a:Action"))) ||
             MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, action) ||
             MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT(ZT("a:Action"))))
    {
        goto failed;
    }

    // max envelope size
    if (MI_RESULT_OK != WSBuf_AddStartTagMustUnderstand(buf, LIT(ZT("w:MaxEnvelopeSize"))) ||
        MI_RESULT_OK != WSBuf_AddUint32(buf, cliHeaders->maxEnvelopeSize) ||
        MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT(ZT("w:MaxEnvelopeSize"))))
    {
        goto failed;
    }

    // message id
    if (MI_RESULT_OK != WSBuf_AddStartTag(buf, LIT(ZT("a:MessageID"))) ||
        MI_RESULT_OK != WSBuf_AddLit(buf, msgID, WS_MSG_ID_SIZE -1) ||
        MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT(ZT("a:MessageID"))))
    {
        goto failed;
    }

    // OperationTimeout
    if (cliHeaders->operationTimeout.days > 0 ||
        cliHeaders->operationTimeout.hours > 0 ||
        cliHeaders->operationTimeout.minutes > 0 ||
        cliHeaders->operationTimeout.seconds > 0 ||
        cliHeaders->operationTimeout.microseconds > 0)
    {
        ZChar interval[64];
        MI_Datetime datetime;
        datetime.isTimestamp = 0;
        memcpy(&datetime.u.interval, &cliHeaders->operationTimeout, sizeof(MI_Interval));
        FormatWSManDatetime(&datetime, interval);

        if (MI_RESULT_OK != WSBuf_AddStartTag(buf, LIT(ZT("w:OperationTimeout"))) ||
            MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, interval) ||
            MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT(ZT("w:OperationTimeout"))))
        {
            goto failed;
        }
    }

    // locale - optional
    if (cliHeaders->locale != NULL)
    {
        if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("<w:Locale xml:lang=\""))) ||
            MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, cliHeaders->locale) ||
            MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("\" s:mustUnderstand=\"false\"/>"))))
        {
            goto failed;
        }
    }

    // data locale - optional
    if (cliHeaders->dataLocale != NULL)
    {
        if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("<p:DataLocale xml:lang=\""))) ||
            MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, cliHeaders->dataLocale) ||
            MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("\" s:mustUnderstand=\"false\"/>"))))
        {
            goto failed;
        }
    }

    if (cliHeaders->operationOptions)
    {
        if (MI_RESULT_OK != WSBuf_CreateOptionSet(buf, cliHeaders->operationOptions))
        {
            goto failed;
        }
    }

#ifndef DISABLE_SHELL
    if (cliHeaders->compressionType)
    {
        if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("<h:CompressionType s:mustUnderstand=\"true\">"))) ||
            MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, cliHeaders->compressionType) ||
            MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("</h:CompressionType>"))))
        {
            goto failed;
        }
    }
    if (cliHeaders->sessionId)
    {
        if (MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("<p:SessionId s:mustUnderstand=\"false\">"))) ||
            MI_RESULT_OK != WSBuf_AddStringNoEncoding(buf, cliHeaders->sessionId) ||
            MI_RESULT_OK != WSBuf_AddLit(buf, LIT(ZT("</p:SessionId>"))))
        {
            goto failed;
        }
    }
#endif

    // selector set
    if (MI_RESULT_OK != WSBuf_CreateSelectorSet(buf, instance, namespace))
    {
        goto failed;
    }

    // end Header
    if (MI_RESULT_OK != WSBuf_AddEndTag(buf, LIT( ZT("s:Header"))))
    {
        goto failed;
    }

    return MI_RESULT_OK;

 failed:
    return MI_RESULT_FAILED;

}