Exemplo n.º 1
0
PAL_INT32_T add_envelope_end ( char *sendbuf,  PAL_INT32_T * soapSize )
{
    soap_send_raw ( sendbuf, "</", 2, soapSize );
    soap_send_raw ( sendbuf, "SOAP-ENV:Envelope", strlen ( "SOAP-ENV:Envelope" ), soapSize );
    soap_send_raw ( sendbuf, ">", 1, soapSize );
    return SUCCESS_OK;
}
Exemplo n.º 2
0
PAL_INT32_T add_body_start ( char *sendbuf,  PAL_INT32_T * soapSize )
{
    soap_send_raw ( sendbuf, "<", 1, soapSize );
    soap_send_raw ( sendbuf, "SOAP-ENV:Body", strlen ( "SOAP-ENV:Body" ), soapSize );
    soap_send_raw ( sendbuf, ">", 1, soapSize );
    return SUCCESS_OK;
}
Exemplo n.º 3
0
PAL_INT32_T soap_add_ID ( char *sendbuf,  PAL_INT32_T *soapSize, PacketType type )
{
    char id[64];
    PAL_UINT32_T tmp;

    if ( type == SEND_INFORM || type == TRANSFER_COMPLETE || type == REQUEST_DOWNLOAD)
    {
        srand ( time(NULL) );
        tmp = rand();
        sprintf ( id, "%d", tmp );
    }
    else
    {
        //get the current id
        strcpy ( id, gId );
    }

    if ( soap_send_raw ( sendbuf, "<", 1, soapSize ) || soap_send_raw ( sendbuf, "cwmp:ID", strlen ( "cwmp:ID" ), soapSize )
            || soap_add_attribute ( sendbuf, "SOAP-ENV:mustUnderstand", "1", soapSize )
            || soap_send_raw ( sendbuf, ">", 1, soapSize )
            || soap_send_raw ( sendbuf, id, strlen ( id ), soapSize )
            || soap_send_raw ( sendbuf, "</cwmp:ID>", strlen ( "</cwmp:ID>" ), soapSize ) )
    {
        return ERROR_PARAMETER;
    }

    return SUCCESS_OK;
}
Exemplo n.º 4
0
PAL_INT32_T add_header_start ( char *sendbuf,  PAL_INT32_T * soapSize, PacketType type )
{

    soap_send_raw ( sendbuf, "<", 1, soapSize );
    soap_send_raw ( sendbuf, "SOAP-ENV:Header", strlen ( "SOAP-ENV:Header" ), soapSize );
    soap_send_raw ( sendbuf, ">", 1, soapSize );
    if ( soap_add_ID ( sendbuf, soapSize, type ) )
    {
        return ERROR_PARAMETER;
    }
    return SUCCESS_OK;

}
Exemplo n.º 5
0
int http_get(struct soap *soap)
{
    FILE*fd = NULL;
    fd = fopen("UserManager.wsdl", "rb"); //open WSDL file to copy
    if (!fd)
    {
        return 404; //return HTTP not found error
    }
    soap->http_content = "text/xml";  //HTTP header with text /xml content
    soap_response(soap,SOAP_FILE);
    for(;;)
    {
        size_t r = fread(soap->tmpbuf,1, sizeof(soap->tmpbuf), fd);
        if (!r)
        {
            break;
        }
        if (soap_send_raw(soap, soap->tmpbuf, r))
        {
            break; //cannot send, but little we can do about that
        }
    }
    fclose(fd);
    soap_end_send(soap);
    return SOAP_OK;
}
Exemplo n.º 6
0
int http_get(struct soap *soap) 
{
   //std::cout << "DEBUG i am here get" << std::endl;
   //soap->fposthdr(soap, "Access-Control-Allow-Origin", "*");

   FILE *fd = NULL;
   char *s = strchr(soap->path, '?'); 
   if (!s || strcmp(s, "?wsdl")) 
      return SOAP_GET_METHOD; 
   fd = fopen(config.WSDL_FILE_PATH.c_str(), "rb"); // open WSDL file to copy 
   if (!fd) 
      return 404; // return HTTP not found error 
   soap->http_content = "text/xml"; // HTTP header with text/xml content 
   soap_response(soap, SOAP_FILE); 
   for (;;) 
   { 
      size_t r = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd); 
      if (!r) 
         break; 
      if (soap_send_raw(soap, soap->tmpbuf, r)) 
         break; // can't send, but little we can do about that 
   } 
   fclose(fd); 
   soap_end_send(soap); 
   return SOAP_OK; 
}
Exemplo n.º 7
0
int32 LoginRESTService::SendResponse(soap* soapClient, google::protobuf::Message const& response)
{
    std::string jsonResponse = JSON::Serialize(response);

    soap_response(soapClient, SOAP_FILE);
    soap_send_raw(soapClient, jsonResponse.c_str(), jsonResponse.length());
    return soap_end_send(soapClient);
}
Exemplo n.º 8
0
// Thread unsafe
int oph_http_get(struct soap *soap)
{
	pmesg(LOG_DEBUG, __FILE__, __LINE__, "Received a HTTP GET Request\n");
	if (!oph_server_protocol || !oph_server_host || !oph_server_port) {
		pmesg(LOG_DEBUG, __FILE__, __LINE__, "Return SOAP Fault\n");
		return SOAP_GET_METHOD;
	}
	FILE *fd = NULL;
	char buffer[OPH_MAX_STRING_SIZE] = { '\0' }, *s = strchr(soap->path, '?');
	if (!s) {
		snprintf(buffer, OPH_MAX_STRING_SIZE, OPH_SERVER_STD_HTTP_RESPONSE, oph_server_protocol, oph_server_host, oph_server_port, oph_server_protocol, oph_server_host, oph_server_port,
			 oph_server_protocol, oph_server_host, oph_server_port);
		soap->http_content = "text/html";
		pmesg(LOG_DEBUG, __FILE__, __LINE__, "Return HTML description of web service\n");
	} else if (strcmp(s, "?wsdl")) {
		pmesg(LOG_DEBUG, __FILE__, __LINE__, "Return SOAP Fault\n");
		return SOAP_GET_METHOD;
	} else {
		snprintf(buffer, OPH_MAX_STRING_SIZE, OPH_SERVER_WSDL, oph_server_location);
		fd = fopen(buffer, "rb");
		if (!fd) {
			pmesg(LOG_DEBUG, __FILE__, __LINE__, "Return HTTP 'Not Found' error\n");
			return 404;
		}
		soap->http_content = "text/xml";
		pmesg(LOG_DEBUG, __FILE__, __LINE__, "Return WSDL description of web service\n");
	}
	soap_response(soap, SOAP_FILE);
	size_t r;
	if (fd) {
		for (;;) {
			r = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd);
			if (!r)
				break;
			if (soap_send_raw(soap, soap->tmpbuf, r))
				break;
		}
		fclose(fd);
	} else {
		r = snprintf(soap->tmpbuf, sizeof(soap->tmpbuf), "%s", buffer);
		soap_send_raw(soap, soap->tmpbuf, r);
	}
	soap_end_send(soap);
	return SOAP_OK;
}
Exemplo n.º 9
0
PAL_INT32_T add_envelope_start ( char *sendbuf,  PAL_UINT32_T * soapSize )
{
    char xmlHead[100];
    strcpy(xmlHead,"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
    soap_send_raw(sendbuf,xmlHead,strlen(xmlHead),soapSize);
    soap_send_raw ( sendbuf, "<", 1, soapSize );
    soap_send_raw ( sendbuf, "SOAP-ENV:Envelope", strlen ( "SOAP-ENV:Envelope" ), soapSize );

    if ( put_loacal_namespace ( sendbuf, soapSize ) )
    {
        return ERROR_PARAMETER;
    }
    soap_add_attribute ( sendbuf, "SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/", soapSize );
    soap_send_raw ( sendbuf, ">", 1, soapSize );

    return SUCCESS_OK;

}
Exemplo n.º 10
0
/* the text handler copies the message back */
int text_handler(struct soap *soap)
{ char *buf;
  size_t len;
  soap_http_body(soap, &buf, &len);
  /* use current soap->http_content from HTTP header as return HTTP type */
  soap_response(soap, SOAP_FILE);
  soap_send_raw(soap, buf, len);
  soap_end_send(soap);
  return SOAP_OK;
}
Exemplo n.º 11
0
PAL_INT32_T soap_add_attribute ( char *sendbuf,  char *attrname, char *attrvalue, PAL_INT32_T *soapSize )
{
    char tmp[100];
    if ( attrname && attrvalue )
    {
        sprintf ( tmp, " %s=\"%s\"", attrname, attrvalue );
        soap_send_raw ( sendbuf, tmp, strlen ( tmp ), soapSize );
    }

    return SUCCESS_OK;
}
Exemplo n.º 12
0
SOAP_FMAC1 void SOAP_FMAC2 soap_putattachments(struct soap *soap)
{
	int i;
	struct soap_plist *pp;
	if (!soap->dime)
		return;
	soap_send_raw(soap, "\0\0\0", -(int)soap->count&3);
	for (i = 0; i < SOAP_PTRHASH; i++)
		for (pp = soap->pht[i]; pp; pp = pp->next)
			if (pp->mark2 == 3)
				switch (pp->type & 0x3FF)
				{
				}
		
	
}
Exemplo n.º 13
0
PAL_INT32_T put_loacal_namespace ( char *sendbuf,  PAL_INT32_T *soapSize )
{
    NameSpace *NSptr;
    char tmp[100];
    NSptr = gLocalNSptr;
    while ( NSptr )
    {
        if ( NSptr->nsname && NSptr->nsvalue )
        {
            sprintf ( tmp, " xmlns:%s=\"%s\"", NSptr->nsname, NSptr->nsvalue );
            soap_send_raw ( sendbuf, tmp, strlen ( tmp ), soapSize );
        }
        else
        {
            return ERROR_PARAMETER;
        }
        NSptr = NSptr->next;
    }
    return SUCCESS_OK;
}
Exemplo n.º 14
0
/**
@fn int soap_mec_stop(struct soap *soap)
@brief Stops encryption or decryption of current message. Use after
soap_mec_start.
@param soap context
@return SOAP_OK or error code
*/
int
soap_mec_stop(struct soap *soap)
{ struct soap_mec_data *data;
  int err = SOAP_OK;
  const char *s = NULL;
  size_t n = 0;
  data = (struct soap_mec_data*)soap->data[1];
  if (!data)
    return soap->error = SOAP_USER_ERROR;
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "MEC Stop alg=%x\n", data->alg));
  err = soap_mec_final(soap, data, &s, &n);
  if (data->alg & SOAP_MEC_ENC)
  { /* reset callbacks */
    if (soap->ffiltersend == soap_mec_filtersend)
      soap->ffiltersend = data->ffiltersend;
    /* send remaining cipher data */
    if (!err && n)
      if (soap_send_raw(soap, s, n))
        return soap->error;
  }
  return err;
}
Exemplo n.º 15
0
int http_get(struct soap *soap)
{
	int retCode = 404;
	FILE *fd = fopen(soap->path + 1, "rb"); 
	if (fd != NULL)
	{
		if (!soap_tag_cmp(soap->path, "*.html"))
			soap->http_content = "text/html"; 
		if (!soap_tag_cmp(soap->path, "*.wsdl"))
			soap->http_content = "text/xml"; 
		soap_response(soap, SOAP_FILE);
		for (;;)
		{
			size_t r = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd);
			if ( (r == 0) || (soap_send_raw(soap, soap->tmpbuf, r)) )
				break;
		}
		fclose(fd);
		soap_end_send(soap);
		retCode = SOAP_OK;
	}
	return retCode;
} 
Exemplo n.º 16
0
/*************************************************************
 * Function:    http_get(struct soap *soap)
 * Arguments:   
 * Description: 
 * Date:        
 * Author:      
**************************************************************/
int http_get(struct soap *soap)
{
    char* fielPath=soap->path;
    char WSDLPATH[128];
    memset(WSDLPATH,0,sizeof(WSDLPATH));
    sprintf(WSDLPATH,"%s/etc/ApsOnlWS.wsdl",EXHOME);
    FILE* fd = fopen(WSDLPATH, "rb");
    if (!fd)
    {
    // return HTTP not found error
    return 404;
    }
    // HTTP header with text/xml content
    soap->http_content = "text/xml";
    soap_response(soap, SOAP_FILE);
    for(;;)
    {
        // READ
        size_t r = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd);
        if (!r)
        {
            break;
        }

        // SEND DATA
        if (soap_send_raw(soap, soap->tmpbuf, r))
        {
            // can't send, but little we can do about that
             break;
        }
    }

    // close fd
    fclose(fd);
    soap_end_send(soap);
    return SOAP_OK;
}
Exemplo n.º 17
0
PAL_INT32_T add_body_end ( char *sendbuf,  PAL_INT32_T * soapSize )
{
    soap_send_raw ( sendbuf, "</SOAP-ENV:Body>", strlen ( "</SOAP-ENV:Body>" ), soapSize );
    return SUCCESS_OK;
}
Exemplo n.º 18
0
static int jsstrout(struct soap *soap, const char *s)
{ int c;
  char buf[8];
  if (soap_send_raw(soap, "\"", 1))
    return soap->error;
  while ((c = *s++))
  { switch (c)
    { case '"':
      case '\\':
        buf[0] = '\\';
        buf[1]  = c;
        if (soap_send_raw(soap, buf, 2))
          return soap->error;
        break;
      default:
        if (c < 32 && c > 0)
        { switch (c)
          { case '\b':
              c = 'b';
              break;
            case '\f':
              c = 'f';
              break;
            case '\n':
              c = 'n';
              break;
            case '\r':
              c = 'r';
              break;
            case '\t':
              c = 't';
              break;
          }
          if (c > 32)
          { buf[0] = '\\';
            buf[1]  = c;
            if (soap_send_raw(soap, buf, 2))
              return soap->error;
          }
          else
	  { (SOAP_SNPRINTF(buf, sizeof(buf), 7), "\\u%4x", c);
            if (soap_send_raw(soap, buf, 6))
              return soap->error;
          }
        }
        else if ((c & 0x80) && (soap->omode & SOAP_ENC_LATIN) && (soap->omode & SOAP_C_UTFSTRING)) // utf8 to ISO 8859-1
        { if (c < 0xE0 && (c & 0x1F) <= 0x03)
            buf[0] = ((c & 0x1F) << 6) | (*s++ & 0x3F);
          else
            buf[0] = '?';
          if (soap_send_raw(soap, buf, 1))
            return soap->error;
        }
        else if ((c & 0x80) && !(soap->omode & SOAP_ENC_LATIN) && !(soap->omode & SOAP_C_UTFSTRING)) // ISO 8859-1 to utf8
        { buf[0] = (char)(0xC0 | ((c >> 6) & 0x1F));
          buf[1] = (char)(0x80 | (c & 0x3F));
          if (soap_send_raw(soap, buf, 2))
            return soap->error;
        }
        else
        { buf[0] = c;
          if (soap_send_raw(soap, buf, 1))
            return soap->error;
        }
    }
Exemplo n.º 19
0
/*
 * Handles the HTTP GET command from soap, only the client update install may be downloaded.
 *
 * This function can only be called when client_update_enabled is set to yes.
 *
 * @note This function is only use for backward compatibility
 */
int HandleClientUpdate(struct soap *soap) 
{ 
	std::string strPath;

	int nRet = 404;				// default return file not found to soap
	char *szClientUpdatePath = NULL;
	char *szCurrentVersion = NULL;
	char *szReq = NULL;
	char *szReqEnd = NULL;
	std::string strLicenseRequest;
	std::string strLicenseResponse;

	ECLicenseClient *lpLicenseClient = NULL;
	unsigned int ulLicenseResponse = 0;
	unsigned char *lpLicenseResponse = NULL;
	ECRESULT er = erSuccess;
	ClientVersion currentVersion = {0};
	ClientVersion latestVersion = {0};
	std::string strClientMSIName;
	FILE *fd = NULL;


	// Get the server.cfg setting
	szClientUpdatePath = g_lpConfig->GetSetting("client_update_path");

	if (!szClientUpdatePath || szClientUpdatePath[0] == 0) {
		g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: The configuration field 'client_update_path' is empty.");
		goto exit;
	}

	// if the version comes as "/autoupdate/6.20.1.1234?licreq", we need to pass the license request
	szReq = strrchr(soap->path, '?');
	if (szReq != NULL) {
		// since we have the ?, that's good enough
		szReq = strstr(soap->buf, "X-License: ");
		if (szReq == NULL) {
			g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Invalid license request, header not found.");
			goto exit;
		}
		szReq += strlen("X-License: ");
		szReqEnd = strstr(szReq, "\r\n"); // TODO: can be be split over multiple lines?
		if (szReqEnd == NULL) {
			g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Invalid license request, end of header not found.");
			goto exit;
		}
		strLicenseRequest = base64_decode(std::string(szReq, szReqEnd - szReq));

		lpLicenseClient = new ECLicenseClient(g_lpConfig->GetSetting("license_socket"),  atoui(g_lpConfig->GetSetting("license_timeout")));
		er = lpLicenseClient->Auth((unsigned char*)strLicenseRequest.c_str(), strLicenseRequest.length(), &lpLicenseResponse, &ulLicenseResponse);
		if (er != erSuccess) {
			g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Invalid license request, error: 0x%08X.", er);
			goto exit;
		}

		strLicenseResponse = base64_encode(lpLicenseResponse, ulLicenseResponse);

		soap->http_content = "binary";
		soap_response(soap, SOAP_FILE);
		nRet = soap_send_raw(soap, strLicenseResponse.c_str(), strLicenseResponse.length());
		g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Processing license request.");
		goto exit;
	}

	// the version comes as "/autoupdate/6.20.1.1234", convert it to "6.20.1.1234"
	szCurrentVersion = soap->path + strlen("/autoupdate");
	if (szCurrentVersion[0] == '/')
		szCurrentVersion++;

	if (szCurrentVersion[0] != '\0') {
		g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: The current client version is %s.", szCurrentVersion);
		if (!GetVersionFromString(szCurrentVersion, &currentVersion))
		{
			g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: Failed in getting version from input data.");
			goto exit;
		}
	}

	if (!GetLatestVersionAtServer(szClientUpdatePath, 0, &latestVersion)) {
		g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: No updates found on server.");
		goto exit;
	}

	if (szCurrentVersion[0] != '\0') {
		int res = CompareVersions(currentVersion, latestVersion);
		if (res == 0) {
			g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Client already has latest version.");
			goto exit;
		} else if (res > 0)	{
			g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Client has newer version than server.");
			goto exit;
		}
	}

	if (!GetClientMSINameFromVersion(latestVersion, &strClientMSIName)) {
		g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: No suitable version available.");
		goto exit;
	}

	if (ConvertAndValidatePath(szClientUpdatePath, strClientMSIName, &strPath) != true) {
		g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: Error in path conversion and validation.");
		goto exit;
	}

	fd = fopen(strPath.c_str(), "rb");
	if (!fd) {
		g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: Path not found %s.", strPath.c_str());
		goto exit;
	}

	g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: Sending client %s new installer %s", PrettyIP(soap->ip).c_str(), strClientMSIName.c_str());

	// application/msi-installer ?
	soap->http_content = "binary";
	soap_response(soap, SOAP_FILE);

	while (true) {
		// FIXME: tmpbuf is only 1K, good enough?
		size_t nSize = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd);

		if (!nSize)
			break;

		if (soap_send_raw(soap, soap->tmpbuf, nSize))
		{
			g_lpLogger->Log(EC_LOGLEVEL_FATAL, "Client update: Error while sending client new installer");
			goto exit;
		}
	}

	nRet = SOAP_OK;

exit:
	if (lpLicenseResponse)
		delete [] lpLicenseResponse;

	if (lpLicenseClient)
		delete lpLicenseClient;

	if (fd)
		fclose(fd);

	return nRet;
}
Exemplo n.º 20
0
int main(int argc, char *argv[])
{
// command line arguments
int nArg;
char *ptr;
char szFileType[64]="";
char szURL[256];
char szUsername[256]="";
char szPassword[256]="";
unsigned int FileSize=0;
char szTargetFileName[256]="";
unsigned int DelaySeconds;
char szCWMPAddress[256]="";

char szProxyHost[256]="";
unsigned int ProxyPort=0;
char szProxyUserId[256]="";
char szProxyPasswd[256]="";
char szTemp[256];
double DownloadSize;
FILE *tmpfile;  //add by wangjr 091201

struct soap soap;
struct Namespace empty_namespaces[] = { { NULL } };

  dprintf(LOG_LEVEL1, "\nDOWNLOAD MANAGER ..execution\n\n");

  // signal handling
  signal(SIGPIPE, sigpipe_handle);
  signal(SIGINT, sigint_handle);

  nErrorCode=0;

  // Command Line Arguments
  for (nArg = 1; nArg < argc; nArg++)
  {
    ptr = argv[nArg];
    if (strncmp(argv[nArg], "--CWMPAddress:", strlen("--CWMPAddress:")) == 0) {
      strcpy(szCWMPAddress, &ptr[strlen("--CWMPAddress:")]);
      dprintf(LOG_LEVEL1, "....CWMPAddress: %s\n", szCWMPAddress);
    }
    else if (strncmp(argv[nArg], "--FileType:", strlen("--FileType:")) == 0) {
      strcpy(szFileType, &ptr[strlen("--FileType:")]);
      dprintf(LOG_LEVEL1, "....FileType: %s\n", szFileType);
    }
    else if (strncmp(argv[nArg], "--URL:", strlen("--URL:")) == 0) {
      strcpy(szURL, &ptr[strlen("--URL:")]);
      dprintf(LOG_LEVEL1, "....URL: %s\n", szURL);
    }
    else if (strncmp(argv[nArg], "--Username:"******"--Username:"******"--Username:"******"....Username: %s\n", szUsername);
    }
    else if (strncmp(argv[nArg], "--Password:"******"--Password:"******"--Password:"******"....Password: %s\n", szPassword);
    }
    else if (strncmp(argv[nArg], "--FileSize:", strlen("--FileSize:")) == 0) {
      strcpy(szTemp, &ptr[strlen("--FileSize:")]);
      FileSize = atoi(szTemp);
      dprintf(LOG_LEVEL1, "....FileSize: %d\n", FileSize);
    }
    else if (strncmp(argv[nArg], "--TargetFileName:", strlen("--TargetFileName:")) == 0) {
      strcpy(szTargetFileName, &ptr[strlen("--TargetFileName:")]);
      dprintf(LOG_LEVEL1, "....TargetFileName: %s\n", szTargetFileName);
    }
    else if (strncmp(argv[nArg], "--DelaySeconds:", strlen("--DelaySeconds:")) == 0) {
      strcpy(szTemp, &ptr[strlen("--DelaySeconds:")]);
      DelaySeconds = atoi(szTemp);
      dprintf(LOG_LEVEL1, "....DelaySeconds: %d\n", DelaySeconds);
    }
    else if (strncmp(argv[nArg], "--ProxyHost:", strlen("--ProxyHost:")) == 0) {
      strcpy(szProxyHost, &ptr[strlen("--ProxyHost:")]);
      dprintf(LOG_LEVEL1, "....szProxyHost: %s\n", szProxyHost);
    }
    else if (strncmp(argv[nArg], "--ProxyPort:", strlen("--ProxyPort:")) == 0) {
      strcpy(szTemp, &ptr[strlen("--ProxyPort:")]);
      ProxyPort = atoi(szTemp);
      dprintf(LOG_LEVEL1, "....ProxyPort: %d\n", ProxyPort);
    }
    else if (strncmp(argv[nArg], "--ProxyUserId:", strlen("--ProxyUserId:")) == 0) {
      strcpy(szProxyUserId, &ptr[strlen("--ProxyUserId:")]);
      dprintf(LOG_LEVEL1, "....szProxyUserId: %s\n", szProxyUserId);
    }
    else if (strncmp(argv[nArg], "--ProxyPasswd:", strlen("--ProxyPasswd:")) == 0) {
      strcpy(szProxyPasswd, &ptr[strlen("--ProxyPasswd:")]);
      dprintf(LOG_LEVEL1, "....szProxyPasswd: %s\n", szProxyPasswd);
    }
  }

  DownloadSize = download_funct(szURL, szTargetFileName, szUsername, szPassword, szProxyHost, ProxyPort, szProxyUserId, szProxyPasswd);

  dprintf(LOG_LEVEL3, "....FileSize: %d\n", FileSize);
  
  if ((FileSize > 0) && ((unsigned long)DownloadSize != FileSize))  //update by wangjr
  	nErrorCode = 9010;
  //else 
  	//nErrorCode = 0;
/*        add by wangjr 091201   */
	tmpfile = fopen("/tmp/tr069", "w");
	if(tmpfile != NULL)
    {
		fprintf(tmpfile, "%d",nErrorCode);
	}
	fclose(tmpfile);
/*        add by wangjr 091201   */

  if (szCWMPAddress && (strcmp(szCWMPAddress, "") != 0))
  {
  // RESPONSE to CWMP server
  
  // ATTENTION : Don't use SOAP_IO_KEEPALIVE during SUBSCRIBE message
  // because each SUBSCRIBE must correspond to one TCP connection
    soap_init2(&soap,SOAP_ENC_XML|SOAP_IO_LENGTH|SOAP_XML_INDENT, SOAP_ENC_XML|SOAP_IO_LENGTH|SOAP_XML_INDENT);
    soap.accept_timeout = 60;
    soap.max_keep_alive = 100; // max keep-alive sequence
    soap.recv_timeout = 60; // Timeout after 5 minutes stall on recv 
    soap.send_timeout = 60; // Timeout after 1 minute stall on send 
    soap_set_namespaces(&soap, empty_namespaces);
  
    soap_connect_command(&soap, SOAP_POST, szCWMPAddress, "");
  
    soap_element_begin_out(&soap, CONST_MESSAGE, 0, NULL);
    soap_element_begin_out(&soap, "NAME", 0, NULL);
    sprintf(szTemp, "%s", CONST_DOWNLOADCOMPLETE);
    soap_send_raw(&soap, szTemp, strlen(szTemp));
    soap_element_end_out(&soap, "NAME");
  
    soap_element_begin_out(&soap, "Value", 0, NULL);
    sprintf(szTemp, "%d", nErrorCode);
    soap_send_raw(&soap, szTemp, strlen(szTemp));
    soap_element_end_out(&soap, "Value");
    soap_element_end_out(&soap, CONST_MESSAGE);
  
    soap_end_send(&soap);
    soap_closesock(&soap);
  
    soap_destroy((struct soap*)&soap); // dealloc C++ data
    soap_end((struct soap*)&soap); // dealloc data and clean up
    soap_done((struct soap*)&soap); // detach soap struct
  }

  dprintf(LOG_LEVEL3, "size of data downloaded: %f\n", DownloadSize);

  dprintf(LOG_LEVEL2, "DOWNLOAD MANAGER, END OF MAIN PROGRAM\n");
  return 0;
}
Exemplo n.º 21
0
PAL_INT32_T envelope_fault ( char *sendbuf, SOAPFault *SOAPFault,  PAL_INT32_T * soapSize )
{
    char tmp[8];
    SetParameterFaultStruct *SetParameterFaultStructPtr;
    soap_send_raw ( sendbuf, "<", 1, soapSize );
    soap_send_raw ( sendbuf, "SOAP-ENV:Fault", strlen ( "SOAP-ENV:Fault" ), soapSize );
    soap_send_raw ( sendbuf, ">", 1, soapSize );
    //sprintf(tmp, "%d", SOAPFault->detail->cwmpFault->FaultCode);
    if ( SOAPFault->faultCode[0] != 0 )
    {
        soap_send_raw ( sendbuf, "<faultcode>", strlen ( "<faultcode>" ), soapSize );
        soap_send_raw ( sendbuf, SOAPFault->faultCode, strlen ( SOAPFault->faultCode ), soapSize );
        soap_send_raw ( sendbuf, "</faultcode>", strlen ( "</faultcode>" ), soapSize );
    }
    else
    {
        return ERROR_PARAMETER;
    }

    if ( SOAPFault->faultString[0] != 0 )
    {
        soap_send_raw ( sendbuf, "<faultstring>", strlen ( "<faultstring>" ), soapSize );
        soap_send_raw ( sendbuf, SOAPFault->faultString, strlen ( SOAPFault->faultString ), soapSize );
        soap_send_raw ( sendbuf, "</faultstring>", strlen ( "</faultstring>" ), soapSize );
    }
    else
    {
        return ERROR_PARAMETER;
    }

    if ( SOAPFault->faultActor[0] != 0 )
    {
        soap_send_raw ( sendbuf, "<faultactor>", strlen ( "<faultactor>" ), soapSize );
        soap_send_raw ( sendbuf, SOAPFault->faultActor, strlen ( SOAPFault->faultActor ), soapSize );
        soap_send_raw ( sendbuf, "</faultactor>", strlen ( "</faultactor>" ), soapSize );
    }

    if ( SOAPFault->detail )
    {
        soap_send_raw ( sendbuf, "<detail>", strlen ( "<detail>" ), soapSize );
        if ( SOAPFault->detail->cwmpFault )
        {
            soap_send_raw ( sendbuf, "<cwmp:Fault>", strlen ( "<cwmp:Fault>" ), soapSize );
            if ( SOAPFault->detail->cwmpFault->FaultCode )
            {
                soap_send_raw ( sendbuf, "<FaultCode>", strlen ( "<FaultCode>" ), soapSize );
                sprintf(tmp,"%d",SOAPFault->detail->cwmpFault->FaultCode);
                soap_send_raw ( sendbuf, tmp, strlen (tmp), soapSize );
                soap_send_raw ( sendbuf, "</FaultCode>", strlen ( "</FaultCode>" ), soapSize );
            }
            if ( SOAPFault->detail->cwmpFault->FaultString[0] != 0 )
            {
                soap_send_raw ( sendbuf, "<FaultString>", strlen ( "<FaultString>" ), soapSize );
                soap_send_raw ( sendbuf, SOAPFault->detail->cwmpFault->FaultString, strlen ( SOAPFault->detail->cwmpFault->FaultString ), soapSize );
                soap_send_raw ( sendbuf, "</FaultString>", strlen ( "</FaultString>" ), soapSize );
            }
            SetParameterFaultStructPtr = SOAPFault->detail->cwmpFault->SetParameterValuesFault;
            while ( SetParameterFaultStructPtr )
            {
                soap_send_raw ( sendbuf, "<SetParameterValuesFault>", strlen ( "<SetParameterValuesFault>" ), soapSize );

                soap_send_raw ( sendbuf, "<ParameterName>", strlen ( "<ParameterName>" ), soapSize );
                soap_send_raw ( sendbuf, SetParameterFaultStructPtr->ParameterName, strlen ( SetParameterFaultStructPtr->ParameterName ), soapSize );
                soap_send_raw ( sendbuf, "</ParameterName>", strlen ( "</ParameterName>" ), soapSize );

                soap_send_raw ( sendbuf, "<FaultCode>", strlen ( "<FaultCode>" ), soapSize );
                sprintf ( tmp, "%d", SetParameterFaultStructPtr->FaultCode );
                soap_send_raw ( sendbuf, tmp, strlen ( tmp ), soapSize );
                soap_send_raw ( sendbuf, "</FaultCode>", strlen ( "</FaultCode>" ), soapSize );


                soap_send_raw ( sendbuf, "<FaultString>", strlen ( "<FaultString>" ), soapSize );
                soap_send_raw ( sendbuf, SetParameterFaultStructPtr->FaultString, strlen ( SetParameterFaultStructPtr->FaultString ), soapSize );
                soap_send_raw ( sendbuf, "</FaultString>", strlen ( "</FaultString>" ), soapSize );

                soap_send_raw ( sendbuf, "</SetParameterValuesFault>", strlen ( "</SetParameterValuesFault>" ), soapSize );

                SetParameterFaultStructPtr = SetParameterFaultStructPtr->next;

            }
            soap_send_raw ( sendbuf, "</cwmp:Fault>", strlen ( "</cwmp:Fault>" ), soapSize );
        }
        soap_send_raw ( sendbuf, "</detail>", strlen ( "</detail>" ), soapSize );
    }

    soap_send_raw ( sendbuf, "</SOAP-ENV:Fault>", strlen ( "</SOAP-ENV:Fault>" ), soapSize );
    return SUCCESS_OK;

}
Exemplo n.º 22
0
SOAP_FMAC1
int
SOAP_FMAC2
soap_out_xsd__anyType(struct soap *soap, const char *tag, int id, const struct soap_dom_element *node, const char *type)
{ if (node)
  { struct soap_dom_element *elt;
    struct soap_dom_attribute *att;
    register struct soap_ilist *p = NULL, *q;
    struct Namespace *ns = NULL;
    const char *prefix;		/* namespace prefix, if namespace is present */
    size_t colon = 0;
    if (node->name)
      tag = node->name;
    if (!tag)
      tag = "_";
    if ((prefix = strchr(tag, ':')))
    { colon = prefix - tag + 1;
      if (colon > sizeof(soap->tag))
        colon = sizeof(soap->tag);
    }
    prefix = NULL;
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "DOM node '%s'\n", tag));
    if (node->nstr)
    { if ((p = soap_lookup_ns(soap, node->nstr)))
      { prefix = p->id;
        p = NULL;
        if (out_element(soap, node, prefix, tag + colon, NULL))
          return soap->error;
      }
      else if (colon)
      { strncpy(soap->tag, tag, colon - 1);
        soap->tag[colon - 1] = '\0';
        if (!(p = soap_enter_ns(soap, soap->tag, node->nstr)))
          return soap->error = SOAP_EOM;
        prefix = p->id;
        if (out_element(soap, node, prefix, tag + colon, node->nstr))
          return soap->error;
      }
      else
      { for (ns = soap->local_namespaces; ns && ns->id; ns++)
          if (ns->ns == node->nstr || !strcmp(ns->ns, node->nstr))
          { /* if (soap->encodingStyle || ns == soap->local_namespaces) */
              prefix = ns->id;
            if (out_element(soap, node, ns->id, tag + colon, NULL))
              return soap->error;
            break;
          }
        if (!ns || !ns->id)
        { sprintf(soap->tag, SOAP_DOMID_FORMAT, soap->idnum++);
          if (!(p = soap_enter_ns(soap, soap->tag, node->nstr)))
            return soap->error = SOAP_EOM;
          prefix = p->id;
          if (out_element(soap, node, prefix, tag + colon, node->nstr))
            return soap->error;
        }
      }
    }
    else if (out_element(soap, node, NULL, tag + colon, NULL))
      return soap->error;
    if (node->type && node->node)
      return SOAP_OK;
    for (att = node->atts; att; att = att->next)
    { if (att->name)
      { if (att->nstr)
        { if ((att->nstr == node->nstr || (node->nstr && !strcmp(att->nstr, node->nstr))) && prefix)
	  { if (out_attribute(soap, prefix, att->name, att->data))
	      return soap->error;
	  }
	  else if ((q = soap_lookup_ns(soap, att->nstr)))
	  { if (out_attribute(soap, q->id, att->name, att->data))
	      return soap->error;
	  }
	  else
	  { for (ns = soap->local_namespaces; ns && ns->id; ns++)
            { if (ns->ns == att->nstr || !strcmp(ns->ns, att->nstr))
	      { if (out_attribute(soap, ns->id, att->name, att->data))
	          return soap->error;
	        break;
	      }
	    }
	    if (!ns || !ns->id)
            { sprintf(soap->msgbuf, "xmlns:"SOAP_DOMID_FORMAT, soap->idnum++);
	      if (soap_attribute(soap, soap->msgbuf, att->nstr))
	        return soap->error;
	      strcat(soap->msgbuf, ":");
	      strcat(soap->msgbuf, att->name);
	      if (soap_attribute(soap, soap->msgbuf + 6, att->data))
	        return soap->error;
            }
          }
        }
	else if (soap_attribute(soap, att->name, att->data))
          return soap->error;
      }
    }
    if (soap_element_start_end_out(soap, NULL))
      return soap->error;
    if (node->data || node->wide || node->elts)
    { if (node->data)
      { if (soap_string_out(soap, node->data, 0))
          return soap->error;
      }
      else if (node->wide)
      { if (soap_wstring_out(soap, node->wide, 0))
          return soap->error;
      }
      else
      { for (elt = node->elts; elt; elt = elt->next)
          if (soap_out_xsd__anyType(soap, tag, 0, elt, NULL))
            return soap->error;
      }
    }
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of DOM node '%s'\n", tag + colon));
    if (soap_send_raw(soap, "</", 2))
      return soap->error;
    if (prefix)
      if (soap_send(soap, prefix) || soap_send_raw(soap, ":", 1))
        return soap->error;
    if (soap_send(soap, tag + colon) || soap_send_raw(soap, ">", 1))
      return soap->error;
    if (p)
      p->level = 0; /* xmlns binding is out of scope */
  }
  return SOAP_OK;
}
Exemplo n.º 23
0
int html_options(struct soap *soap, struct option *options)
{ struct option *p;
  soap_send(soap, "<table border='0' cellspacing='0' cellpadding='0' bgcolor='#666666' nosave>\n");
  soap_send(soap, "<tr height='10'><td background='btl.gif'></td><td background='bt.gif'></td><td background='bt.gif'></td><td background='bt.gif'></td><td background='bt.gif'></td><td background='bt.gif'></td><td width='10' background='btr.gif'></td><td width='10' height='10' background='obls.gif'></td></tr>");
  for (p = options; p->name; p++)
  { const char *s, *t, *n;
    int i;
    n = p->name;
    if (n[0] && n[1] == '.')
      n += 2;
    s = p->selections;
    soap_send(soap, "<tr><td background='bl.gif'></td><td align='right'>");
    if (!n[0])
    { if (s)
        soap_send(soap, s);
      soap_send(soap, "</td><td></td><td></td><td></td><td>");
      if (p->value)
        soap_send(soap, p->value);
      soap_send(soap, "</td>");
    }
    else if (!s)
    { soap_send(soap, n);
      soap_send(soap, "</td><td width='10' background='ls.gif'></td><td bgcolor='#FFFFFF'><a href='?");
      soap_send(soap, n);
      if (p->selected)
        soap_send(soap, "='><img src='checked.gif' align='absmiddle' border='0'></a></td><td width='10' background='rs.gif'></td><td>on</td>");
      else
        soap_send(soap, "'><img src='unchecked.gif' align='absmiddle' border='0'></a></td><td width='10' background='rs.gif'></td><td>off</td>");
    }
    else if (strchr(s, ' '))
    { soap_send(soap, n);
      soap_send(soap, "</td>");
      for (i = 0; ; i++)
      { t = strchr(s, ' ');
        if (i == 0)
	  soap_send(soap, "<td width='10' background='ls.gif'></td><td bgcolor='#FFFFFF'>");
        else
	  soap_send(soap, "<tr><td background='bl.gif'></td><td></td><td width='10' background='ls.gif'></td><td bgcolor='#FFFFFF'>");
        if (i == p->selected)
          soap_send(soap, "<img src='selected.gif' align='absmiddle' border='0'></td><td width='10' background='rs.gif'></td><td>");
        else
        { soap_send(soap, "<a href='?");
          soap_send(soap, n);
          soap_send(soap, "=");
          if (t)
            soap_send_raw(soap, s, t - s);
          else
            soap_send(soap, s);
          soap_send(soap, "'>");
          soap_send(soap, "<img src='deselected.gif' align='absmiddle' border='0'></a></td><td width='10' background='rs.gif'></td><td>");
	}
        if (t)
          soap_send_raw(soap, s, t - s);
        else
          soap_send(soap, s);
        soap_send(soap, "</td>");
        if (!t)
          break;
        soap_send(soap, "<td width='10' background='br.gif'></td><td width='10' background='ls.gif'></td></tr>\n");
        s = t + 1;
      }
    }
    else
    { char buf[16];
      soap_send(soap, n);
      soap_send(soap, "</td><td width='10' background='ls.gif'></td><td bgcolor='#FFFFFF'>&nbsp;</td><td width='10' background='rs.gif'></td><td><input type='text' name='");
      soap_send(soap, n);
      soap_send(soap, "' value='");
      if (p->value)
        soap_send(soap, p->value);
      soap_send(soap, "' size='");
      sprintf(buf, "%d", p->selected > 0 ? p->selected : 24);
      soap_send(soap, buf);
      soap_send(soap, "'><input type='submit' value='Set ");
      soap_send(soap, s);
      soap_send(soap, "'></td>");
    }
    soap_send(soap, "<td width='10' background='br.gif'></td><td width='10' background='ls.gif'></td></tr>\n");
    // <tr height='1'><td height='1' background='bl.gif'></td><td></td><td></td><td></td><td></td><td width='10' height='1' background='br.gif'></td><td width='10' height='1' background='ls.gif'></td></tr>\n");
  }
  soap_send(soap, "<tr height='10'><td background='bbl.gif'></td><td background='bb.gif'></td><td background='bb.gif'></td><td background='bb.gif'></td><td background='bb.gif'></td><td background='bb.gif'></td><td width='10' background='bbr.gif'><td width='10' height='10' background='ls.gif'</td></tr>\n<tr height='10'><td width='10' height='10' background=otrs.gif></td><td height='10' background='ts.gif'></td><td height='10' background='ts.gif'></td><td height='10' background='ts.gif'></td><td height='10' background='ts.gif'></td><td height='10' background='ts.gif'></td><td height='10' background='ts.gif'></td><td width='10' height='10' background='otls.gif'></td></tr>\n</table>\n");
  return SOAP_OK;
}