Ejemplo n.º 1
0
int http_get(struct soap *soap)
{
	char *s = strchr(soap->path, '?');
	if (s && !strcmp(s, "?test")) {
		soap_response(soap, SOAP_HTML);
		soap_send(soap, "<HTML>You called test().</HTML>");
		soap_end_send(soap);
		return SOAP_OK;
	}
	
	soap_response(soap, SOAP_HTML);
	soap_send(soap, "<HTML>success - afd is running</HTML>");
	soap_end_send(soap);
	return SOAP_OK;
}
Ejemplo n.º 2
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; 
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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);
}
Ejemplo n.º 5
0
/* the jpg handler just responds with HTTP OK */
int jpg_handler(struct soap *soap)
{ char *buf;
  size_t len;
  soap_http_body(soap, &buf, &len);
  soap_response(soap, SOAP_OK);
  soap_end_send(soap);
  return SOAP_OK;
}
Ejemplo n.º 6
0
/* the image handler responds with HTTP OK and a text/html body */
int image_handler(struct soap *soap)
{ char *buf;
  size_t len;
  soap_http_body(soap, &buf, &len);
  soap_response(soap, SOAP_HTML);
  soap_send(soap, "<html>Image received</html>");
  soap_end_send(soap);
  return SOAP_OK;
}
Ejemplo n.º 7
0
int soap_foptions(struct soap *soap)
{ 
   int err=0; 
   //std::cout << "DEBUG soap_foptions" << std::endl;
   //if ((err = soap->fposthdr(soap, "Allow", "CONVERT")))
   //    return err;
   soap_response(soap, SOAP_OK); 
   soap_end_send(soap);
   return SOAP_OK;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
int methodResponse::send()
{ /* no namespaces */
  soap->namespaces = NULL;
  /* no SOAP encodingStyle */
  soap->encodingStyle = NULL;
  /* content length */
  soap_begin_count(soap);
  if (soap->mode & SOAP_IO_LENGTH)
    soap_put_methodResponse(soap, this, "methodResponse", NULL);
  soap_end_count(soap);
  /* send response */
  if (soap_response(soap, SOAP_OK)
   || soap_put_methodResponse(soap, this, "methodResponse", NULL)
   || soap_end_send(soap))
    return soap->error;
  return SOAP_OK;
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
} 
Ejemplo n.º 12
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;
}
Ejemplo n.º 13
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;
}