Пример #1
0
  void HttpOutput::StateMachine::CloseBody()
  {
    switch (state_)
    {
      case State_WritingHeader:
        SetContentLength(0);
        SendBody(NULL, 0);
        break;

      case State_WritingBody:
        if (!hasContentLength_ ||
            contentPosition_ == contentLength_)
        {
          state_ = State_Done;
        }
        else
        {
          LOG(ERROR) << "The body size has not reached what was declared with SetContentSize()";
          throw OrthancException(ErrorCode_BadSequenceOfCalls);
        }

        break;

      case State_WritingMultipart:
        LOG(ERROR) << "Cannot invoke CloseBody() with multipart outputs";
        throw OrthancException(ErrorCode_BadSequenceOfCalls);

      case State_Done:
        return;  // Ignore

      default:
        throw OrthancException(ErrorCode_InternalError);
    }      
  }
void ICACHE_FLASH_ATTR MainHttpServerSocket::DoSetWiFiPage(const char *page, HttpParameters *paramarray, int params)
	{

		char *ssid;
		char *password;

		for(int i=0;i<params;i++)
			{
				if(os_strcmp(paramarray[i].parameter,"sel") == 0)
					{
						ssid = paramarray[i].value;
					}
				if(os_strcmp(paramarray[i].parameter,"pw") == 0)
					{
						password = paramarray[i].value;
					}
			}

		bool b = wifi.Connect(ssid,password);
		if(b)
			{
				char buf[os_strlen(set_wifiPage) + 256];
				os_strcpy(buf,set_wifiPage);
				str_replace(buf,"$WIFI$",ssid);
				SetContentLength(buf);
				CloseOnSent();
				Send(buf);
			}
		else
			{
				char buf[os_strlen(set_wifiErrorPage) + 256];
				os_strcpy(buf,set_wifiPage);
				str_replace(buf,"$WIFI$",ssid);
				SetContentLength(buf);
				CloseOnSent();
				Send(buf);
			}
	}
void
FTPChannelChild::DoOnStartRequest(const PRInt32& aContentLength,
                                  const nsCString& aContentType,
                                  const PRTime& aLastModified,
                                  const nsCString& aEntityID,
                                  const IPC::URI& aURI)
{
  LOG(("FTPChannelChild::RecvOnStartRequest [this=%x]\n", this));

  SetContentLength(aContentLength);
  SetContentType(aContentType);
  mLastModifiedTime = aLastModified;
  mEntityID = aEntityID;

  nsCString spec;
  nsCOMPtr<nsIURI> uri(aURI);
  uri->GetSpec(spec);
  nsBaseChannel::URI()->SetSpec(spec);

  AutoEventEnqueuer ensureSerialDispatch(this);
  nsresult rv = mListener->OnStartRequest(this, mListenerContext);
  if (NS_FAILED(rv))
    Cancel(rv);
}
nsresult nsMailboxProtocol::Initialize(nsIURI * aURL)
{
  NS_PRECONDITION(aURL, "invalid URL passed into MAILBOX Protocol");
  nsresult rv = NS_OK;
  if (aURL)
  {
    rv = aURL->QueryInterface(NS_GET_IID(nsIMailboxUrl), (void **) getter_AddRefs(m_runningUrl));
    if (NS_SUCCEEDED(rv) && m_runningUrl)
    {
      nsCOMPtr <nsIMsgWindow> window;
      rv = m_runningUrl->GetMailboxAction(&m_mailboxAction); 
      // clear stopped flag on msg window, because we care.
      nsCOMPtr <nsIMsgMailNewsUrl> mailnewsUrl = do_QueryInterface(m_runningUrl);
      if (mailnewsUrl)
      {
        mailnewsUrl->GetMsgWindow(getter_AddRefs(window));
        if (window)
          window->SetStopped(false);
      }

      if (m_mailboxAction == nsIMailboxUrl::ActionParseMailbox)
      {
        // Set the length of the file equal to the max progress
        nsCOMPtr<nsIFile> file;
        GetFileFromURL(aURL, getter_AddRefs(file));
        if (file)
        {
          int64_t fileSize = 0;
          file->GetFileSize(&fileSize);
          mailnewsUrl->SetMaxProgress(fileSize);
        }

        rv = OpenFileSocket(aURL, 0, -1 /* read in all the bytes in the file */);
      }
      else
      {
        // we need to specify a byte range to read in so we read in JUST the message we want.
        rv = SetupMessageExtraction();
        if (NS_FAILED(rv)) return rv;
        uint32_t aMsgSize = 0;
        rv = m_runningUrl->GetMessageSize(&aMsgSize);
        NS_ASSERTION(NS_SUCCEEDED(rv), "oops....i messed something up");
        SetContentLength(aMsgSize);
        mailnewsUrl->SetMaxProgress(aMsgSize);

        if (RunningMultipleMsgUrl())
        {
          rv = OpenFileSocketForReuse(aURL, m_msgOffset, aMsgSize);
          // if we're running multiple msg url, we clear the event sink because the multiple
          // msg urls will handle setting the progress.
          mProgressEventSink = nullptr;
        }
        else
        {
          nsCOMPtr<nsIMsgIncomingServer> server;
          nsCOMPtr<nsIMsgDBHdr> msgHdr;
          nsCOMPtr<nsIMsgFolder> folder;
          nsCOMPtr<nsIMsgMessageUrl> msgUrl = do_QueryInterface(m_runningUrl, &rv);
          NS_ENSURE_SUCCESS(rv,rv);
          rv = msgUrl->GetMessageHeader(getter_AddRefs(msgHdr));
          if (msgHdr)
          {
            msgHdr->GetFolder(getter_AddRefs(folder));
            if (folder)
              folder->GetServer(getter_AddRefs(server));
          }
          if (server)
          {
            nsCOMPtr<nsIMsgPluggableStore> msgStore;
            rv = server->GetMsgStore(getter_AddRefs(msgStore));
            NS_ENSURE_SUCCESS(rv, rv);

            if (NS_SUCCEEDED(rv) && msgHdr)
            {
              nsCOMPtr<nsIInputStream> stream;
              int64_t offset = 0;
              bool reusable = false;

              rv = folder->GetMsgInputStream(msgHdr, &reusable, getter_AddRefs(stream));
              NS_ENSURE_SUCCESS(rv, rv);
              nsCOMPtr<nsISeekableStream> seekableStream(do_QueryInterface(stream, &rv));
              NS_ENSURE_SUCCESS(rv, rv);
              seekableStream->Tell(&offset);
              // create input stream transport
              nsCOMPtr<nsIStreamTransportService> sts =
                  do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
              if (NS_FAILED(rv)) return rv;
              m_readCount = aMsgSize;
              rv = sts->CreateInputTransport(stream, offset,
                                             int64_t(aMsgSize), true,
                                             getter_AddRefs(m_transport));

              m_socketIsOpen = false;
             
            }
          }
          else // must be a .eml file
            rv = OpenFileSocket(aURL, 0, aMsgSize);
        }
        NS_ASSERTION(NS_SUCCEEDED(rv), "oops....i messed something up");
      }
    }
  }
  
  m_lineStreamBuffer = new nsMsgLineStreamBuffer(OUTPUT_BUFFER_SIZE, true);
  
  m_nextState = MAILBOX_READ_FOLDER;
  m_initialState = MAILBOX_READ_FOLDER;
  mCurrentProgress = 0;
  
  // do we really need both?
  m_tempMessageFile = m_tempMsgFile;
  return rv;
}