0

I am new to SOAP and am trying to implement user authentication, i kindly request some help,

Here is the XML request sent from client

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:tt="http://www.onvif.org/ver10/schema"
            xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
            xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
            xmlns:tds="http://www.onvif.org/ver10/device/wsdl">
    <soapenv:Header>
              <wsse:Security>
                <wsse:UsernameToken>
                  <wsse:Username>username</wsse:Username>

        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wssusername-token-profile-
            1.0#PasswordDigest">tuOSpGlFlIXsozq4HFNeeGeFLEI=</wsse:Password>
            <wsse:Nonce>LKqI6G/AikKCQrN0zqZFlg==</wsse:Nonce>
            <wsu:Created>2010-09-16T07:50:45Z</wsu:Created>
            </wsse:UsernameToken>
          </wsse:Security>
        </SOAP-ENV:Header>
      <SOAP-ENV:Body>
        <tds:SetHostname>
          <tds:Name>camera1</tds:Name>
       </tds:SetHostname>
     </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

and I want to access that username sent in this XML request

In the Soap generated SoapServer.c it has a function named

     `SOAP_FMAC5 int SOAP_FMAC6 soap_serve___tds__SetHostname(struct soap *soap)

the below function is where the parsing of xml to SOAP structure take places,

`

SOAP_FMAC5 int SOAP_FMAC6 soap_serve___tds__SetHostname(struct soap *soap) {

struct __tds__SetHostname soap_tmp___tds__SetHostname;
struct _tds__SetHostnameResponse tds__SetHostnameResponse;
soap_default__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse);
soap_default___tds__SetHostname(soap, &soap_tmp___tds__SetHostname);
soap->encodingStyle = NULL;
if (!soap_get___tds__SetHostname(soap, &soap_tmp___tds__SetHostname, "-tds:SetHostname", NULL))
    return soap->error;
if (soap_body_end_in(soap)
 || soap_envelope_end_in(soap)
 || soap_end_recv(soap))
    return soap->error;
soap->error = __tds__SetHostname(soap, soap_tmp___tds__SetHostname.tds__SetHostname, &tds__SetHostnameResponse);
if (soap->error)
    return soap->error;
soap_serializeheader(soap);
soap_serialize__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse);
if (soap_begin_count(soap))
    return soap->error;
if (soap->mode & SOAP_IO_LENGTH)
{   if (soap_envelope_begin_out(soap)
     || soap_putheader(soap)
     || soap_body_begin_out(soap)
     || soap_put__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse, "tds:SetHostnameResponse", NULL)
     || soap_body_end_out(soap)
     || soap_envelope_end_out(soap))
         return soap->error;
};
if (soap_end_count(soap)
 || soap_response(soap, SOAP_OK)
 || soap_envelope_begin_out(soap)
 || soap_putheader(soap)
 || soap_body_begin_out(soap)
 || soap_put__tds__SetHostnameResponse(soap, &tds__SetHostnameResponse, "tds:SetHostnameResponse", NULL)
 || soap_body_end_out(soap)
 || soap_envelope_end_out(soap)
 || soap_end_send(soap))
return soap->error;
return soap_closesock(soap);
  }

` so tried to access/print the username in this method (Starting off with the basic access as of now)

fprintf(stderr,"%s\n",soap->header->wsse__Security->UsernameToken->Username);

But this prints some junk value everytime,accessing of the Username by pointings to structures is also perfectly correct, it would be help full if some one give some pointers as to how to access the SOAP header.

Manu
  • 5,534
  • 6
  • 32
  • 42
  • Is the above XML correctly quoted? There are at least two wsse closing tags missing. – Zane Nov 12 '12 at 14:44
  • Hard to say without knowing what SoapServer.c does. If you can check for parse errors, do that and make sure there are none before you go further. Then you should be able to extract the user name if SoapServer.c works. Otherwise, it could be relatively simple to write a function that scans for the user name only. – Mikkel K. Nov 12 '12 at 15:04
  • @Zane :sorry for that, i have the entire XML quoted now – Manu Nov 13 '12 at 04:50

1 Answers1

0

It depends where are you trying to print this username as it will delete structure at the end. If you just want to send username from client to server then send it as argument to soap_send / soap_call(according to sync/async function) function. Check soap client server communication for further details. At one end you are just sending information and other end recieving other things soap will take care internally.

Rocker
  • 25
  • 5