Beispiel #1
0
void JsonRpcServer::jsonRequestReceived(const QJsonObject& request,
                                        QObject* socket)
{
    JCON_ASSERT(request.value("jsonrpc").toString() == "2.0");

    if (request.value("jsonrpc").toString() != "2.0") {
        logError("invalid protocol tag");
        return;
    }

    QString method_name = request.value("method").toString();
    if (method_name.isEmpty()) {
        logError("no method present in request");
    }

    QVariant params = request.value("params").toVariant();

    QString request_id = request.value("id").toString(InvalidRequestId);

    QVariant return_value;
    if (!dispatch(method_name, params, request_id, return_value)) {
        auto msg = QString("method '%1' not found, check name and "
                           "parameter types ").arg(method_name);
        logError(msg);

        // send error response if request had valid ID
        if (request_id != InvalidRequestId) {
            QJsonDocument error =
                createErrorResponse(request_id,
                                    JsonRpcError::EC_MethodNotFound,
                                    msg);

            JsonRpcEndpoint* endpoint = findClient(socket);
            if (!endpoint) {
                logError("invalid client socket, cannot send response");
                return;
            }

            endpoint->send(error);
            return;
        }
    }

    // send response if request had valid ID
    if (request_id != InvalidRequestId) {
        QJsonDocument response = createResponse(request_id,
                                                return_value,
                                                method_name);

        JsonRpcEndpoint* endpoint = findClient(socket);
        if (!endpoint) {
            logError("invalid client socket, cannot send response");
            return;
        }

        endpoint->send(response);
    }
}
Beispiel #2
0
ACSIClient *addClient(ACSIClient *client_list, char ip[48], int port) {
	if (client_list == NULL) {
		client_list = (ACSIClient *) calloc(1, sizeof(ACSIClient));
		memcpy(client_list->ip, ip, 48);
		client_list->port = port;
		return client_list;
	}

	ACSIClient *found = findClient(client_list, ip, port);

	if (found == NULL) {
		ACSIClient *end = client_list;
		while (end->next != NULL) {
			end = end->next;
		}

		end->next = (ACSIClient *) calloc(1, sizeof(ACSIClient));
		memcpy(end->next->ip, ip, 48);
		end->next->port = port;
		return end->next;

		return end;
	}
	else {
		return found;
	}
}
Beispiel #3
0
bool WaitingList::clientLogin(const Player* player)
{
	if(player->hasFlag(PlayerFlag_CanAlwaysLogin) || player->getAccountType() >= ACCOUNT_TYPE_GAMEMASTER || player->isAccountManager())
		return true;

	if(waitList.empty() && Status::getInstance()->getPlayersOnline() < Status::getInstance()->getMaxPlayersOnline())
	{
		//no waiting list and enough room
		return true;
	}

	cleanUpList();

	uint32_t slot;
	WaitListIterator it = findClient(player, slot);
	if(it != waitList.end())
	{
		if((Status::getInstance()->getPlayersOnline() + slot) <= Status::getInstance()->getMaxPlayersOnline())
		{
			//should be able to login now
			delete *it;
			waitList.erase(it);
			return true;
		}
		else
		{
			//let them wait a bit longer
			(*it)->timeout = OTSYS_TIME() + (getTimeOut(slot) * 1000);
			return false;
		}
	}

	Wait* wait = new Wait();

	if(player->isPremium())
	{
		slot = 1;
		for(WaitListIterator it = waitList.begin(); it != waitList.end(); ++it)
		{
			if(!(*it)->premium)
			{
				waitList.insert(it, wait);
				break;
			}
			++slot;
		}
	}
	else
	{
		waitList.push_back(wait);
		slot = (uint32_t)waitList.size();
	}

	wait->name = player->getName();
	wait->acc = player->getAccount();
	wait->ip = player->getIP();
	wait->premium = player->isPremium();
	wait->timeout = OTSYS_TIME() + (getTimeOut(slot) * 1000);
	return false;
}
Beispiel #4
0
static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
			  unsigned char *buf, size_t nr)
{
   struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data;
   struct r3964_client_info *pClient;
   struct r3964_message *pMsg;
   struct r3964_client_message theMsg;
   DECLARE_WAITQUEUE (wait, current);
   
   int pid = current->pid;
   int count;
   
   TRACE_L("read()");
 
   pClient=findClient(pInfo, pid);
   if(pClient)
   {
      pMsg = remove_msg(pInfo, pClient);
      if(pMsg==NULL)
      {
		 /* no messages available. */
         if (file->f_flags & O_NONBLOCK)
		 {
            return -EAGAIN;
		 }
         /* block until there is a message: */
         add_wait_queue(&pInfo->read_wait, &wait);
repeat:
         current->state = TASK_INTERRUPTIBLE;
         pMsg = remove_msg(pInfo, pClient);
	 if (!pMsg && !signal_pending(current))
		 {
            schedule();
            goto repeat;
         }
         current->state = TASK_RUNNING;
         remove_wait_queue(&pInfo->read_wait, &wait);
      }
      
      /* If we still haven't got a message, we must have been signalled */

      if (!pMsg) return -EINTR;

      /* deliver msg to client process: */
      theMsg.msg_id = pMsg->msg_id;
      theMsg.arg    = pMsg->arg;
      theMsg.error_code = pMsg->error_code;
      count = sizeof(struct r3964_client_message);

      kfree(pMsg);
      TRACE_M("r3964_read - msg kfree %x",(int)pMsg);

      if (copy_to_user(buf,&theMsg, count))
	return -EFAULT;

      TRACE_PS("read - return %d", count);
      return count;
   }
   return -EPERM;
}
Beispiel #5
0
/* Called without the kernel lock held - fine */
static unsigned int r3964_poll(struct tty_struct * tty, struct file * file,
		      struct poll_table_struct *wait)
{
   struct r3964_info *pInfo=(struct r3964_info*)tty->disc_data;
   int pid=current->pid;
   struct r3964_client_info *pClient;
   struct r3964_message *pMsg=NULL;
   unsigned long flags;
   int result = POLLOUT;

   TRACE_L("POLL");

   pClient=findClient(pInfo,pid);
   if(pClient)
     {
       poll_wait(file, &pInfo->read_wait, wait);
       save_flags(flags);
       cli();
       pMsg=pClient->first_msg;
       restore_flags(flags);
       if(pMsg)
	   result |= POLLIN | POLLRDNORM;
     }
   else
     {
       result = -EINVAL;
     }
   return result;
}
Beispiel #6
0
static int read_telegram(struct r3964_info *pInfo, struct pid *pid,
			 unsigned char __user * buf)
{
	struct r3964_client_info *pClient;
	struct r3964_block_header *block;

	if (!buf) {
		return -EINVAL;
	}

	pClient = findClient(pInfo, pid);
	if (pClient == NULL) {
		return -EINVAL;
	}

	block = pClient->next_block_to_read;
	if (!block) {
		return 0;
	} else {
		if (copy_to_user(buf, block->data, block->length))
			return -EFAULT;

		remove_client_block(pInfo, pClient);
		return block->length;
	}

	return -EINVAL;
}
Beispiel #7
0
static int enable_signals(struct r3964_info *pInfo, struct pid *pid, int arg)
{
	struct r3964_client_info *pClient;
	struct r3964_client_info **ppClient;
	struct r3964_message *pMsg;

	if ((arg & R3964_SIG_ALL) == 0) {
		/* Remove client from client list */
		for (ppClient = &pInfo->firstClient; *ppClient;
		     ppClient = &(*ppClient)->next) {
			pClient = *ppClient;

			if (pClient->pid == pid) {
				TRACE_PS("removing client %d from client list",
					 pid_nr(pid));
				*ppClient = pClient->next;
				while (pClient->msg_count) {
					pMsg = remove_msg(pInfo, pClient);
					if (pMsg) {
						kfree(pMsg);
						TRACE_M("enable_signals - msg "
							"kfree %p", pMsg);
					}
				}
				put_pid(pClient->pid);
				kfree(pClient);
				TRACE_M("enable_signals - kfree %p", pClient);
				return 0;
			}
		}
		return -EINVAL;
	} else {
		pClient = findClient(pInfo, pid);
		if (pClient) {
			/* update signal options */
			pClient->sig_flags = arg;
		} else {
			/* add client to client list */
			pClient = kmalloc(sizeof(struct r3964_client_info),
					GFP_KERNEL);
			TRACE_M("enable_signals - kmalloc %p", pClient);
			if (pClient == NULL)
				return -ENOMEM;

			TRACE_PS("add client %d to client list", pid_nr(pid));
			spin_lock_init(&pClient->lock);
			pClient->sig_flags = arg;
			pClient->pid = get_pid(pid);
			pClient->next = pInfo->firstClient;
			pClient->first_msg = NULL;
			pClient->last_msg = NULL;
			pClient->next_block_to_read = NULL;
			pClient->msg_count = 0;
			pInfo->firstClient = pClient;
		}
	}

	return 0;
}
Beispiel #8
0
int32_t WaitingList::getClientSlot(const Player* player)
{
	uint32_t slot;
	WaitListIterator it = findClient(player, slot);
	if(it != waitList.end())
		return slot;

	return -1;
}
// Client port finder by id.
qjackctlAlsaPort *qjackctlAlsaClientList::findClientPort ( int iAlsaClient,
	int iAlsaPort )
{
	qjackctlAlsaClient *pClient = findClient(iAlsaClient);
	if (pClient == NULL)
		return NULL;

	return pClient->findPort(iAlsaPort);
}
static ssize_t r3964_write(struct tty_struct *tty, struct file *file,
			   const unsigned char *data, size_t count)
{
	struct r3964_info *pInfo = tty->disc_data;
	struct r3964_block_header *pHeader;
	struct r3964_client_info *pClient;
	unsigned char *new_data;

	TRACE_L("write request, %d characters", count);

	if (!pInfo)
		return -EIO;

	if (count > R3964_MTU) {
		if (pInfo->flags & R3964_DEBUG) {
			TRACE_L(KERN_WARNING "r3964_write: truncating user "
				"packet from %u to mtu %d", count, R3964_MTU);
		}
		count = R3964_MTU;
	}
	new_data = kmalloc(count + sizeof(struct r3964_block_header),
			GFP_KERNEL);
	TRACE_M("r3964_write - kmalloc %p", new_data);
	if (new_data == NULL) {
		if (pInfo->flags & R3964_DEBUG) {
			printk(KERN_ERR "r3964_write: no memory\n");
		}
		return -ENOSPC;
	}

	pHeader = (struct r3964_block_header *)new_data;
	pHeader->data = new_data + sizeof(struct r3964_block_header);
	pHeader->length = count;
	pHeader->locks = 0;
	pHeader->owner = NULL;

	tty_lock();

	pClient = findClient(pInfo, task_pid(current));
	if (pClient) {
		pHeader->owner = pClient;
	}

	memcpy(pHeader->data, data, count);	

	if (pInfo->flags & R3964_DEBUG) {
		dump_block(pHeader->data, count);
	}

	add_tx_queue(pInfo, pHeader);
	trigger_transmit(pInfo);

	tty_unlock();

	return 0;
}
Beispiel #11
0
static ssize_t r3964_read(struct tty_struct *tty, struct file *file,
			  unsigned char __user * buf, size_t nr)
{
	struct r3964_info *pInfo = tty->disc_data;
	struct r3964_client_info *pClient;
	struct r3964_message *pMsg;
	struct r3964_client_message theMsg;
	int ret;

	TRACE_L("read()");

	tty_lock();

	pClient = findClient(pInfo, task_pid(current));
	if (pClient) {
		pMsg = remove_msg(pInfo, pClient);
		if (pMsg == NULL) {
			/* no messages available. */
			if (file->f_flags & O_NONBLOCK) {
				ret = -EAGAIN;
				goto unlock;
			}
			/* block until there is a message: */
			wait_event_interruptible_tty(pInfo->read_wait,
					(pMsg = remove_msg(pInfo, pClient)));
		}

		/* If we still haven't got a message, we must have been signalled */

		if (!pMsg) {
			ret = -EINTR;
			goto unlock;
		}

		/* deliver msg to client process: */
		theMsg.msg_id = pMsg->msg_id;
		theMsg.arg = pMsg->arg;
		theMsg.error_code = pMsg->error_code;
		ret = sizeof(struct r3964_client_message);

		kfree(pMsg);
		TRACE_M("r3964_read - msg kfree %p", pMsg);

		if (copy_to_user(buf, &theMsg, ret)) {
			ret = -EFAULT;
			goto unlock;
		}

		TRACE_PS("read - return %d", ret);
		goto unlock;
	}
	ret = -EPERM;
unlock:
	tty_unlock();
	return ret;
}
Beispiel #12
0
void CAimer39RTSPClient::continueAfterPLAY(RTSPClient* rtspClient, int resultCode, char* resultString)
{
	Boolean success = False;

	do {
		UsageEnvironment& env = rtspClient->envir(); // alias
		StreamClientState& scs = ((ourRTSPClient*)rtspClient)->scs; // alias
		CAimer39RTSPClient * arc = findClient( (ourRTSPClient*)rtspClient );

		if ( NULL == arc ) {
			env << "some how the system in to a dangerous situation!" << "\n";
			break;
		}
		
		arc->m_errorCode = resultCode;
		if (resultCode != 0) {
			arc->m_lastErrorMsg = resultString;
			env << *rtspClient << "Failed to start playing session: " << resultString << "\n";
			break;
		}

		// Set a timer to be handled at the end of the stream's expected duration (if the stream does not already signal its end
		// using a RTCP "BYE").  This is optional.  If, instead, you want to keep the stream active - e.g., so you can later
		// 'seek' back within it and do another RTSP "PLAY" - then you can omit this code.
		// (Alternatively, if you don't want to receive the entire stream, you could set this timer for some shorter value.)
		/*if (scs.duration > 0) {
			unsigned const delaySlop = 2; // number of seconds extra to delay, after the stream's expected duration.  (This is optional.)
			scs.duration += delaySlop;
			unsigned uSecsToDelay = (unsigned)((scs.duration - scs.session->playStartTime())*1000000);
			if (scs.streamTimerTask)
				env.taskScheduler().unscheduleDelayedTask(scs.streamTimerTask);
			scs.streamTimerTask = env.taskScheduler().scheduleDelayedTask(uSecsToDelay, (TaskFunc*)streamTimerHandler, rtspClient);
		}*/

		env << *rtspClient << "Started playing session";
		if (scs.duration > 0) {
			env << " (for up to " << scs.duration << " seconds)";
		}
		env << "...\n";

		if (arc->m_pStartPlayCB)
			arc->m_pStartPlayCB(scs.duration, scs.session->playStartTime(), arc->m_pStartPlayCBP, arc);

		success = True;
	} while (0);
	delete[] resultString;

	if (!success) {
		// An unrecoverable error occurred with this stream.
		shutdownStream(rtspClient);
		return;
	}
}
Beispiel #13
0
void Router::doServiceRoute(ServiceConnection* conn, MSG_HEAD_BACK* head, char* body)
{
	MSG_HEAD_GATE pGate;
	pGate.id = head->id;
	pGate.length = head->length;
	pGate.err = head->err;
	Client* client = findClient(head->pid);
	if (client)
	{
		client->connection->send((char*)&pGate, sizeof(MSG_HEAD_GATE), body, head->length);
	}
}
Beispiel #14
0
// Client:port finder.
qjackctlPortItem *qjackctlClientList::findClientPort (
	const QString& sClientPort )
{
	qjackctlPortItem *pPort = 0;
	int iColon = sClientPort.indexOf(':');
	if (iColon >= 0) {
		qjackctlClientItem *pClient = findClient(sClientPort.left(iColon));
		if (pClient) {
			pPort = pClient->findPort(
				sClientPort.right(sClientPort.length() - iColon - 1));
		}
	}
	return pPort;
}
Beispiel #15
0
void JabberAdd::serviceChanged(const QString &host)
{
    JabberClient *client = findClient(host.latin1());
    for (AGENTS_MAP::iterator it = m_agents.begin(); it != m_agents.end(); ++it){
        agentInfo &info = (*it).second;
        if (info.search){
            tabAdd->removePage(info.search);
            delete info.search;
        }
    }
    m_agents.clear();
    if (client)
        client->get_agents();
}
Beispiel #16
0
void CAimer39RTSPClient::continueAfterSETUP(RTSPClient* rtspClient, int resultCode, char* resultString) 
{
	do {
		UsageEnvironment& env = rtspClient->envir(); // alias
		StreamClientState& scs = ((ourRTSPClient*)rtspClient)->scs; // alias
		CAimer39RTSPClient * arc = findClient( (ourRTSPClient*)rtspClient );

		if ( NULL == arc ) {
			env << "some how the system in to a dangerous situation!" << "\n";
			break;
		}
		
		arc->m_errorCode = resultCode;
		if (resultCode != 0) {
			arc->m_lastErrorMsg = resultString;
			env << *rtspClient << "Failed to set up the \"" << *scs.subsession << "\" subsession: " << resultString << "\n";
			break;
		}

		env << *rtspClient << "Set up the \"" << *scs.subsession
		<< "\" subsession (client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1 << ")\n";

		// Having successfully setup the subsession, create a data sink for it, and call "startPlaying()" on it.
		// (This will prepare the data sink to receive data; the actual flow of data from the client won't start happening until later,
		// after we've sent a RTSP "PLAY" command.)

		scs.subsession->sink = DummySink::createNew(env, *scs.subsession, arc, rtspClient->url());
		  // perhaps use your own custom "MediaSink" subclass instead
		if (scs.subsession->sink == NULL) {
			env << *rtspClient << "Failed to create a data sink for the \"" << *scs.subsession
			<< "\" subsession: " << env.getResultMsg() << "\n";
			break;
		}

		env << *rtspClient << "Created a data sink for the \"" << *scs.subsession << "\" subsession\n";
		scs.subsession->miscPtr = rtspClient; // a hack to let subsession handle functions get the "RTSPClient" from the subsession 
		scs.subsession->sink->startPlaying(*(scs.subsession->readSource()),
						   subsessionAfterPlaying, scs.subsession);
		// Also set a handler to be called if a RTCP "BYE" arrives for this subsession:
		if (scs.subsession->rtcpInstance() != NULL) {
			scs.subsession->rtcpInstance()->setByeHandler(subsessionByeHandler, scs.subsession);
		}
	} while (0);
	delete[] resultString;

	// Set up the next subsession, if any:
	setupNextSubsession(rtspClient);
}
Beispiel #17
0
// Implementation of the RTSP 'response handlers':
void CAimer39RTSPClient::continueAfterDESCRIBE(RTSPClient* rtspClient, int resultCode, char* resultString)
{
	do {
		UsageEnvironment& env = rtspClient->envir(); // alias
		StreamClientState& scs = ((ourRTSPClient*)rtspClient)->scs; // alias
		CAimer39RTSPClient * arc = findClient( (ourRTSPClient*)rtspClient );
		arc->m_bIsPrepare = false;

		if ( NULL == arc ) {
			arc->m_errorCode = -1;
			env << "some how the system in to a dangerous situation!" << "\n";
			break;
		}
		
		arc->m_errorCode = resultCode;
		if (resultCode != 0) {
			arc->m_lastErrorMsg = resultString;
			env << *rtspClient << "Failed to get a SDP description: " << resultString << "\n";
			delete[] resultString;
			break;
		}

		char* const sdpDescription = resultString;
		env << *rtspClient << "Got a SDP description:\n" << sdpDescription << "\n";

		// Create a media session object from this SDP description:
		scs.session = MediaSession::createNew(env, sdpDescription);
		delete[] sdpDescription; // because we don't need it anymore
		if (scs.session == NULL) {
			env << *rtspClient << "Failed to create a MediaSession object from the SDP description: " << env.getResultMsg() << "\n";
			arc->m_errorCode = -1;
			arc->m_lastErrorMsg = env.getResultMsg();
			break;
		} else if (!scs.session->hasSubsessions()) {
			env << *rtspClient << "This session has no media subsessions (i.e., no \"m=\" lines)\n";
			arc->m_errorCode = 2;
			arc->m_lastErrorMsg = "This session has no media subsessions (i.e., no \"m=\" lines)\n";
			break;
		}
		
		arc->m_bIsPrepare = true;
		return;
	} while (0);
	
	// An unrecoverable error occurred with this stream.
	shutdownStream(rtspClient);
}
Beispiel #18
0
void PythonScriptInterface::HandleClientCommand(void *user, const char *extra) {
	ClientInfoTable *tbl = findClient(user);
	if(tbl) {
		std::vector<ScriptCommand *>::iterator it = tbl->registered_commands.begin();
		ScriptCommand *cmd;
		while(it != tbl->registered_commands.end()) {
			cmd = *it;
			if(strncasecmp(cmd->name,&extra[1], strlen(cmd->name)) == 0) {
				PyObject *ret = PyObject_CallFunction(cmd->run_func, "s", extra);
				PyErr_Print();
				Py_XDECREF(ret);
				break;
			}
			it++;
		}
	}
}
Beispiel #19
0
void CAimer39RTSPClient::setupNextSubsession(RTSPClient* rtspClient) 
{
	UsageEnvironment& env = rtspClient->envir(); // alias
	StreamClientState& scs = ((ourRTSPClient*)rtspClient)->scs; // alias
	CAimer39RTSPClient * arc = findClient( (ourRTSPClient*)rtspClient );

	if ( NULL == arc ) {
		arc->m_errorCode = -1;
		env << "some how the system in to a dangerous situation!" << "\n";
		return;
	}

	scs.subsession = scs.iter->next();
	if (scs.subsession != NULL) {
		vector<MediaSubsession *>::iterator iter = arc->m_vecNoNeedStream.begin();
		for ( ; iter != arc->m_vecNoNeedStream.end(); ++iter ) {
			if ( *iter == scs.subsession ) {
				setupNextSubsession(rtspClient); // give up on this subsession; go to the next one
				return;
			}
		}

		if (!scs.subsession->initiate()) {
			env << *rtspClient << "Failed to initiate the \"" << *scs.subsession << "\" subsession: " << env.getResultMsg() << "\n";
			arc->m_errorCode = 3;
			arc->m_lastErrorMsg = env.getResultMsg();
			setupNextSubsession(rtspClient); // give up on this subsession; go to the next one
		} else {
			env << *rtspClient << "Initiated the \"" << *scs.subsession
			<< "\" subsession (client ports " << scs.subsession->clientPortNum() << "-" << scs.subsession->clientPortNum()+1 << ")\n";

			// Continue setting up this subsession, by sending a RTSP "SETUP" command:
			rtspClient->sendSetupCommand(*scs.subsession, continueAfterSETUP);
		}
		return;
	}

	// We've finished setting up all of the subsessions.  Now, send a RTSP "PLAY" command to start the streaming:
	if (scs.session->absStartTime() != NULL) {
		// Special case: The stream is indexed by 'absolute' time, so send an appropriate "PLAY" command:
		rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY, scs.session->absStartTime(), scs.session->absEndTime());
	} else {
		scs.duration = scs.session->playEndTime() - scs.session->playStartTime();
		rtspClient->sendPlayCommand(*scs.session, continueAfterPLAY);
	}
}
Beispiel #20
0
void Router::doClientRoute(ClientConnection* conn, char* head, char* body)
{
	//pBuffer->append(head, hsize);
	//pBuffer->append(body, bsize);
	//
	Client *client = findClient(conn);
	MSG_HEAD_GATE* pHead = (MSG_HEAD_GATE*)head;
	MSG_HEAD_BACK pBack;
	pBack.id = pHead->id;
	pBack.length = pHead->length;
	pBack.rid = client->rid;
	pBack.tid = client->tid;
	pBack.pid = client->pid;
	//pBack.cid = client->
	pMaster->send((char*)&pBack, sizeof(MSG_HEAD_BACK), body, pHead->length);
	//pMaster->send(pBuffer->data(), pBuffer->bytesAvaliable());
	//pMaster->send();
}
Beispiel #21
0
void CAimer39RTSPClient::shutdownStream( RTSPClient* rtspClient ) 
{
	UsageEnvironment& env = rtspClient->envir(); // alias
	StreamClientState& scs = ((ourRTSPClient*)rtspClient)->scs; // alias

	CAimer39RTSPClient * arc = findClient( (ourRTSPClient*)rtspClient );

	if ( NULL == arc ) {
		env << "some how the system in to a dangerous situation!" << "\n";
		return;
	}

	// First, check whether any subsessions have still to be closed:
	if (scs.session != NULL) { 
		Boolean someSubsessionsWereActive = False;
		MediaSubsessionIterator iter(*scs.session);
		MediaSubsession* subsession;

		while ((subsession = iter.next()) != NULL) {
			if (subsession->sink != NULL) {
				Medium::close(subsession->sink);
				subsession->sink = NULL;

				if (subsession->rtcpInstance() != NULL) {
					subsession->rtcpInstance()->setByeHandler(NULL, NULL); // in case the server sends a RTCP "BYE" while handling "TEARDOWN"
				}

				someSubsessionsWereActive = True;
			}
		}

		if (someSubsessionsWereActive) {
			// Send a RTSP "TEARDOWN" command, to tell the server to shutdown the stream.
			// Don't bother handling the response to the "TEARDOWN".
			rtspClient->sendTeardownCommand(*scs.session, NULL);
		}
	}

	env << *rtspClient << "Closing the stream.\n";
	arc->m_bIsShutDown = true;
	if (arc->m_pFinishCallback)	arc->m_pFinishCallback(arc->m_pCallBackParam, arc); //call back inform stream over
	Medium::close(rtspClient);
	// Note that this will also cause this stream's "StreamClientState" structure to get reclaimed.
}
Beispiel #22
0
/*	추가: 김영중
		로드된 모든 aml, eml 파일들의 (id, name) 정보를 보낸다.
*/
void SimulatorData::onAccept(int id)
{
	kaiSocket* sock = findClient(id);
	kaiMsg msg;
	msg.setBuffer(msgbuffer, 4096);
	msg.begin();

	SystemList& systems = _simulator->getSystems();
	short cnt = systems.size();
	msg << cnt;
	for (SystemList::iterator iter = systems.begin(); iter != systems.end(); ++iter)
	{
		rxSystem* sys = (*iter);
		string name;
		GetStringFromStringType(name, sys->name());
		msg << sys->id() << name;
	}

	/* 장이 버젼 - 데모를 위해 주석처리

	//	send environment infoes
	EnvironmentList& envs= _simulator->getEnvironments();
	cnt = envs.size();
	msg << cnt;
	for (EnvironmentList::iterator iter = envs.begin(); iter != envs.end(); ++iter)
	{
		rxEnvironment * env = (*iter);
		string name;
		GetStringFromStringType(name, env->name());
		msg << env->id() << name;
	}
	*/
	
	msg.id(KP_NOTI_ROBOT_INFOES);
	msg.end();

	sock->send(msg);


	TCHAR* message = TEXT("Simulation controller is coneected\n");
	SendMessage(theApp.m_pMainWnd->m_hWnd, SEND_LOG_MESSGE, (WPARAM)message, NULL);
}
Beispiel #23
0
void StrikeBalanceWidget::createActions()
{
    // Add tool tar actions for order list.
    m_addAct          = new QAction(QIcon(":/add"), tr("Add"), this);
    m_deleteAct       = new QAction(QIcon(":/delete"), tr("Delete"), this);
    m_saveAct         = new QAction(QIcon(":/ok"), tr("Save"), this);
    m_cancelAct       = new QAction(QIcon(":/cancel"), tr("Cancel"), this);
    m_findAct         = new QAction(QIcon(":/find"), tr("Find"), this);
    m_findClientAct   = new QAction(QIcon(":/find"), tr("Find Client"), this);
    
    m_deleteAct->setDisabled(true);
    m_saveAct->setDisabled(true);
    m_cancelAct->setDisabled(true);

    connect(m_addAct, SIGNAL(triggered()), this, SLOT(addOrder()));
    connect(m_deleteAct, SIGNAL(triggered()), this, SLOT(deleteOrder()));
    connect(m_saveAct, SIGNAL(triggered()), this, SLOT(saveOrder()));
    connect(m_cancelAct, SIGNAL(triggered()), this, SLOT(cancelModifiedOrder()));
    connect(m_findAct, SIGNAL(triggered()), this, SLOT(findOrder()));
    connect(m_findClientAct, SIGNAL(triggered()), this, SLOT(findClient()));
}
int removeClient(int down[], struct client clnt[], int* clnt_num, int socket){
    int i, clnt_idx;


    pthread_mutex_lock(&clnt_lock);
    clnt_idx = findClient(clnt, *clnt_num, socket);

    for(i=0; i<*clnt_num; i++){
        if(i <= clnt_idx)
            down[i] = 1;
    }

    for(i=clnt_idx; i<*clnt_num-1; i++){
        clnt[i] = clnt[i+1];
    }
    *clnt_num -= 1;

    pthread_mutex_unlock(&clnt_lock);

    return *clnt_num;
}
Beispiel #25
0
void JabberAdd::startSearch()
{
    if (m_result == NULL)
        return;
    JabberClient *client = findClient(cmbServices->currentText().latin1());
    if (client == NULL)
        return;
    if (tabAdd->currentPageIndex() == 0){
        QString jid = edtID->text();
        if (client->add_contact(jid.utf8())){
            unsigned grp_id = 0;
            ContactList::GroupIterator it;
            Group *grp;
            unsigned nGrp = cmbGroup->currentItem();
            while ((grp = ++it) != NULL){
                if (grp->id() == 0)
                    continue;
                if (nGrp-- == 0){
                    grp_id = grp->id();
                    break;
                }
            }
            Contact *contact;
            JabberUserData *data = client->findContact(jid.utf8(), NULL, false, contact);
            if (data && (contact->getGroup() != grp_id)){
                contact->setGroup(grp_id);
                Event e(EventContactChanged, contact);
                e.process();
            }
        }else{
            m_result->setText(i18n("%1 already in contact list") .arg(jid));
        }
    }else if (tabAdd->currentPage()->inherits("JabberSearch")){
        JabberSearch *search = static_cast<JabberSearch*>(tabAdd->currentPage());
        QString condition = search->condition();
        string search_id = client->search(search->id(), NULL, condition.utf8());
        m_result->setSearch(client, search_id.c_str());
    }
}
Beispiel #26
0
void Router::onChanelMessage(ServiceConnection* conn, MSG_HEAD_BACK* head, char* body)
{
	switch (head->id)
	{
	case MSG_CREATE_CHANEL_100:
	{
		MSG_CREATE_CHANEL msg;
		msg.readBody(body, head->length);
		createChanel(msg.cid);
	}
	case MSG_CHANEL_STATUS_102:
	{
		MSG_CHANEL_STATUS msg;
		Chanel* chanel = findChanel(head->cid);
		Client* client = findClient(msg.value);
		if (msg.status_type == CHANEL_STATUS_ADD_PLAYER)
		{
			if (chanel && client)
			{
				chanel->addClient(client);
				client->rid = head->cid;
				client->tid = head->tid;
			}
		}
		else if (msg.status_type == CHANEL_STATUS_RMV_PLAYER)
		{
			if (chanel && client)
			{
				chanel->removeClient(client);
				client->rid = head->cid;
				client->tid = head->tid;
			}
		}
		break;
	}
	default:
		break;
	}
}
bool WaitingList::clientLogin(const Player* player)
{
	if (player->hasFlag(PlayerFlag_CanAlwaysLogin) || player->getAccountType() >= ACCOUNT_TYPE_GAMEMASTER) {
		return true;
	}

	uint32_t maxPlayers = static_cast<uint32_t>(g_config.getNumber(ConfigManager::MAX_PLAYERS));
	if (maxPlayers == 0 || (priorityWaitList.empty() && waitList.empty() && g_game.getPlayersOnline() < maxPlayers)) {
		return true;
	}

	WaitingList::cleanupList(priorityWaitList);
	WaitingList::cleanupList(waitList);

	uint32_t slot;

	WaitListIterator it = findClient(player, slot);
	if (it != waitList.end()) {
		if ((g_game.getPlayersOnline() + slot) <= maxPlayers) {
			//should be able to login now
			waitList.erase(it);
			return true;
		}

		//let them wait a bit longer
		it->timeout = OTSYS_TIME() + (getTimeout(slot) * 1000);
		return false;
	}

	slot = priorityWaitList.size();
	if (player->isPremium()) {
		priorityWaitList.emplace_back(OTSYS_TIME() + (getTimeout(slot + 1) * 1000), player->getGUID());
	} else {
		slot += waitList.size();
		waitList.emplace_back(OTSYS_TIME() + (getTimeout(slot + 1) * 1000), player->getGUID());
	}
	return false;
}
Beispiel #28
0
void JabberAdd::startSearch()
{
    if (m_result == NULL)
        return;
    JabberClient *client = findClient(cmbServices->currentText().latin1());
    if (client == NULL)
        return;
    if (tabAdd->currentPageIndex() == 0){
        QString jid = edtID->text();
        unsigned grp_id = 0;
        ContactList::GroupIterator it;
        Group *grp;
        unsigned nGrp = cmbGroup->currentItem();
        while ((grp = ++it) != NULL){
            if (grp->id() == 0)
                continue;
            if (nGrp-- == 0){
                grp_id = grp->id();
                break;
            }
        }
        if (client->add_contact(jid.utf8(), grp_id)){
            m_result->setText(i18n("%1 added to contact list") .arg(jid));
        }else{
            m_result->setText(i18n("%1 is already in contact list") .arg(jid));
        }
        if (m_wizard)
            m_wizard->setFinishEnabled(m_result, true);
    }else if (tabAdd->currentPage()->inherits("JabberSearch")){
        JabberSearch *search = static_cast<JabberSearch*>(tabAdd->currentPage());
        bool bXSearch;
        QString condition = search->condition(bXSearch);
        string search_id = client->search(search->id(), NULL, condition.utf8());
        m_result->setSearch(client, search_id.c_str(), bXSearch);
    }
}
Beispiel #29
0
bool dropClient(int clientNumber){
	struct client* clientPointer = findClient(clientNumber);
	struct client* target;
	//check to see if client exists
	if (clientPointer == NULL)
		return false;
	//the client is at the head of the list
	else if(clientPointer == clientHead){
		target = clientHead;
		clientHead = clientHead -> next;
		free(target);
	}
	else{
		target = (clientPointer);
		clientPointer = clientHead;
		while(clientPointer != NULL && clientPointer->next != target){
			clientPointer = clientPointer->next;
		}
		clientPointer = target->next;
		free(target);
	}
	
	return true;
}
Beispiel #30
0
/* Called without the kernel lock held - fine */
static unsigned int r3964_poll(struct tty_struct *tty, struct file *file,
			struct poll_table_struct *wait)
{
	struct r3964_info *pInfo = tty->disc_data;
	struct r3964_client_info *pClient;
	struct r3964_message *pMsg = NULL;
	unsigned long flags;
	int result = POLLOUT;

	TRACE_L("POLL");

	pClient = findClient(pInfo, task_pid(current));
	if (pClient) {
		poll_wait(file, &pInfo->read_wait, wait);
		spin_lock_irqsave(&pInfo->lock, flags);
		pMsg = pClient->first_msg;
		spin_unlock_irqrestore(&pInfo->lock, flags);
		if (pMsg)
			result |= POLLIN | POLLRDNORM;
	} else {
		result = -EINVAL;
	}
	return result;
}