Esempio n. 1
0
void MyNetMailbox::getHeadersRequest()
{
// 	LOG_ENTER("MyNetMailbox::getHeadersRequest");
        std::string page,url;
        boost::smatch match;
        boost::regex re_inbox("<a href=\"([^\"]*)\">.leri</a>");
        boost::regex re("<a class=\"subject\" href=\"rbody.php[^\"]*passed_id=([0-9]*)[^\"]*\">([^<>]*)</a>");
//	setState(Mailbox::ReadHeadersIP); // request headers
        boost::replace_first(auth,"web2","webmail");
	mserv=auth.substr(0,auth.find("showFolder.php"));
	page=doGet(auth+"&mailbox=INBOX.Posta_kutusu");
	while(1)
	{
                std::string::const_iterator pbegin = page.begin();
                std::string::const_iterator pend = page.end();
                while (regex_search(pbegin, pend, match, re, boost::match_default))
		{
			EmailHeader hdr(match[1], match[2]);
// 			LOG(Log::Debug,"Subject: "+match[2]);
// 			LOG(Log::Debug, "Found header: " + hdr.subject);
			addHeader(hdr);
			addHeaderLink(match[1]);
			pbegin = match[2].second;
		}
		if(!regex_search(page,match,re_inbox))
			break;
		url=match[1];
                boost::erase_all(url,"amp;");
		page=doGet(mserv+url);
	}
// 	setState(Mailbox::ReadHeadersDone);
}
Esempio n. 2
0
void start_protocol(const int clientSocket) 
{

	char readBuffer[BUFFERSIZE];
	int readBytes;
	char *cmdString;
	char *ptr;
	char *token;
	char *accessRoute;

	
		cmdString = (char *) calloc(255,1);
		while((readBytes = read(clientSocket,readBuffer,MAXBYTESREAD))>0)
		{
				cmdString = (char *) realloc(cmdString,strlen(cmdString)+readBytes+1);
				strncat(cmdString,readBuffer,readBytes);
				//Read the last 4 characters to determine the EOF
				ptr = cmdString+(strlen(cmdString)-4);
				if(strcmp(ptr,"\r\n\r\n")==0) 
				{	
					*ptr = '\0';
					break;
				}
		}	
			
			debug(4,"<- %s",cmdString);

			token = strtok(cmdString," \t\b");
			debug(4,"%s",token);
			if(strcmp(token,"GET")==0)
			{
				token = strtok(NULL," \t\b");
				if(token == NULL) 
				{
					sendLine(clientSocket, "ERROR ( Acces Route )\r\n\r\n");
				}
				else
				{
					accessRoute = token;
					token = strtok(NULL," \t\b"); 
					if(strcmp(token,"HTTP"))
					{
						doGet(clientSocket,accessRoute);
					}
					else
					{
						sendLine(clientSocket, "Missing Protocol\r\n");
					}
				}
			}
			else
			{
				sendLine(clientSocket, "Unkown command\r\n\r\n");
			}	
			
			if(cmdString != NULL)
				free(cmdString);
	
	
}
bool CParameter::doAccess(type& value, bool bSet,
                          CParameterAccessContext& parameterAccessContext) const
{
    if (bSet) {
        // set value
        if (!doSet(value, getOffset() - parameterAccessContext.getBaseOffset(),
                   parameterAccessContext)) {

            appendParameterPathToError(parameterAccessContext);
            return false;

        }
        // Synchronize
        if (!sync(parameterAccessContext)){

            appendParameterPathToError(parameterAccessContext);
            return false;
        }
    } else {
        // get value
        if (!doGet(value, getOffset() - parameterAccessContext.getBaseOffset(),
                   parameterAccessContext)) {

            appendParameterPathToError(parameterAccessContext);
            return false;
        }
    }
    return true;
}
Esempio n. 4
0
//
// SourceExpression_Binary::doGetBase
//
void SourceExpression_Binary::doGetBase(ObjectVector *objects,
                                        VariableData *dst)
{
   VariableType::Reference type = getType();
   VariableData::Pointer   src  = VariableData::create_stack(type->getSize(pos));

   make_objects_memcpy_prep(objects, dst, src, pos);

   if(docast)
   {
      create_value_cast_explicit(exprL, type, context, pos)->makeObjects(objects, src);
      create_value_cast_explicit(exprR, type, context, pos)->makeObjects(objects, src);
   }
   else
   {
      VariableData::Pointer tmp;

      tmp = VariableData::create_stack(exprL->getType()->getSize(pos));
      exprL->makeObjects(objects, tmp);

      tmp = VariableData::create_stack(exprR->getType()->getSize(pos));
      exprR->makeObjects(objects, tmp);
   }

   doGet(objects, type, 0);

   make_objects_memcpy_post(objects, dst, src, type, context, pos);
}
Esempio n. 5
0
  void CountryInfoGetter::GetRegionInfo(m2::PointD const & pt, CountryInfo & info) const
  {
    GetByPoint doGet(*this, pt);
    ForEachCountry(pt, doGet);

    if (doGet.m_res != -1)
      GetRegionInfo(m_countries[doGet.m_res].m_name, info);
  }
Esempio n. 6
0
void RockComMailbox::getHeadersRequest()
{
// 	LOG_ENTER("RockComMailbox::getHeadersRequest");
	std::string url("http://mymail.rock.com/scripts/mail/mailbox.mail?folder=INBOX"),page;
// 	setState(Mailbox::ReadHeadersIP); // request headers
	totalEmails = 0;
	pgcnt=0;
	page=doGet(url + auth);
	while(1)
	{
		//cout << "Read Headers In Progress" << endl;
		boost::match_results<std::string::const_iterator> match;
//		regex mheadre("<a href=\"/scripts/mail/(.*?) onclick=.+?title=\"(?:<B> )(.*?)(?: </B>)\">");
		boost::regex mheadre("<a href=\"/scripts/mail/(.*?) onclick=.+?title=\"(?:<B>)*(.*?)(?: </B>)*\">");
		std::string::const_iterator pbegin = page.begin();
		std::string::const_iterator pend = page.end();
		while (boost::regex_search(pbegin, pend, match, mheadre, boost::match_default))
		{
			EmailHeader hdr(match[1], match[2]);
			//cout << match[2] << endl;
//			LOG(Log::Debug, "Found header: " + hdr.subject);
	//		cout << hdr.subject << endl;
			addHeader(hdr);
			addHeaderLink(match[1]);
			pbegin = match[2].second;
		}
        boost::regex re2("<a href=\"/scripts/[^<>]*\"><img src=\"http://img1.us4.outblaze.com/rock.com/nextPg.gif\"");
        boost::smatch match2;

		if (!boost::regex_search(page,match,re2))
		{
// 			setState(Mailbox::ReadHeadersDone);
			break;
		}
		else
		{
			//cout << match[2] << endl;
			std::stringstream numstr;
			pgcnt++;
			numstr << pgcnt*50+1;
			std::string url = "http://mymail.rock.com/scripts/mail/mailbox.mail?folder=INBOX&order=Newest&.ob=2013874a6a87e3165de301dc859da6acf78d4520&mview=a&mstart="+numstr.str()+";";
			page=doGet(url);
		}
	}
}
 Message sendMessage(const Message &msg) override {
   if (msg.type == "put") {
     return doPut(msg.params);
   } else if (msg.type == "get") {
     return doGet(msg.params);
   } else {
     return Message("error", {"Unknown command"});
   }
 }
Esempio n. 8
0
  string CountryInfoGetter::GetRegionFile(m2::PointD const & pt) const
  {
    GetByPoint doGet(*this, pt);
    ForEachCountry(pt, doGet);

    if (doGet.m_res != -1)
      return m_countries[doGet.m_res].m_name;
    else
      return string();
  }
Esempio n. 9
0
ExceptionOr<Ref<IDBRequest>> IDBIndex::get(ExecState& execState, JSValue key)
{
    LOG(IndexedDB, "IDBIndex::get");

    auto idbKey = scriptValueToIDBKey(execState, key);
    if (!idbKey->isValid())
        return Exception { IDBDatabaseException::DataError, ASCIILiteral("Failed to execute 'get' on 'IDBIndex': The parameter is not a valid key.") };

    return doGet(execState, IDBKeyRangeData(idbKey.ptr()));
}
Esempio n. 10
0
RefPtr<WebCore::IDBRequest> IDBIndex::get(ScriptExecutionContext* context, IDBKeyRange* range, ExceptionCodeWithMessage& ec)
{
    LOG(IndexedDB, "IDBIndex::get");

    if (!context) {
        ec.code = IDBDatabaseException::InvalidStateError;
        return nullptr;
    }

    return doGet(*context, IDBKeyRangeData(range), ec);
}
Esempio n. 11
0
RefPtr<WebCore::IDBRequest> IDBIndex::get(ScriptExecutionContext* context, IDBKeyRange* range, ExceptionCode& ec)
{
    LOG(IndexedDB, "IDBIndex::get");

    if (!context) {
        ec = INVALID_STATE_ERR;
        return nullptr;
    }

    return doGet(*context, IDBKeyRangeData(range), ec);
}
Esempio n. 12
0
int RockComMailbox::downloadRequest(int seg)
{
// 	LOG_ENTER("RockComMailbox::downloadRequest");
	//cout << hdr.uniqueId << endl;
// 	string page=doGet("http://mymail.rock.com/scripts/mail/"+hdr.uniqueId);
// 	smatch match;
// 	regex re("<A HREF=\"(/getattach/[^\"]*)");
// 	if(!regex_search(page,match,re))
// 		return 1;
// 	else
// 		return 0;
// 		throw MoorieException("Unable to download attachement.");
// 	setState(Mailbox::DownloadIP);
// 	setSegment(s);
// 	doGet("http://mymail.rock.com"+match[1]);
	std::string mylink = getLink(seg);
	setCookie(auth);
	page = doGet("http://mymail.rock.com/scripts/mail/"+mylink);
	boost::regex re("<A HREF=\"(/getattach/[^\"]*)");

	boost::smatch match;
	std::string link, downlink;
 	if(boost::regex_search(page,match,re)) {
		link=match[1];
//		cout << link << endl;
		downlink = "http://mymail.rock.com"+link;
		LOG(Log::Debug, downlink);
		downloadSeg();
		doGet(downlink);
		if (downloadSegDone() == 0)
			return 0;
		else
			return 1;
//		setState(Mailbox::DownloadIP);
//		setSegment(s);
	} else
		return 1;

}
Esempio n. 13
0
int MyNetMailbox::downloadRequest(int seg)
{
// 	LOG_ENTER("MyNetMailbox::downloadRequest");
        std::string page,dlink;

        std::string id = getLink(seg);
	page=doGet(mserv+"rbody2.php?mailbox=INBOX.Posta_kutusu&passed_id="+id);
	dlink=mserv+"download.php?absolute_dl=true&passed_id="+id+"&mailbox=INBOX.Posta_kutusu&ent_id=2";

	LOG(Log::Debug, dlink);
	downloadSeg();
	doGet(dlink);
// 	setSegment(s);

// 	dlink="download.php?absolute_dl=true&passed_id="+hdr.uniqueId+"&mailbox=INBOX.Posta_kutusu&ent_id=2";
// 	setState(Mailbox::DownloadIP);
// 	doGet(mserv+dlink);
	if (downloadSegDone() == 0)
		return 0;
	else
		return 1;
}
Esempio n. 14
0
RefPtr<IDBRequest> IDBIndex::get(ScriptExecutionContext& context, const Deprecated::ScriptValue& key, ExceptionCodeWithMessage& ec)
{
    LOG(IndexedDB, "IDBIndex::get");

    DOMRequestState requestState(&context);
    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key);
    if (!idbKey || idbKey->type() == KeyType::Invalid) {
        ec.code = IDBDatabaseException::DataError;
        ec.message = ASCIILiteral("Failed to execute 'get' on 'IDBIndex': The parameter is not a valid key.");
        return nullptr;
    }

    return doGet(context, IDBKeyRangeData(idbKey.get()), ec);
}
Esempio n. 15
0
int MyNetMailbox::loginRequest()
{
// 	LOG(Log::Debug,"MyNetMailbox::loginRequest");
// 	LOG(Log::Debug,"MyNetMailbox::State");
        std::string page,url,purl;
	url="http://eposta.mynet.com/index/mymail.html";
	page=doGet(url);
	purl="http://uyeler.mynet.com/login/login.asp?loginRequestingURL=http%3A%2F%2Feposta.mynet.com%2Findex%2Fmymail.html&formname=eposta";
                const std::string vars = std::string("faultCount=&faultyUser=&loginRequestingURL=")
		+ escape(url)
		+"&nameofservice=eposta&pageURL="
		+ escape(purl)
		+"&password="******"&rememberstate=2&rememberstatep=2&username="******"&x=0&y=0";
// 	setState(Mailbox::LoginIP);
	doPost("https://uyeler.mynet.com/index/uyegiris.html",vars);
	page=doGet(url,true);
        if(page.find("Merhaba "+getUser())==std::string::npos)
	{
// 		setState(Mailbox::LoginError); //login failure
// 		throw MoorieException("Login failed");
		return 1;
	}
// 	setState(Mailbox::LoginDone);
        boost::smatch match;
	//regex re("Location: (http[^\r\n]*)");
	//regex_search(page,match,re);
	//page=doGet(match[1]);
        boost::regex re("<a href=\"([^\"]*mynet.com/web2/src/showFolder.php\\?adu[^\"&]*)");
        boost::regex_search(page,match,re);
	auth=match[1];
// 	setState(Mailbox::Connected);
	return 0;
}
Esempio n. 16
0
int GoogleAppsMailbox::loginRequest()
{
    //const QRegExp moorhuntHashRegex("(<<a[a-h].*>>)");


    page = doGet("https://www.google.com/a/"+getMailbox());
    int pos = 0;
    QRegExp re3("GALX\\\".*value=\\\"(.*)\\\"./>");
    re3.setMinimal(true);
    if (re3.indexIn(page, pos) == -1)
        return 1;

    //LOG(Log::Info, page);
    const QString vars = QString("ltmpl=default&ltmplcache=2&continue=")
                + escape("https://mail.google.com/a/"+getMailbox()+"/")
                +"&service=mail&GALX="
                + escape(re3.cap(1))
                +"&rm=false&hl=pl&Email="+escape(getUser())
                +"&Passwd="+escape(getPassword())
                +"&rmShown=1";
    page = doPost("https://www.google.com/a/"+getMailbox()+"/LoginAction2?service=mail",vars, true);

    QString username = getUser();

    QRegExp re(username);
    QRegExp re2("&amp;");
    QRegExp authre("auth=([\\w\\d-]+)"); // To Do

    if (re.indexIn(page, pos) != -1)
    {
        QString url = re.cap(1);

        LOG(Log::Info, page + " <f");
        if(url.indexOf("answer=40695") != -1)
        {
            LOG(Log::Info, "Niestety, konto zostało wyłączone. - " + getMailbox());
            return 1;
        }
        url.replace(re2, "&");
        url = unescape(url);
        if (authre.indexIn(page, pos) != -1)
            auth = authre.cap(1);
            LOG(Log::Info, auth + " <s");
        return 0;
    }
    else
        return 1;
}
Esempio n. 17
0
double Nimbits::getValue(String point) {
  EthernetClient client;

  String content;

  content += "&id=";
  content +=  (_email + "/" + point);

  if (client.connect(_hostname.c_str(), _port)) {


    doGet(client, VALUE_API, content);
    String response = getFullResponse(client);


    String str = getContent(response);

      client.stop();


      int str_len = str.length() + 1;
      StaticJsonBuffer<256> jsonBuffer;
      char char_array[str_len];

      // Copy it over
      str.toCharArray(char_array, str_len);

      JsonObject& root = jsonBuffer.parseObject(char_array);

  if (!root.success()) {

    return -1.0;

  }

  double d = root["d"];

  return d;


  }
  else {

    client.stop();
    return 0;
  }

}
Esempio n. 18
0
RefPtr<WebCore::IDBRequest> IDBIndex::get(ScriptExecutionContext* context, const Deprecated::ScriptValue& key, ExceptionCode& ec)
{
    LOG(IndexedDB, "IDBIndex::get");

    if (!context) {
        ec = INVALID_STATE_ERR;
        return nullptr;
    }

    DOMRequestState requestState(context);
    RefPtr<IDBKey> idbKey = scriptValueToIDBKey(&requestState, key);
    if (!idbKey || idbKey->type() == KeyType::Invalid) {
        ec = static_cast<ExceptionCode>(IDBExceptionCode::DataError);
        return nullptr;
    }

    return doGet(*context, IDBKeyRangeData(idbKey.get()), ec);
}
//Funcion protocolo
void start_protocol(const int socket,const char *remoteFilename,const char *localFilename) {

	char writeBuffer[1024];
	char readBuffer[10240];
	int readBytes;
	char *cmdString;
	char *freeCmdString;
	char *ptr;
	char *token;

	sprintf(writeBuffer,"GET %s\r\n\r\n",remoteFilename);
	sendLine(socket,writeBuffer);
	
	//LEEMOS LA RESPUESTA AL GET
	cmdString = (char *) malloc(254);
	while((readBytes = read(socket,readBuffer,1))>0) {
		cmdString = (char *) realloc(cmdString,strlen(cmdString)+readBytes+1);
		strncat(cmdString,readBuffer,readBytes);
		ptr = cmdString+(strlen(cmdString)-4);
		if(strcmp(ptr,"\r\n\r\n")==0) {
			*ptr = '\0';
			break;
		}
	}
	
	freeCmdString = cmdString;
	
	debug(4,"Recibimos: %s\n",cmdString);
	token = strsep(&cmdString,"\r");
	cmdString++; // Eliminamos el \n de igual manera.
	
	if(strcmp(token,"NOT_FOUND")==0) {
		debug(1,"ERROR: Archivo no encontrado(%s)",token);
		return;
	} else if(strcmp(token,"OK")==0) {
		token = strstr(cmdString,":");
		doGet(socket,localFilename,strtol(token+2,NULL,10));
	} else {
		debug(1,"ERROR UNKOWN ANSWER (%s)",token);
	}
	
	sendLine(socket,"QUIT\r\n\r\n");
	free(freeCmdString);
}
//Funcion Protocolo
void start_protocol(const int clientSocket,const char baseDir[]) {

	char readBuffer[1024];
	int readBytes;
	char *cmdString;
	char *ptr;
	char *token;

	while(true) {
		cmdString = (char *) calloc(255,1);
		while((readBytes = read(clientSocket,readBuffer,1))>0) {
			cmdString = (char *) realloc(cmdString,strlen(cmdString)+readBytes+1);
			strncat(cmdString,readBuffer,readBytes);
			ptr = cmdString+(strlen(cmdString)-4);
			if(strcmp(ptr,"\r\n\r\n")==0) {
				*ptr = '\0';
				break;
			}
		}

		debug(4,"<- %s",cmdString);

		token = strtok(cmdString," \t\b");
		if(strcmp(token,"GET")==0) {
			token = strtok(NULL," \t\b");
			if(token == NULL) {
				sendLine(clientSocket, "ERROR ( Missing FileName )\r\n\r\n");
			} else {
				doGet(clientSocket,baseDir, token);
			}
		} else if(strcmp(token,"LIST")==0) {
			doList(clientSocket,baseDir);
		} else if(strcmp(token,"QUIT")==0) {
					break;
		} else {
			sendLine(clientSocket, "UNKOWN METHOD\r\n\r\n");
		}

		if(cmdString != NULL) free(cmdString);
	}

}
Esempio n. 21
0
int main(int argc, char *argv[])
{
  int sockfd, newsockfd, portno, clilen;
  char buffer[LEN_BUF];
  char msg[LEN_MSG];
  struct sockaddr_in serv_addr, cli_addr;
  int n, flag, i, pid;

  /* Command line arguments */
  if(argc < 2)
  {
    fprintf(stderr, "usage : %s <port>\n", argv[0]);
    exit(0);
  }

  /*call to socket() */
  sockfd=socket(AF_INET, SOCK_STREAM, 0);
  if(sockfd < 0)
  {
    perror("Error opening socket\n");
    exit(1);
  }

  /*initialize socket structure*/
  bzero((char *) &serv_addr, sizeof(serv_addr)); /* set serv_addr to zeros*/
  portno = atoi(argv[1]);
  printf("Starting proxy on %d\n", portno);
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr.s_addr = INADDR_ANY;
  serv_addr.sin_port = htons(portno);

  /* bind the host address */
  if(bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
  {
    perror("Error on binding\n");
    exit(1);
  }

  /* start listening for clients */
  listen(sockfd, 5);
  clilen = sizeof(cli_addr);
  printf("Proxy running...\nHave fun ! - kh\n");

  /* accept actual connection from client */
  while(1)
  {
    newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
    if(newsockfd < 0)
    {
      perror("Error on accept\n");
      exit(1);
    }

    /* if connection is established, get request */
    bzero(buffer, LEN_BUF);
    bzero(msg, LEN_MSG);
    printf("\nMessage:\n");
    flag = 0;
    while( (n = read(newsockfd, buffer, LEN_BUF-1)) > 0)
    {
      printf("%s", buffer);
      strcat(msg, buffer);
      /* check for \n\n */
      for(i = 0; i < strlen(msg); i++)
      {
        if(msg[i] == '\r')
        {
          if(msg[i+1] == '\n' && msg[i+2] == '\r' && msg[i+3] == '\n')
          {
            printf("\nHTTP Request accepted\n");
            flag = 1;
            break;
          }
        }
      }
      if(flag == 1)
        break;
    }

    /* Send HTTP Request to server */
    if(flag == 1)
    {
#ifdef MULTITHREAD
      pid = fork();
      if(pid == 0)
      {
#endif
        n = doGet(msg, newsockfd);
#ifdef MULTITHREAD
        printf("New thread %d created\n");
      }
#endif
    }
    else
    {
      n = write(newsockfd, "HTTP/1.0 400 Bad Request\n\n", 26);
      if(n < 0)
      {
        perror("Error writing to socket\n");
        exit(1);
      }
    }
#ifdef MULTITHREAD
    if(pid == 0)
    {
      printf("the thread %d fulfilled its destiny successfully\n", getpid());
      exit(0);
    }
#endif
  }
  return 0;
}
Esempio n. 22
0
ExceptionOr<Ref<IDBRequest>> IDBIndex::get(ExecState& execState, IDBKeyRange* range)
{
    LOG(IndexedDB, "IDBIndex::get");

    return doGet(execState, IDBKeyRangeData(range));
}
Esempio n. 23
0
int doAction(const QString& command, const QString& argument, QStringList *options)
{
	if(command == "get") return doGet(argument, options);
	if(command == "update") return doUpdate(argument, options);
	if(command == "install") return doInstall(argument, options);
}
Esempio n. 24
0
bool HttpServlet::start()
{
	socket_stream* in;
	socket_stream* out;
	bool cgi_mode;

	bool first = first_;
	if (first_)
		first_ = false;

	if (stream_ == NULL)
	{
		// 数据流为空,则当 CGI 模式处理,将标准输入输出
		// 作为数据流
		in = NEW socket_stream();
		in->open(ACL_VSTREAM_IN);

		out = NEW socket_stream();
		out->open(ACL_VSTREAM_OUT);
		cgi_mode = true;
	}
	else
	{
		in = out = stream_;
		cgi_mode = false;
	}

	// 在 HTTP 长连接重复请求情况下,以防万一,需要首先删除请求/响应对象
	delete req_;
	delete res_;

	res_ = NEW HttpServletResponse(*out);
	req_ = NEW HttpServletRequest(*res_, *session_, *in, local_charset_,
			 parse_body_enable_, parse_body_limit_);

	// 设置 HttpServletRequest 对象
	res_->setHttpServletRequest(req_);

	if (rw_timeout_ >= 0)
		req_->setRwTimeout(rw_timeout_);

	res_->setCgiMode(cgi_mode);

	string method_s(32);
	http_method_t method = req_->getMethod(&method_s);

	// 根据请求的值自动设定是否需要保持长连接
	if (!cgi_mode)
		res_->setKeepAlive(req_->isKeepAlive());

	bool  ret;

	switch (method)
	{
	case HTTP_METHOD_GET:
		if (upgradeWebsocket(*req_, *res_))
		{
			if (res_->sendHeader() == false)
			{
				logger_error("sendHeader error!");
				return false;
			}
			ret = doWebsocket(*req_, *res_);
		} else
			ret = doGet(*req_, *res_);
		break;
	case HTTP_METHOD_POST:
		ret = doPost(*req_, *res_);
		break;
	case HTTP_METHOD_PUT:
		ret = doPut(*req_, *res_);
		break;
	case HTTP_METHOD_CONNECT:
		ret = doConnect(*req_, *res_);
		break;
	case HTTP_METHOD_PURGE:
		ret = doPurge(*req_, *res_);
		break;
	case HTTP_METHOD_DELETE:
		ret = doDelete(*req_, *res_);
		break;
	case  HTTP_METHOD_HEAD:
		ret = doHead(*req_, *res_);
		break;
	case HTTP_METHOD_OPTION:
		ret = doOptions(*req_, *res_);
		break;
	case HTTP_METHOD_PROPFIND:
		ret = doPropfind(*req_, *res_);
		break;
	case HTTP_METHOD_OTHER:
		ret = doOther(*req_, *res_, method_s.c_str());
		break;
	default:
		ret = false; // 有可能是IO失败或未知方法
		if (req_->getLastError() == HTTP_REQ_ERR_METHOD)
			doUnknown(*req_, *res_);
		else if (first)
			doError(*req_, *res_);
		break;
	}

	if (in != out)
	{
		// 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑,
		// 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性
		// 这样可以保证与客户端保持长连接
		in->unbind();
		out->unbind();
		delete in;
		delete out;
	}

	return ret;
}
Esempio n. 25
0
bool HttpServlet::doRun(dbuf_pool* dbuf)
{
	socket_stream* in;
	socket_stream* out;
	bool cgi_mode;

	bool first = first_;
	if (first_)
		first_ = false;

	if (stream_ == NULL)
	{
		// 数据流为空,则当 CGI 模式处理,将标准输入输出
		// 作为数据流
		in = NEW socket_stream();
		in->open(ACL_VSTREAM_IN);

		out = NEW socket_stream();
		out->open(ACL_VSTREAM_OUT);
		cgi_mode = true;
	}
	else
	{
		in = out = stream_;
		cgi_mode = false;
	}

	// req/res 采用栈变量,减少内存分配次数

	HttpServletResponse res(*out, dbuf);
	HttpServletRequest req(res, *session_, *in, local_charset_,
		parse_body_enable_, parse_body_limit_, dbuf);

	// 设置 HttpServletRequest 对象
	res.setHttpServletRequest(&req);

	if (rw_timeout_ >= 0)
		req.setRwTimeout(rw_timeout_);

	res.setCgiMode(cgi_mode);

	string method_s(32);
	http_method_t method = req.getMethod(&method_s);

	// 根据请求的值自动设定是否需要保持长连接
	if (!cgi_mode)
		res.setKeepAlive(req.isKeepAlive());

	bool  ret;

	switch (method)
	{
	case HTTP_METHOD_GET:
		ret = doGet(req, res);
		break;
	case HTTP_METHOD_POST:
		ret = doPost(req, res);
		break;
	case HTTP_METHOD_PUT:
		ret = doPut(req, res);
		break;
	case HTTP_METHOD_CONNECT:
		ret = doConnect(req, res);
		break;
	case HTTP_METHOD_PURGE:
		ret = doPurge(req, res);
		break;
	case HTTP_METHOD_DELETE:
		ret = doDelete(req, res);
		break;
	case  HTTP_METHOD_HEAD:
		ret = doHead(req, res);
		break;
	case HTTP_METHOD_OPTION:
		ret = doOptions(req, res);
		break;
	case HTTP_METHOD_PROPFIND:
		ret = doPropfind(req, res);
		break;
	case HTTP_METHOD_OTHER:
		ret = doOther(req, res, method_s.c_str());
		break;
	default:
		ret = false; // 有可能是IO失败或未知方法
		if (req.getLastError() == HTTP_REQ_ERR_METHOD)
			doUnknown(req, res);
		else if (first)
			doError(req, res);
		break;
	}

	if (in != out)
	{
		// 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑,
		// 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性
		// 这样可以保证与客户端保持长连接
		in->unbind();
		out->unbind();
		delete in;
		delete out;
	}

	// 返回给上层调用者:true 表示继续保持长连接,否则表示需断开连接
	return ret && req.isKeepAlive()
		&& res.getHttpHeader().get_keep_alive();
}
Esempio n. 26
0
//
// SourceExpression_Binary::doSetBaseEmulated
//
void SourceExpression_Binary::doSetBaseEmulated(ObjectVector *objects,
   VariableData *dst, VariableData *src, VariableType *typeL)
{
   int tmpBase = 0;
   ObjectExpression::Pointer tmpA, tmpB;

   VariableData::Pointer tmp = VariableData::create_stack(src->size);

   if(dst->type != VariableData::MT_VOID)
      make_objects_memcpy_prep(objects, dst, tmp, pos);

   // For addressed variables, acquire the address now.
   if(src->type == VariableData::MT_ARRAY || src->type == VariableData::MT_FARPTR ||
      src->type == VariableData::MT_POINTER)
   {
      src->offsetTemp = VariableData::create_stack
                     (src->offsetExpr->getType()->getSize(pos));
      src->offsetExpr->makeObjects(objects, src->offsetTemp);

      if(src->type == VariableData::MT_FARPTR)
      {
         tmpB = context->getTempVar(tmpBase++);
         objects->addToken(OCODE_SET_TEMP, tmpB);
      }

      tmpA = context->getTempVar(tmpBase++);
      objects->addToken(OCODE_SET_TEMP, tmpA);
   }

   // Acquire exprL.
   doSetBaseGet(objects, src, tmpA, tmpB);

   // Put address, if any, before exprR.
   if(tmpA) objects->addToken(OCODE_GET_TEMP, tmpA);
   if(tmpB) objects->addToken(OCODE_GET_TEMP, tmpB);

   // Acquire exprR.
   if(docast)
      create_value_cast_explicit(exprR, typeL, context, pos)->makeObjects(objects, tmp);
   else
      exprR->makeObjects(objects, tmp);

   // Swap out exprR to get address, if needed.
   if(tmpB)
   {
      if(tmp->size == 1)
         objects->addToken(OCODE_STK_SWAP);
      else
         Error_NP("stub");

      objects->addToken(OCODE_SET_TEMP, tmpB);
   }

   if(tmpA)
   {
      if(tmp->size == 1)
      {
         objects->addToken(OCODE_STK_SWAP);
         objects->addToken(OCODE_SET_TEMP, tmpA);
      }
      else if(tmp->size == 2)
      {
         auto tmpC = context->getTempVar(tmpBase);
         objects->addToken(OCODE_SET_TEMP, tmpC);
         objects->addToken(OCODE_STK_SWAP);
         objects->addToken(OCODE_SET_TEMP, tmpA);
         objects->addToken(OCODE_GET_TEMP, tmpC);
      }
      else
         Error_NP("stub");
   }

   // Evaluate.
   doGet(objects, typeL, tmpBase);

   // Set exprL.
   doSetBaseSet(objects, src, tmpA, tmpB);

   if(dst->type != VariableData::MT_VOID)
   {
      doSetBaseGet(objects, src, tmpA, tmpB);

      make_objects_memcpy_post(objects, dst, tmp, typeL, context, pos);
   }
}
Esempio n. 27
0
bool HttpServlet::doRun(session& session, socket_stream* stream /* = NULL */,
	bool body_parse /* = true */, int body_limit /* = 102400 */)
{
	socket_stream* in;
	socket_stream* out;
	bool cgi_mode;

	if (stream == NULL)
	{
		// 数据流为空,则当 CGI 模式处理,将标准输入输出
		// 作为数据流
		stream = NEW socket_stream();
		(void) stream->open(ACL_VSTREAM_IN);
		in = stream;

		stream = NEW socket_stream();
		(void) stream->open(ACL_VSTREAM_OUT);
		out = stream;
		cgi_mode = true;
	}
	else
	{
		in = out = stream;
		cgi_mode = false;
	}

	// req/res 采用栈变量,减少内存分配次数

	HttpServletResponse res(*out);
	HttpServletRequest req(res, session, *in, local_charset_,
		body_parse, body_limit);

	if (rw_timeout_ >= 0)
		req.setRwTimeout(rw_timeout_);

	res.setCgiMode(cgi_mode);

	bool  ret;

	http_method_t method = req.getMethod();
	if (method == HTTP_METHOD_GET)
		ret = doGet(req, res);
	else if (method == HTTP_METHOD_POST)
		ret = doPost(req, res);
	else if (method == HTTP_METHOD_PUT)
		ret = doPut(req, res);
	else if (method == HTTP_METHOD_CONNECT)
		ret = doConnect(req, res);
	else if (method == HTTP_METHOD_PURGE)
		ret = doPurge(req, res);
	else
	{
		ret = false; // 有可能是IO失败或未知方法
		http_request_error_t n = req.getLastError();
		if (n == HTTP_REQ_ERR_METHOD)
			doUnknown(req, res);
		else
			doError(req, res);
	}

	if (in != out)
	{
		// 如果是标准输入输出流,则需要先将数据流与标准输入输出解绑,
		// 然后才能释放数据流对象,数据流内部会自动判断流句柄合法性
		// 这样可以保证与客户端保持长连接
		in->unbind();
		out->unbind();
		delete in;
		delete out;
	}

	return ret;
}
WASAPINotificationClient& WASAPINotificationClient::get() {
	// Hacky way of making sure we get a thread-safe yet lazy initialization of the static.
	boost::call_once(&WASAPINotificationClient::doGetOnce, notification_client_init_once);
	return doGet();
}
void CParameter::doGetValue(string& strValue, uint32_t uiOffset, CParameterAccessContext& parameterAccessContext) const
{
    doGet(strValue, uiOffset, parameterAccessContext);
}
Esempio n. 30
0
 //-----------------------------------------------------------------------
 void ParamCommand::doCopy(void* target, const void* source)
 {
     // Default implementation just get/set, derived class should be implement
     // their special case version for effective (i.e. avoid string conversion).
     doSet(target, doGet(source));
 }