예제 #1
0
void CAsyncQueueImpl::OnRequestArrive(unsigned short requestId, unsigned int len) {
    switch (requestId) {
    case Queue::idEnqueue:
        if (len < MAIN_THREAD_BYTES) {
            //if message size is small, we directly enqueue messages within main thread to avoid expensive thread context switch
            std::string key;
            unsigned short idMessage;
            m_UQueue >> key >> idMessage;
            SPA::UINT64 index;
            Enqueue(key, idMessage, index);
            DropCurrentSlowRequest();
            SendResult(requestId, index);
        }
        break;
    case Queue::idFlush:
    {
        unsigned int len = *((unsigned int*) m_UQueue.GetBuffer());
        int option = *((int*) m_UQueue.GetBuffer(sizeof (unsigned int) +len));
        if (option == (int) oMemoryCached) {
            //if option is oMemoryCached, we directly flush within main thread to avoid expensive thread context switch
            std::string key;
            m_UQueue >> key >> option;
            UINT64 messageCount, fileSize;
            Flush(key, option, messageCount, fileSize);
            DropCurrentSlowRequest();
            SendResult(requestId, messageCount, fileSize);
        }
    }
예제 #2
0
BOOL CMobileServer::ExecuteCommand(LPSTR pszCommand)
{
    if (strcmp(pszCommand, "Reset") == 0)
    {
        SendResult(MTPERR_COMMAND_OK);
        ResetSystem();
    }
    SendResult(MTPERR_COMMAND_ERROR);
    return TRUE;
}
예제 #3
0
static int CgiPostForm(HTTPD_SESSION *hs)
{
    char *arg;
    char *val;
    char *first = NULL;
    char *last = NULL;
    long avail;

    avail = hs->s_req.req_length;
    while (avail) {
        arg = HttpArgReadNext(hs, &avail);
        if (arg) {
            val = HttpArgValue(&hs->s_req);
            if (val) {
                if (strcmp(arg, "firstname") == 0) {
                    first = strdup(val);
                }
                else if (strcmp(arg, "familyname") == 0) {
                    last = strdup(val);
                }
            }
        }
    }
    SendResult(hs, first, last);
    free(first);
    free(last);

    return 0;
}
예제 #4
0
FinishGame::FinishGame(GameScene *_scene)
{
    scene = _scene;
    finishSreen = new FinishGameScreen();
    scene->addItem(finishSreen);

    btn_back = CreateBtn("Back");
    QObject::connect( btn_back, SIGNAL(pressed()), this, SLOT(BackClick()) );
    btn_back->move(100, 300);

    btn_repeat = CreateBtn("Repeat");
    QObject::connect( btn_repeat, SIGNAL(pressed()), this, SLOT(RepeatClick()) );
    btn_repeat->move(100, 450);

    btn_send_result = CreateBtn("Send Record");
    QObject::connect( btn_send_result, SIGNAL(pressed()), this, SLOT(SendResult()) );
    btn_send_result->move(100, 150);

    field_name = new QLineEdit;
    field_name->move(450, 200);
    field_name->setFont(QFont("Arial", 20));

    scene->addWidget(field_name);

    timer = new QTimer;
    timer->setInterval(50);
    QObject::connect( timer, SIGNAL(timeout()), this, SLOT(InputText()) );
    timer->start();

    is_saved_result = false;

    Hide();
}
예제 #5
0
static int CgiPostForm(HTTPD_SESSION *hs)
{
    char *arg;
    char *val;
    char *user = NULL;
    char *pwd = NULL;
    long avail;

    avail = hs->s_req.req_length;
    while (avail) {
        arg = HttpArgReadNext(hs, &avail);
        if (arg) {
            val = HttpArgValue(&hs->s_req);
            if (val) {
                if (strcmp(arg, "username") == 0) {
                    user = strdup(val);
                }
                else if (strcmp(arg, "password") == 0) {
                    pwd = strdup(val);
                }
            }
        }
    }
    if (strcmp(user, "Kevin") == 0) {
    	if (strcmp(pwd, "Kevin") == 0){
    		SendResult(hs, user, pwd);
    	}
    }
    //free(user);
    //free(pwd);

    return 0;
}
예제 #6
0
int GameSession( int players_number )
{
  GAME *game;

  LogInit();

  if ((game = AcceptPlayers(players_number)) == NULL)
  {
/*    MessageBox(NULL, strerror(GetLastError()), "Vse ochen ploho((", 0);*/
    return 0x239;
  }

  SendPropInfo(*game);

  while (1)
  {
    COMMAND command;
    RESULT result;

    command = ReadCommand(*game);
    result = CheckResult(game, command);
    SendResult(*game, result);
    game->Current_player = (game->Current_player + 1) % game->Players_number;

    if (result.Result == RESULT_WINNER)
    {
      EndGame(*game);
      free(game->Players);
      free(game);
      return 0x30;
    }
  }
}
예제 #7
0
bool KeyGrabPopupBox::Create(void)
{
    bool foundtheme = false;

    // Load the theme for this screen
    foundtheme = LoadWindowFromXML("controls-ui.xml", "keygrabpopup", this);

    if (!foundtheme)
        return false;

    m_messageText = dynamic_cast<MythUIText *> (GetChild("message"));
    m_okButton = dynamic_cast<MythUIButton *> (GetChild("ok"));
    m_cancelButton = dynamic_cast<MythUIButton *> (GetChild("cancel"));

    if (!m_messageText || !m_okButton || !m_cancelButton)
    {
        LOG(VB_GENERAL, LOG_ERR, "Theme is missing critical elements.");
        return false;
    }

    QString label = QString("%1\n\n%2").arg(tr("Press A Key"))
                                       .arg(tr("Waiting for key press"));

    m_messageText->SetText(label);

    connect(m_okButton, SIGNAL(Clicked()), SLOT(SendResult()));
    connect(m_cancelButton, SIGNAL(Clicked()), SLOT(Close()));

    m_okButton->SetEnabled(false);
    m_cancelButton->SetEnabled(false);

    BuildFocusList();

    SetFocusWidget(m_okButton);

    return true;
}
예제 #8
0
static int CgiGetForm(HTTPD_SESSION *hs)
{
    char *arg;
    char *val;
    char *first = NULL;
    char *last = NULL;

    for (arg = HttpArgParseFirst(&hs->s_req); arg; arg = HttpArgParseNext(&hs->s_req)) {
        val = HttpArgValue(&hs->s_req);
        if (val) {
            if (strcmp(arg, "firstname") == 0) {
                first = strdup(val);
            }
            else if (strcmp(arg, "familyname") == 0) {
                last = strdup(val);
            }
        }
    }
    SendResult(hs, first, last);
    free(first);
    free(last);

    return 0;
}
예제 #9
0
void CMobileServer::TerminateAlert()
{
    SendResult(MTPERR_TELNET_DISCONNECT);
}
XBOX::VError VChromeDbgHdlPage::TreatMsg()
{		
	XBOX::VError		l_err;
	XBOX::VString		l_cmd;
	XBOX::VString		l_resp;
	bool				l_found;
	sBYTE*				l_id;
	ChrmDbgMsg_t		l_msg;
	bool				l_msg_found;

	l_err = VE_OK;

	l_cmd = K_UNKNOWN_CMD;
	l_found = false;
	l_err = CheckInputData();

	VString l_trace("VChromeDbgHdlPage::TreatMsg Method=");
	l_trace += fMethod;
	if (fParams)
	{
		l_trace += " ,";
		VString l_params = "params=<";
		l_params.AppendCString(fParams);
		l_params += ">";
		l_trace += l_params;
	}
	sPrivateLogHandler->Put( (l_err != VE_OK ? WAKDBG_ERROR_LEVEL : WAKDBG_INFO_LEVEL),l_trace);

	if (!l_err)
	{
		DebugMsg("VChromeDbgHdlPage::TreatMsg Method='%S', Id='%s',Params='%s'\n",&fMethod,fId,(fParams ? fParams : "."));
	}
	else
	{
		DebugMsg("VChromeDbgHdlPage::TreatMsg CheckInputData pb !!!!\n");
	}

	l_cmd = K_APP_CAC_GET_FRA_WIT_MAN;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_APP_CAC_GET_FRA_WIT_MAN_STR1);
	}
#if 1
	l_cmd = K_APP_CAC_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	

		l_resp = K_APP_CAC_ENA_STR1;
		l_err = SendMsg(l_resp);
		if (!l_err)
		{
			l_err = SendResult(K_EMPTY_STR);
		}
	}

	l_cmd = K_DBG_REM_BRE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		sBYTE	*l_end;
		sBYTE	*l_tmp;
		l_tmp = strstr(fParams,K_BRK_PT_ID_STR);
		if (l_tmp)
		{
			l_tmp += strlen(K_BRK_PT_ID_STR)+1;// +1 to skip the '"'

			l_end = strchr(l_tmp,'"');
			if (l_end)
			{
				*l_end = 0;
				/*if (strstr(l_tmp,K_FILE_STR) == l_tmp)
				{
					l_tmp += strlen(K_FILE_STR);
				}*/
				l_end = strchr(l_tmp,':');
				if (l_end)
				{
					sscanf(l_end,":%d:",&l_msg.data.Msg.fLineNumber);
					*l_end = 0;
					l_msg.type = SEND_CMD_MSG;
					l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_REMOVE_BREAKPOINT_MSG;
					l_msg.data.Msg.fSrcId = fSrcId;
					//l_msg.data.Msg.fUrl[fURL.ToBlock(l_msg.data.Msg.fUrl,K_MAX_FILESIZE-1,VTC_UTF_8,false,false)] = 0;
					l_err = fOutFifo.Put(l_msg);
					if (testAssert( l_err == VE_OK ))
					{
						// we answer as success since wakanda is not able to return a status regarding bkpt handling
						l_err = SendResult(K_EMPTY_STR);
					}
				}
			}
		}
	}

	l_cmd = K_DBG_EVA_ON_CAL_FRA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		sBYTE*		l_tmp_exp;
		sBYTE*		l_ord;
		l_tmp_exp = strstr(fParams,K_EXPRESSION_STR);
		l_ord = strstr(fParams,K_ORDINAL_STR);
		if (l_tmp_exp && l_ord)
		{
			l_tmp_exp += strlen(K_EXPRESSION_STR);
			sBYTE *l_end_str;
			l_end_str = strchr(l_tmp_exp,'"');
			if (l_end_str)
			{
				l_msg.data.Msg.fLineNumber = atoi(l_ord+strlen(K_ORDINAL_STR));
				*l_end_str = 0;
				VString l_exp(l_tmp_exp);
				DebugMsg("requiring value of '%S'\n",&l_exp);
				//l_resp = CVSTR("\"result\":{\"type\":\"number\",\"value\":3,\"description\":\"3\"}");
				l_msg.type = SEND_CMD_MSG;
				l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_EVALUATE_MSG;
				l_msg.data.Msg.fSrcId = fSrcId;
				l_msg.data.Msg.fString[l_exp.ToBlock(l_msg.data.Msg.fString,K_MAX_FILESIZE-1,VTC_UTF_8,false,false)] = 0;
				l_err = fOutFifo.Put(l_msg);
				if (testAssert( l_err == VE_OK ))
				{
					l_err = fFifo.Get(&l_msg,&l_msg_found,0);
					if (testAssert( l_err == VE_OK ))
					{
						if (l_msg_found && (l_msg.type == EVAL_MSG))
						{
						}
						else
						{
							l_err = VE_INVALID_PARAMETER;
							xbox_assert(false);
						}
					}
				}
				l_resp = l_msg.data._dataStr;
				VString		l_hdr = CVSTR("\"result\":{\"value\":{");
				VString		l_sub;
				if (l_resp.GetLength() > l_hdr.GetLength())
				{
					l_resp.GetSubString(l_hdr.GetLength(),l_resp.GetLength()-l_hdr.GetLength()+1,l_sub);
				}
				l_resp = CVSTR("\"result\":");
				l_resp += l_sub;
				if (!l_err)
				{
					l_err = SendResult(l_resp);
				}
			}
			else
			{
				l_err = VE_INVALID_PARAMETER;
			}
		}
		else
		{
			l_err = VE_INVALID_PARAMETER;
		}
	}

	l_cmd = K_DBG_SET_BRE_BY_URL;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		sBYTE	*l_line_nb;
		sBYTE	*l_col_nb;
		sBYTE	*l_url;
		l_err = GetBrkptParams(fParams,&l_url,&l_col_nb,&l_line_nb);

		if (!l_err)
		{
			l_msg.type = SEND_CMD_MSG;
			l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_SET_BREAKPOINT_MSG;
			l_msg.data.Msg.fSrcId = fSrcId;
			l_msg.data.Msg.fLineNumber = atoi(l_line_nb);
			//l_msg.data.Msg.fUrl[fURL.ToBlock(l_msg.data.Msg.fUrl,K_MAX_FILESIZE-1,VTC_UTF_8,false,false)] = 0;
			l_err = fOutFifo.Put(l_msg);
			xbox_assert( l_err == VE_OK );
		}
		if (!l_err)
		{
			l_resp = K_DBG_SET_BRE_BY_URL_STR1;
			l_url[strlen(l_url)-1] = 0;// -1 is aimed to remove the final '"'
			l_resp += l_url;
			l_resp += ":";
			l_resp += l_line_nb;
			l_resp += ":";
			l_resp += l_col_nb;
			l_resp += K_DBG_SET_BRE_BY_URL_STR2;
			l_resp += fId;
			l_resp += "}";
			// we answer as success since wakanda is not able to return a status regarding bkpt handling
			l_err = SendMsg(l_resp);
		}
	}

	l_cmd = K_NET_GET_RES_BOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_resp = K_NET_GET_RES_BOD_STR1;
		l_resp += K_LINE_1;
		l_resp += K_LINE_2;
		l_resp += K_LINE_3;
		l_resp += K_LINE_4;
		l_resp += K_LINE_5;
		l_resp += K_LINE_6;
		l_resp += K_NET_GET_RES_BOD_STR2;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}
	
	l_cmd = K_PAG_GET_RES_CON;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_resp = K_PAG_GET_RES_CON_STR1;
		l_resp += K_LINE_1;
		l_resp += K_LINE_2;
		l_resp += K_LINE_3;
		l_resp += K_LINE_4;
		l_resp += K_LINE_5;
		l_resp += K_LINE_6;
		l_resp += K_PAG_GET_RES_CON_STR2;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}

	l_cmd = K_DOM_SET_INS_MOD_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DOM_PUS_NOD_BY_PAT_TO_FRO_END;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_resp = K_DOM_PUS_NOD_BY_PAT_TO_FRO_END_STR1;
		l_resp.AppendLong(fBodyNodeId);
		l_resp += K_ID_FMT_STR;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}
	
	l_cmd = K_PAG_REL;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		// page reload from CHrome not handled
		xbox_assert(false);
		l_err = VE_UNKNOWN_ERROR;
		return l_err;
#if 0

if (s_brkpt_line_nb.GetLength())
{
	return TreatPageReload(NULL);
	return l_err;
}
		l_resp = K_PAG_REL_STR1;
		l_err = SendMsg(l_resp);
		if (!l_err)
		{
			l_err = SendResult(K_EMPTY_STR);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR2;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR3;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR4;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR5;
			l_err = SendMsg(l_resp);
		}
		if (!l_err)
		{
			l_resp = K_PAG_REL_STR6;
			l_err = SendMsg(l_resp);
		}

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR7;
			l_err = SendMsg(l_resp);
		}

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR8;
			l_err = SendMsg(l_resp);
		}
				if (!l_err)
		{
			l_resp = K_PAG_REL_STR9;
			l_err = SendMsg(l_resp);
		}

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR10;
			l_err = SendMsg(l_resp);
		}		

		if (!l_err)
		{
			l_resp = K_PAG_REL_STR11;
			l_err = SendMsg(l_resp);
		}	
#endif
	}

	l_cmd = K_DBG_GET_SCR_SOU;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_SCRIPTID_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_SCRIPTID_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_id += strlen(K_SCRIPTID_ID_STR);
			sBYTE*	l_end = strchr(l_id,'"');
			if (l_end)
			{
				*l_end = 0;
				strncpy(l_msg.data.Msg.fString,l_id,K_STR_MAX_SIZE);
				l_msg.data.Msg.fString[K_STR_MAX_SIZE-1] = 0;
			}
			else
			{
				l_err = VE_INVALID_PARAMETER;
			}
		}
		l_resp = K_DBG_GET_SCR_SOU_STR1;

		if (!l_err)
		{
			for(VectorOfVString::iterator l_it = fSource.begin(); (l_it != fSource.end()); )
			{
				l_resp += *l_it;
				l_resp += K_LINE_FEED_STR;
				++l_it;
			}
		}
		else
		{
			l_resp += CVSTR(" NO SOURCE AVAILABLE ");
			l_resp += K_LINE_FEED_STR;
		}
		l_resp += "\"},\"id\":";
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);
	}
	
	l_cmd = K_RUN_GET_PRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_BACKSLASHED_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_BACKSLASHED_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_msg.type = SEND_CMD_MSG;
			l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_LOOKUP_MSG;
			l_msg.data.Msg.fObjRef = atoi(l_id+strlen(K_BACKSLASHED_ID_STR));
			l_err = fOutFifo.Put(l_msg);
			if (testAssert( l_err == VE_OK ))
			{
				l_err = fFifo.Get(&l_msg,&l_msg_found,0);
				xbox_assert( l_err == VE_OK );
			}
			if (!l_err)
			{
				if (l_msg_found && (l_msg.type != LOOKUP_MSG))
				{
					l_err = VE_INVALID_PARAMETER;
				}
				xbox_assert(l_err == VE_OK);
			}
		}
		if (!l_err)
		{
			l_resp = l_msg.data._dataStr;
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}

	l_cmd = K_DOM_HIG_FRA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DOM_HIG_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);

	}

	l_cmd = K_RUN_REL_OBJ_GRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DOM_REQ_CHI_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp = K_DOM_REQ_CHI_NOD_STR1;
			l_resp.AppendLong(fBodyNodeId);
			l_resp += K_DOM_REQ_CHI_NOD_STR2;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR3;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR4A;
			//l_resp += K_DOM_REQ_CHI_NOD_STR4B;
			//l_resp += K_DOM_REQ_CHI_NOD_STR4C;
			//l_resp += K_DOM_REQ_CHI_NOD_STR4D;
#if 1
			l_resp += "n";
			/*VectorOfVString::const_iterator l_it = fSource.begin();
			for(; l_it != fSource.end(); l_it++)
			{
				l_resp += *l_it;
				l_resp += K_LINE_FEED_STR;
			}*/
			l_resp+= "\\";
#endif
			l_resp += K_DOM_REQ_CHI_NOD_STR4E;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR5;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR6;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR7;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR8;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR9;
			l_resp.AppendLong(s_node_id++);
			l_resp += K_DOM_REQ_CHI_NOD_STR10;

			l_err = SendMsg(l_resp);

			if (!l_err)
			{
				l_err = SendResult(K_EMPTY_STR);
			}
		}

	}

	l_cmd = K_CON_ADD_INS_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}
	
	l_cmd = K_CSS_GET_MAT_STY_FOR_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp.AppendBlock(_binary_getMatchedStylesForNode,sizeof(_binary_getMatchedStylesForNode),VTC_UTF_8);
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}

	l_cmd = K_CSS_GET_INL_STY_FOR_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp.AppendBlock(_binary_getInlineStylesForNode,sizeof(_binary_getInlineStylesForNode),VTC_UTF_8);
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}
	l_cmd = K_CSS_GET_COM_STY_FOR_NOD;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_id = strstr(fParams,K_NODE_ID_STR);
		if (!l_id)
		{
			DebugMsg("NO %s param found for %S\n",K_NODE_ID_STR,&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err && (atoi(l_id+strlen(K_NODE_ID_STR)) != fBodyNodeId) )
		{
			DebugMsg("INCORRECT BODY node id for %S\n",&fMethod);
			l_err = VE_INVALID_PARAMETER;
		}
		if (!l_err)
		{
			l_resp.AppendBlock(_binary_getComputedStyleForNode,sizeof(_binary_getComputedStyleForNode),VTC_UTF_8);
			l_resp += fId;
			l_resp += "}";
			l_err = SendMsg(l_resp);
		}
	}
	
	l_cmd = K_DOM_GET_DOC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {

		l_resp = K_GET_DOC_STR1;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR2;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR3;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR4;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR5;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR6;
		fBodyNodeId = s_node_id;
		l_resp.AppendLong(s_node_id++);
		l_resp += K_GET_DOC_STR7A;
		l_resp += fFileName;
		l_resp += K_GET_DOC_STR7B;
		l_resp += fId;
		l_resp += "}";

		l_err = SendMsg(l_resp);
	}

	l_cmd = K_DOM_HID_HIG;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DBG_SET_PAU_ON_EXC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_TIM_SET_INC_MEM_DET;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_CSS_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_CSS_GET_SUP_PRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_resp.AppendBlock(_binary_getSupportedCSSProperties,sizeof(_binary_getSupportedCSSProperties),VTC_UTF_8);
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);

	}	
	
	l_cmd = K_DOM_STO_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DAT_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_INS_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		fEnabled = true;
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_CON_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_PRO_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DBG_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_DBG_CAN_SET_SCR_SOU;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_WOR_SET_WOR_INS_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_NET_CAN_CLE_BRO_CAC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_NET_CAN_CLE_BRO_COO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_PAG_GET_RES_TRE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_resp = K_PAG_GET_RES_TRE_STR1A;
		l_resp.AppendLong(fPageNb*K_FRAME_FACTOR);
		l_resp += K_PAG_GET_RES_TRE_STR1B;
		l_resp += fFileName;
		l_resp.AppendLong(fPageNb);
		l_resp += ".html";
		l_resp += K_PAG_GET_RES_TRE_STR1C;
		l_resp += fFileName;
		l_resp += K_PAG_GET_RES_TRE_STR1D;
		l_resp += fId;
		l_resp += "}";
		l_err = SendMsg(l_resp);

	}
	l_cmd = K_PAG_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_NET_ENA;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}

	l_cmd = K_PRO_HAS_HEA_PRO;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_PRO_IS_SAM;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_PRO_CAU_REC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {	
		l_err = SendResult(K_RESULT_FALSE_STR);
	}

	l_cmd = K_DBG_SUP_NAT_BRE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_TRUE_STR);
	}

	l_cmd = K_DBG_RES;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		fState = RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_CONTINUE_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_STE_INT;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		//fState = IJSWChrmDebugger::RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_STEP_INTO_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_STE_OUT;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		//fState = IJSWChrmDebugger::RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_STEP_OUT_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_STE_OVE;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
		//fState = IJSWChrmDebugger::RUNNING_STATE;
		if (!l_err)
		{
			l_resp = K_DBG_RES_STR;
			l_err = SendMsg(l_resp);
		}
		l_msg.type = SEND_CMD_MSG;
		l_msg.data.Msg.fType = WAKDebuggerServerMessage::SRV_STEP_OVER_MSG;
		l_err = fOutFifo.Put(l_msg);
		xbox_assert( l_err == VE_OK );
	}
	l_cmd = K_DBG_CAU_REC;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_RESULT_FALSE_STR);
	}
	l_cmd = K_DBG_PAU;
	if (!l_err && !l_found && (l_found = fMethod.EqualToString(l_cmd)) ) {
		l_err = SendResult(K_EMPTY_STR);
	}
	if (!l_found)
	{
		DebugMsg("VChromeDbgHdlPage::TreatMsg Method='%S' UNKNOWN!!!\n",&fMethod);
		exit(-1);
		return VE_OK;// --> pour l'instant on renvoit OK  !!! VE_INVALID_PARAMETER;
	}
#endif
	return l_err;

}
XBOX::VError VChromeDbgHdlPage::TreatPageReload(VString *inStr, intptr_t inSrcId)
{
	XBOX::VError		l_err;
	XBOX::VString		l_resp;

	VString l_trace("VChromeDbgHdlPage::TreatPageReload called");
	sPrivateLogHandler->Put( WAKDBG_INFO_LEVEL,l_trace);

	/*if (fSrcSent)
	{
		l_err = SendDbgPaused(inStr,inSrcId);
	}*/
	//else
	{
		l_resp = K_PAG_REL_AFT_BKPT_STR1A;
		l_resp += fFileName;
		l_resp += K_PAG_REL_AFT_BKPT_STR1B;
		l_resp += fFileName;
		l_resp += K_PAG_REL_AFT_BKPT_STR1C;
		l_err = SendMsg(l_resp);
		if (!l_err)
		{
			l_err = SendResult(K_EMPTY_STR);
			l_resp = K_PAG_REL_AFT_BKPT_STR2A;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR2B;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR3;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR4A;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR4B;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR5;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR6;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR7A1;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR7A2;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR7A3;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR7A4;
			l_resp.AppendLong(fPageNb);
			l_resp += K_PAG_REL_AFT_BKPT_STR7B;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR8;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR9A;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR9B;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR10;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR11A;
			l_resp.AppendULong8(inSrcId);
			l_resp += K_PAG_REL_AFT_BKPT_STR11B;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR11C;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			l_resp = K_PAG_REL_AFT_BKPT_STR12A1;
			l_resp += fFileName;
			l_resp += K_PAG_REL_AFT_BKPT_STR12A2;
			l_resp.AppendULong8(inSrcId);
			l_resp += K_PAG_REL_AFT_BKPT_STR12A3;
			l_resp.AppendLong(fPageNb);
			l_resp += K_PAG_REL_AFT_BKPT_STR12B;
		}
		if (!l_err)
		{
			l_err = SendMsg(l_resp);
			if (!l_err)
			{
				l_err = SendDbgPaused(inStr,inSrcId);
			}
			//fSrcSent = true;
		}
	}
	return l_err;
}
예제 #12
0
QTSS_Error FilterRequest(QTSS_Filter_Params* inParams)
{
    if (NULL == inParams || NULL == inParams->inRTSPSession || NULL == inParams->inRTSPRequest)
    {   Assert(0);
        return QTSS_NoErr;
    }

    OSMutexLocker locker(sAdminMutex);
    //check to see if we should handle this request. Invokation is triggered
    //by a "GET /" request
    
    QTSS_Error err = QTSS_NoErr;
    QTSS_RTSPRequestObject theRequest = inParams->inRTSPRequest;

    UInt32 paramLen = sizeof(sSessID);
    err = QTSS_GetValue(inParams->inRTSPSession, qtssRTSPSesID, 0, (void*)&sSessID, &paramLen);     
    if (err != QTSS_NoErr) 
        return QTSS_NoErr;

    StrPtrLen theFullRequest;
    err = QTSS_GetValuePtr(theRequest, qtssRTSPReqFullRequest, 0, (void**)&theFullRequest.Ptr, &theFullRequest.Len);
    if (err != QTSS_NoErr) 
        return QTSS_NoErr;
        
    
    StringParser fullRequest(&theFullRequest);
        
    if ( !IsAdminRequest(&fullRequest) ) 
        return QTSS_NoErr;
        
    if ( !AcceptSession(inParams->inRTSPSession) )
    {   (void)QTSS_Write(inParams->inRTSPRequest, sPermissionDeniedHeader, ::strlen(sPermissionDeniedHeader), NULL, 0);     
        (void)QTSS_Write(inParams->inRTSPRequest, sHTMLBody, ::strlen(sHTMLBody), NULL, 0);
        KeepSession(theRequest,false);
        return QTSS_NoErr;
    }
    
    if(!GetRequestAuthenticatedState(inParams)) // must authenticate before handling
    {
        if(QTSS_IsGlobalLocked()) // must NOT be global locked
            return QTSS_RequestFailed;
            
        if (!IsAuthentic(inParams,&fullRequest)) 
        {  
            (void)QTSS_Write(inParams->inRTSPRequest, sUnauthorizedResponseHeader, ::strlen(sUnauthorizedResponseHeader), NULL, 0);     
            (void)QTSS_Write(inParams->inRTSPRequest, sHTMLBody, ::strlen(sHTMLBody), NULL, 0);
            KeepSession(theRequest,false);
            return QTSS_NoErr;
        }
        
    }
    
    if (GetRequestFlushState(inParams)) 
    {   StillFlushing(inParams,true);
        return QTSS_NoErr;
    }
        
    if (!QTSS_IsGlobalLocked())
    {       
        if (InWaitInterval(inParams)) 
            return QTSS_NoErr; 

        //qtss_printf("New Request Wait for GlobalLock session=%"_U32BITARG_"\n",sSessID);
        (void)QTSS_RequestGlobalLock();
        KeepSession(theRequest,true);
        return QTSS_NoErr; 
    }
    
    //qtss_printf("Handle request session=%"_U32BITARG_"\n",sSessID);
    APITests_DEBUG();
    
    if (sQueryPtr != NULL) 
    {   delete sQueryPtr;
        sQueryPtr = NULL;   
    }
    sQueryPtr = NEW QueryURI(&theFullRequest);
    if (sQueryPtr == NULL) return QTSS_NoErr;
    
    ShowQuery_DEBUG();
    
    if (sAdminPtr != NULL) 
    {   delete sAdminPtr;
        sAdminPtr = NULL;
    }
    UInt32 result = sQueryPtr->EvalQuery(NULL, NULL);
    if (result == 0) do
    {
        if( ElementNode_CountPtrs() > 0)
        {   ElementNode_ShowPtrs();
            Assert(0);
        }
            
        GetQueryData(theRequest);
        
        SendResult(theRequest); 
        delete sAdminPtr;
        sAdminPtr = NULL;
        
        if (sQueryPtr && !sQueryPtr->QueryHasReponse())
        {   UInt32 err = 404;
            (void) sQueryPtr->EvalQuery(&err,NULL);
            ReportErr(inParams, err);
            break;
        }

        if (sQueryPtr && sQueryPtr->QueryHasReponse())
        {   ReportErr(inParams, sQueryPtr->GetEvaluResult());
        }
        
        if (sQueryPtr->fIsPref && sQueryPtr->GetEvaluResult() == 0)
        {   QTSS_ServiceID id;
            (void) QTSS_IDForService(QTSS_REREAD_PREFS_SERVICE, &id);           
            (void) QTSS_DoService(id, NULL);
        }
    } while(false);
    else
    {
        SendHeader(theRequest);         
        ReportErr(inParams, sQueryPtr->GetEvaluResult());
    }
    
    if (sQueryPtr != NULL) 
    {   delete sQueryPtr;
        sQueryPtr = NULL;
    }
    
    (void) StillFlushing(inParams,true);
    return QTSS_NoErr;

}
예제 #13
0
static int LoopSocket()
{
	assert(_listenfd!=-1);
	
	fd_set _fdset;

	//struct timeval tv = {100,0};
	
	struct sigaction act;
	act.sa_handler=acthandler; 
	sigemptyset(&act.sa_mask);//empty it
	act.sa_flags=0;
	if(sigaction(SIGCHLD,&act,NULL)==-1){
		printf("sigaction error %d\n", errno);////not good...............???
		return -1;
	}

	while(1)
	{	
		int maxfd=0;
		FD_ZERO(&_fdset);
		if(_listenfd>0)FD_SET(_listenfd, &_fdset);
		if(_broadcastfd>0)FD_SET(_broadcastfd, &_fdset);
		maxfd = (_broadcastfd>_listenfd)?_broadcastfd:_listenfd;
		
		//tv.tv_sec = 60000;
		//tv.tv_usec = 0;
		int res = select(1+maxfd , &_fdset, NULL, NULL, NULL);
		if(-1==res)
		{
			if(EINTR==errno)
			{
				printf("select EINTR\n");
				continue;
			}
			else
			{
				printf("[loop_socket]select errno=%d;\n", errno);
				break;
			}
		}
		else if(0==res)
		{
			printf("time up\n");
		}
		else if(FD_ISSET(_listenfd, &_fdset))
		{
			struct sockaddr_in addr;
			socklen_t addr_len = sizeof(struct sockaddr_in);	

			int tfd = accept(_listenfd, (struct sockaddr *)&addr, &addr_len);
			if(tfd>0)
			{
				if(_pid == -1)
				{
					CreateClientProcess(tfd);					
				}
				else
				{
					//should handle epipe......................todo......................
					SendResult(tfd, strdup("error:server be occupied\n"));			
					//printf("server be occupied by %d\n", _ctrlfd);
					shutdown(tfd, 0);
					close(tfd);
				}
			}
		}
		else if(FD_ISSET(_broadcastfd, &_fdset))
		{	
			printf("get for upd server\n");
			int i=0;
			struct sockaddr_in from_addr;
			socklen_t from_addr_len = sizeof(struct sockaddr_in);
			int err = recvfrom(_broadcastfd, &i, 4, 0, (struct sockaddr *)&from_addr, &from_addr_len);
			printf("_broadcastfd%d, %p, msg from %s, %d, err%d, %s\n", _broadcastfd, &_broadcastfd, inet_ntoa(from_addr.sin_addr), ntohs(from_addr.sin_port), err, strerror(errno));
			if(err==-1)
			{
				break;
			}
			if(i==0x5a)
			{
				printf("_broadcastfd yes\n");
				//notify server inerface
				struct sockaddr_in listen_addr;
				socklen_t addrlen = sizeof(listen_addr);
				if(getsockname(_listenfd, (struct sockaddr *)&listen_addr, &addrlen)==-1)
				{
					printf("[getsockname]errno=%d;\n", errno);
				}
				char ack[64];
				sprintf(ack, "notifyaddr:ip=%s:port=%d", inet_ntoa(listen_addr.sin_addr), ntohs(listen_addr.sin_port));
				
				sendto(_broadcastfd, ack, strlen(ack)+1, 0, (struct sockaddr*)&from_addr, from_addr_len);
			}

		}
		else
		{}
	}

	return 0;
}
예제 #14
0
static int CreateClientProcess(int fd)
{
	int pid=0;
	pid=fork();
	if(pid==0)
	{
		signal(SIGCHLD, SIG_DFL);
		close(_listenfd);
		close(_broadcastfd);
		printf("fork new pid=%d, fd=%d\n", pid, fd);

		sleep(2);
		
		char *_recvBuf = 0;
		int RECV_BUFF_LEN = 1024;
		while((_recvBuf = (char *)malloc(RECV_BUFF_LEN))==NULL)
		{
			sleep(1);
		}

		printf("_recvBuf=%p\n", _recvBuf);
		
		while(1)
		{
			int err = ReadCmd(fd, _recvBuf, RECV_BUFF_LEN);
			if(err <= 0)
			{
				printf("ReadCmd connect close %d\n", fd);
				break;
			}
			
			void* result = HandleCmd(fd, _recvBuf, NULL, 0);

			err = SendResult(fd, result);
			if(err <= 0)
			{
				printf("SendResult error\n");
				break;
			}

			free(result);
		}

		if(_recvBuf) free(_recvBuf);
		
		shutdown(fd, SHUT_RD);
		close(fd);
		exit(0);
		printf("fork new end%d\n", pid);

	}
	else if(pid>0)
	{
		printf("CreateClientProcess fork main %d\n", pid);
		_pid=pid;
		close(fd);
		//sleep(2);
	}
	else if(pid==-1)
	{
		printf("CreateClientProcess fork error %d\n", pid);
	}

	return pid;
}
예제 #15
0
void
avtDataObjectInformation::ParallelMerge(const avtDataObjectWriter_p dobw)
{
#ifdef PARALLEL

    int groupSize = 1;
    int myRank, commSize;

    MPI_Comm_size(VISIT_MPI_COMM, &commSize);
    MPI_Comm_rank(VISIT_MPI_COMM, &myRank);
    int mpiResultLenTag = GetUniqueMessageTag();
    int mpiResultStrTag = GetUniqueMessageTag();
    int mpiSwapLenTag   = GetUniqueMessageTag();
    int mpiSwapStrTag   = GetUniqueMessageTag();
    groupSize = 1;

    // walk up the communication tree, swapping and merging infos
    while (groupSize < commSize)
    {
        int swapWithProc = -1;
        int myGroupNum = myRank / groupSize;
        int myGroupIdx = myRank % groupSize;

        // determine processor to swap with
        if (myGroupNum % 2)   // myGroupNum is odd
            swapWithProc = (myGroupNum - 1) * groupSize + myGroupIdx;
        else                  // myGroupNum is even
            swapWithProc = (myGroupNum + 1) * groupSize + myGroupIdx;

        // only do the swap between 0th processors in each group AND only
        // if the processor to swap with is in range of communicator
        if ((myGroupIdx == 0) &&
                (0 <= swapWithProc) && (swapWithProc < commSize))
            SwapAndMerge(dobw, swapWithProc, mpiSwapLenTag, mpiSwapStrTag);

        groupSize <<= 1;
    }

    // At this point the processor(s) at the top of the tree have the
    // merged result. So, now we need to re-distribute it to all
    groupSize >>= 2;

    // walk back down the communication tree, sending results
    while (groupSize >= 1)
    {
        int swapWithProc = -1;
        int myGroupNum = myRank / groupSize;
        int myGroupIdx = myRank % groupSize;

        // determine processor to send to
        if (myGroupNum % 2)   // myGroupNum is odd
        {
            swapWithProc = (myGroupNum - 1) * groupSize + myGroupIdx;
            if ((myGroupIdx == 0) &&
                    (0 <= swapWithProc) && (swapWithProc < commSize))
                RecvResult(dobw, swapWithProc, mpiResultLenTag, mpiResultStrTag);
        }
        else                  // myGroupNum is even
        {
            swapWithProc = (myGroupNum + 1) * groupSize + myGroupIdx;
            if ((myGroupIdx == 0) &&
                    (0 <= swapWithProc) && (swapWithProc < commSize))
                SendResult(dobw, swapWithProc, mpiResultLenTag, mpiResultStrTag);
        }

        groupSize >>= 1;
    }

#endif

    // indicate that it is ok to use this processor's extents as global extents;
    GetAttributes().SetCanUseThisProcsAsOriginalOrActual(true);
}
예제 #16
0
void CMobileServer::OnPut(WORKSESSION *pSession, LPSTR pszBuffer, int nLength)
{
    MFRAMEHEADER	*pHeader;
    MFRAME			*pFrame;
    WORD	crc, crc1;
    BOOL	bChecksum;
    int		i, len, nSeek=1;
    BYTE	c, *p;
    char    buffer[1024];

    for(i=0; i<nLength; i+=nSeek)
    {
        nSeek = 1;
        c = pszBuffer[i];
        switch(m_theHeader.nState) {
        case PUT_STATE_WHITE :
            if (c != '[')
                break;
            m_Chunk.Add(c);
            m_theHeader.nState = PUT_STATE_IDENT;
            break;

        case PUT_STATE_IDENT :
            if (c != '@')
            {
                m_Chunk.Flush();
                m_theHeader.nState = PUT_STATE_WHITE;
                break;
            }
            m_Chunk.Add(c);
            m_theHeader.nState = PUT_STATE_SEQ;
            break;

        case PUT_STATE_SEQ :
            if (m_theHeader.nSeq != c)
            {
                m_Chunk.Flush();
                WriteToModem(MOBILE_NAK);
                m_theHeader.nState = PUT_STATE_WHITE;
                break;
            }
            m_Chunk.Add(c);
            m_theHeader.nState = PUT_STATE_HEADER;
            break;

        case PUT_STATE_HEADER :
            nSeek = MIN(nLength-i, (int)sizeof(MFRAMEHEADER)-m_Chunk.GetSize());
            m_Chunk.Add(pszBuffer+i, nSeek);
            if (m_Chunk.GetSize() < (int)sizeof(MFRAMEHEADER))
                break;
            pHeader = (MFRAMEHEADER *)m_Chunk.GetBuffer();
            if (pHeader->len > 4096)
            {
                m_Chunk.Flush();
                WriteToModem(MOBILE_NAK);
                m_theHeader.nState = PUT_STATE_WHITE;
                break;
            }
            m_theHeader.nFrameSize = pHeader->len;
            m_theHeader.nState = PUT_STATE_DATA;
            break;

        case PUT_STATE_DATA :
            len   = m_theHeader.nFrameSize + sizeof(MFRAMEHEADER) + sizeof(MFRAMETAIL);
            nSeek = MIN(nLength-i, len-m_Chunk.GetSize());
            m_Chunk.Add(pszBuffer+i, nSeek);
            if (m_Chunk.GetSize() < len)
                break;

            pFrame = (MFRAME *)m_Chunk.GetBuffer();
            crc  = GetCrc((BYTE *)m_Chunk.GetBuffer(), pFrame->hdr.len+sizeof(MFRAMEHEADER), 0);
            p    = (BYTE *)(m_Chunk.GetBuffer() + pFrame->hdr.len + sizeof(MFRAMEHEADER));
            memcpy(&crc1, p, sizeof(WORD));
            bChecksum = (crc == crc1) ? TRUE : FALSE;

            // printf("MOBILE-PUT: SEQ=%d, CRC=0x%04X(0x%04X), Checksum=%s\r\n",
            // pFrame->hdr.seq, crc1, crc, bChecksum ? "Ok" : "Error");

            if (bChecksum)
            {
                m_theHeader.nSeq++;
                fwrite(pFrame->data, 1, m_theHeader.nFrameSize, m_theHeader.fp);
                m_theHeader.nSeek += m_theHeader.nFrameSize;
                m_theHeader.nErrorCount = 0;
                WriteToModem(MOBILE_ACK);
            }
            else
            {
                m_theHeader.nErrorCount++;
                WriteToModem(MOBILE_NAK);
            }
            /*
            printf("Total=%d, Current=%d, Packet=%d\r\n",
            	m_theHeader.nLength, m_theHeader.nSeek, m_theHeader.nFrameSize);
            printf("szURL=%s, bInstall=%s\r\n", m_theHeader.szURL, m_theHeader.bInstall ? "yes" : "no");
            */

            if (m_theHeader.nLength <= m_theHeader.nSeek)
            {
                // Download Ok
                fclose(m_theHeader.fp);
                m_theHeader.fp = NULL;

                if (m_theHeader.bInstall)
                    SendResult(MTPERR_INSTALL_START);
                sprintf(buffer, "mv /tmp/upload.tmp %s", m_theHeader.szURL);
                system(buffer);
                if (m_theHeader.bInstall)
                    FirmwareUpdate(m_theHeader.szURL);
                if (m_theHeader.bInstall)
                    SendResult(MTPERR_INSTALL_END);
            }
            m_Chunk.Flush();
            m_theHeader.nState = PUT_STATE_WHITE;
            break;
        }

    }
}
예제 #17
0
BOOL CMobileServer::OnReceiveSession(WORKSESSION *pSession, LPSTR pszBuffer, int nLength)
{
    char	*p, *p1, *pszHeader;
    int		i, len;

    time(&m_tmLastReceived);
//	printf("MobileServer: %d Bytes recv.\r\n", nLength);
//	DUMPSTRING(pszBuffer, nLength);

#ifdef __TEST_ONLY__
//  int     nError;
//	IF4Invoke	*pInvoke;
//  CIF4Invoke  invoke("192.168.0.23", 8000, 60);
//
//	pInvoke = invoke.GetHandle();
//	pInvoke->bAsync = TRUE;
//
//  invoke.AddParam("4.2.1", 5);
//  invoke.AddParam("4.2.2", 1);
//  invoke.AddParam("1.9", 0);
//
//  nError = invoke.Command("104.12", IF4_CMDATTR_REQUEST | IF4_CMDATTR_MCUIPC | IF4_CMDATTR_RESPONSE);
//  if (nError != IF4ERR_NOERROR)
//      printf("ERROR: %s\r\n", IF4API_GetErrorMessage(nError));
#endif

    if (m_nState != STATE_DATA)
    {
        m_Chunk.Add(pszBuffer, nLength);
        m_Chunk.Close();
        p   = m_Chunk.GetBuffer();
        len = m_Chunk.GetSize();

        pszHeader = NULL;
        for(i=0; i<len; i++)
        {
            if (strncmp(p+i, "NURI/", 5) == 0)
            {
                pszHeader = p+i;
                break;
            }
        }

        if (len >= 512)
        {
            m_Chunk.Flush();
            return TRUE;
        }

        if (pszHeader == NULL)
            return TRUE;

        p1 = strstr(pszHeader, "\n\n");
        if (p1 == NULL)
            p1 = strstr(pszHeader, "\r\r");
        if (p1 == NULL)
            p1 = strstr(pszHeader, "\r\n\r\n");
        if (p1 == NULL)
            return TRUE;

        *p1 = '\0';
        if (GetHeader(&m_theHeader, pszHeader, strlen(pszHeader)))
        {
            m_bLiveSession = TRUE;
            switch(m_theHeader.nMethod) {
            case MOBILE_METHOD_TELNET :
                SendResult(MTPERR_TELNET_ACCEPT);
                usleep(1000000);
                m_theClient.NewConnection(atoi(m_theHeader.szURL));
                m_nState = STATE_DATA;
                break;

            case MOBILE_METHOD_NACS :
                SendResult(MTPERR_NACS_ACCEPT);
                usleep(1000000);
                m_theClient.NewConnection(atoi(m_theHeader.szURL));
                m_nState = STATE_DATA;
                break;

            case MOBILE_METHOD_COMMAND :
                ExecuteCommand(m_theHeader.szURL);
                break;

            case MOBILE_METHOD_GET :
                SendResult(MTPERR_GET_ACCEPT);
                m_nState = STATE_DATA;
                break;

            case MOBILE_METHOD_PUT :
                SendResult(MTPERR_PUT_ACCEPT);
                m_theHeader.fp = fopen("/tmp/upload.tmp", "wb");
                m_nState = STATE_DATA;
                break;

            case MOBILE_METHOD_LIST :
                SendResult(MTPERR_LIST_ACCEPT);
                m_nState = STATE_DATA;
                break;
            }
        }
        else
        {
            // Return to error message
            SendResult(MTPERR_INVALID_REQUEST);
        }

        m_Chunk.Flush();
        return TRUE;
    }

    switch(m_theHeader.nMethod) {
    case MOBILE_METHOD_TELNET :
    case MOBILE_METHOD_NACS :
        m_theClient.SendToHost(pszBuffer, nLength);
        break;

    case MOBILE_METHOD_GET :
        break;

    case MOBILE_METHOD_PUT :
        OnPut(pSession, pszBuffer, nLength);
        break;

    case MOBILE_METHOD_LIST :
        break;
    }
    return TRUE;
}