示例#1
0
void XimCandidateWindow::slotStdinActivated(int fd)
{
    QList<QStringList> messageList = parse_messages(get_messages(fd));
    for (int i = 0, j = messageList.count(); i < j; i++) {
        QStringList message = messageList[i];
        QString command = message[0];
        if (command == "activate")
            activateCand(message);
        else if (command == "select")
            selectCand(message);
        else if (command == "show")
            showCand();
        else if (command == "hide")
            hide();
        else if (command == "move")
            moveCand(message);
        else if (command == "deactivate")
            deactivateCand();
        else if (command == "set_nr_candidates")
            setNrCandidates(message);
        else if (command == "set_page_candidates")
            setPageCandidates(message);
        else if (command == "show_page")
            showPage(message);
    }
}
示例#2
0
void user_login(struct plugin_handle* plugin, struct plugin_user* user)
{
	struct chat_history_data* data = (struct chat_history_data*) plugin->ptr;
	struct cbuffer* buf = NULL;
	// size_t messages = 0;

	if (data->history_connect > 0 && list_size(data->chat_history) > 0)
	{
		buf = cbuf_create(MAX_HISTORY_SIZE);
		cbuf_append(buf, "Chat history:\n");
		get_messages(data, data->history_connect, buf);
		plugin->hub.send_message(plugin, user, cbuf_get(buf));
		cbuf_destroy(buf);
	}
}
示例#3
0
/**
 * The callback function for handling the !history command.
 */
static int command_history(struct plugin_handle* plugin, struct plugin_user* user, struct plugin_command* cmd)
{
	struct cbuffer* buf;
	struct chat_history_data* data = (struct chat_history_data*) plugin->ptr;
	struct plugin_command_arg_data* arg = plugin->hub.command_arg_next(plugin, cmd, plugin_cmd_arg_type_integer);
	int maxlines;

	if (!list_size(data->chat_history))
		return command_status(plugin, user, cmd, cbuf_create_const("No messages."));

	if (arg)
		maxlines = arg->data.integer;
	else
		maxlines = data->history_default;
	
	buf = cbuf_create(MAX_HISTORY_SIZE);
	cbuf_append_format(buf, "*** %s: Chat History:\n", cmd->prefix);
	get_messages(data, maxlines, buf);

	plugin->hub.send_message(plugin, user, cbuf_get(buf));
	cbuf_destroy(buf);
	return 0;
}
示例#4
0
int main(int argc, char **argv)
{
  QCoreApplication qca(argc, argv);
  QStringList args = QCoreApplication::arguments();

  Settings settings = Settings::CommandLineParse(args);
  if(settings.Help || !settings.IsValid()) {
    QTextStream qtout(stdout, QIODevice::WriteOnly);
    qtout << "usage: " << args[0] << " [options] [settings.conf]\n\n";
    qtout << "options:\n";
    qtout << Settings::GetUsage() << "\n";
    if(!settings.Help) {
      qtout << "error: " << settings.GetError() << "\n\n";
    }
    return -1;
  }
  Settings::ApplicationSettings = settings;

  QList<QSharedPointer<Node> > nodes;

  QSharedPointer<ISink> default_sink(new DummySink());
  QSharedPointer<SinkMultiplexer> app_sink(new SinkMultiplexer());

  QSharedPointer<CommandLine> commandline;
  QSharedPointer<SignalSink> signal_sink(new SignalSink());
  app_sink->AddSink(signal_sink.data());

  QSharedPointer<KeyShare> keys(new KeyShare(settings.PublicKeys));
  Hash hashalgo;
  foreach(const Id &server, settings.ServerIds) {
    QString serv = server.ToString();
    if(!keys->Contains(serv)) {
      qFatal("Missing key for %s", serv.toLatin1().data());
    }
    Q_ASSERT(Id(hashalgo.ComputeHash(keys->GetKey(serv)->GetByteArray())) == server);
  }

  QList<Address> local_end_points = settings.LocalEndPoints;

  for(int idx = 0; idx < settings.LocalNodeCount; idx++) {
    Id local_id = idx < settings.LocalId.count() ? settings.LocalId[idx] : Id();
    QSharedPointer<AsymmetricKey> key;

    QString key_path = settings.PrivateKeys + "/" + local_id.ToString();
    QFile key_file(key_path);
    if(key_file.exists()) {
      key = QSharedPointer<AsymmetricKey>(new DsaPrivateKey(key_path));
    } else {
      QByteArray id = local_id.GetByteArray();
      key = QSharedPointer<AsymmetricKey>(new DsaPrivateKey(id, true));
    }

    QSharedPointer<ISink> nsink = (idx == 0) ? app_sink.dynamicCast<ISink>() : default_sink;
    QSharedPointer<Overlay> overlay(new Overlay(local_id, local_end_points,
          settings.RemoteEndPoints, settings.ServerIds));
    overlay->SetSharedPointer(overlay);

    CreateRound create_round = RoundFactory::GetCreateRound(settings.RoundType);
    QSharedPointer<Session> session;
    if(settings.ServerIds.contains(local_id)) {
      session = MakeSession<ServerSession>(overlay, key, keys, create_round);
    } else {
      session = MakeSession<ClientSession>(overlay, key, keys, create_round);
    }
    session->SetSink(nsink.data());
    QSharedPointer<Node> node(new Node(key, keys, overlay, nsink, session));
    nodes.append(node);

    for(int idx = 0; idx < local_end_points.count(); idx++) {
      local_end_points[idx] = AddressFactory::GetInstance().
        CreateAny(local_end_points[idx].GetType());
    }
  }

  QScopedPointer<WebServer> ws;
//  QScopedPointer<SessionEntryTunnel> tun_entry;
//  QScopedPointer<SessionExitTunnel> tun_exit;

  if(settings.Console) {
    commandline = QSharedPointer<CommandLine>(new CommandLine(nodes));
    QObject::connect(&qca, SIGNAL(aboutToQuit()), commandline.data(), SLOT(Stop()));
    commandline->Start();
    app_sink->AddSink(commandline.data());
  }

  if(settings.WebServer) {
    ws.reset(new WebServer(settings.WebServerUrl));

    /* Stop Web server when application is about to quit */
    QObject::connect(&qca, SIGNAL(aboutToQuit()), ws.data(), SLOT(Stop()));

    /* When the web server stops, quit the application */
    QObject::connect(ws.data(), SIGNAL(Stopped()), &qca, SLOT(quit()));

    QSharedPointer<GetMessagesService> get_messages(new GetMessagesService());
    QObject::connect(signal_sink.data(), SIGNAL(IncomingData(const QByteArray&)),
        get_messages.data(), SLOT(HandleIncomingMessage(const QByteArray&)));
    ws->AddRoute(QHttpRequest::HTTP_GET, "/session/messages", get_messages);

    QSharedPointer<GetFileService> get_webpage(new GetFileService("index.html"));
    ws->AddRoute(QHttpRequest::HTTP_GET, "/web", get_webpage);

    QSharedPointer<GetDirectoryService> get_dir(new GetDirectoryService("webpath"));
    ws->AddRoute(QHttpRequest::HTTP_GET, "/dir", get_dir);

    QSharedPointer<SessionService> session_serv(new SessionService(nodes[0]->GetSession()));
    ws->AddRoute(QHttpRequest::HTTP_GET, "/session", session_serv);

    QSharedPointer<SendMessageService> send_message(new SendMessageService(nodes[0]->GetSession()));
    ws->AddRoute(QHttpRequest::HTTP_POST, "/session/send", send_message);

//    QSharedPointer<BuddiesService> bs(new BuddiesService(nodes[0]->GetSessionManager()));
//    ws->AddRoute(QHttpRequest::HTTP_GET, "/session/buddies", bs);

    ws->Start();
  }
示例#5
0
void dwg_process_message(str_t *ip_from, str_t *input, dwg_outqueue_t *outqueue)
{
	dwg_outqueue_t *output	= NULL;
    dwg_hbp_t	*hbp		= malloc(sizeof(dwg_hbp_t));
    dwg_hbp_t	*item, *aux = NULL;

    LOG(L_DEBUG, "%s: received %d bytes\n", __FUNCTION__, input->len);

    if (!get_messages(input, hbp))
    {
    	LOG(L_ERROR, "%s: error processing message\n", __FUNCTION__);
    	return;
    }

    clist_foreach_safe(hbp, item, aux, next)
    {
    	output	= NULL;

		switch(item->hdr.type)
		{
			case DWG_TYPE_KEEP_ALIVE:
				LOG(L_DEBUG, "%s: received DWG_TYPE_KEEP_ALIVE\n", __FUNCTION__);
				break;
			case DWG_TYPE_STATUS:
				LOG(L_DEBUG, "%s: received DWG_TYPE_STATUS\n", __FUNCTION__);

				int index;
				dwg_ports_status_t *ports_status	= malloc(sizeof(dwg_ports_status_t));

				ports_status->size			= (int) item->body.s[0];
				ports_status->status_array	= malloc(sizeof(dwg_port_status_t) * ports_status->size);

				for (index = 0; index < ports_status->size; index++)
				{
					ports_status->status_array[index].port	= index;
					ports_status->status_array[index].status = (int) item->body.s[index + 1];
				}

				DWG_CALL_IF_NOT_NULL(_callbacks->status_callback, ip_from, ports_status);

				output	= malloc(sizeof(dwg_outqueue_t));
				if (!dwg_build_status_response(&item->hdr, &output->content))
				{
					LOG(L_ERROR, "%s: error building reponse", __FUNCTION__);

					free(output);
					output	= NULL;
				}

				break;
			case DWG_TYPE_SEND_SMS:
				LOG(L_DEBUG, "%s: received DWG_TYPE_SEND_SMS\n", __FUNCTION__);
				break;
			case DWG_TYPE_SEND_USSD:
				LOG(L_DEBUG, "%s: received DWG_TYPE_SEND_USSD\n", __FUNCTION__);
				break;
			case DWG_TYPE_SEND_SMS_RESP:
				LOG(L_DEBUG, "%s: received DWG_TYPE_SEND_SMS_RESP\n", __FUNCTION__);

				if ((int) item->body.s[0] == 0)
				{
					LOG(L_DEBUG, "%s: SMS was received by the GW\n", __FUNCTION__);
				}
				else
				{
					LOG(L_ERROR, "%s: Error sending SMS\n", __FUNCTION__);
				}

				output	= malloc(sizeof(dwg_outqueue_t));
				if (!dwg_build_sms_ack(&item->hdr, &output->content))
				{
					LOG(L_ERROR, "%s: error building response", __FUNCTION__);

					free(output);
					output	= NULL;
				}
				break;
			case DWG_TYPE_SEND_USSD_RESP:
				LOG(L_DEBUG, "%s: received DWG_TYPE_SEND_USSD_RESP\n", __FUNCTION__);

				if ((int) item->body.s[0] == 0)
				{
					LOG(L_DEBUG, "%s: USSD was received by the GW\n", __FUNCTION__);
				}
				else
				{
					LOG(L_ERROR, "%s: Error sending USSD\n", __FUNCTION__);
				}

				break;
			case DWG_TYPE_SEND_SMS_RESULT:
				LOG(L_DEBUG, "%s: received DWG_TYPE_SEND_SMS_RESULT\n", __FUNCTION__);

				dwg_sms_response_t	*response	= malloc(sizeof(dwg_sms_response_t));
				dwg_deserialize_sms_response(&item->body, response);

				DWG_CALL_IF_NOT_NULL(_callbacks->msg_response_callback, ip_from, response);

				output	= malloc(sizeof(dwg_outqueue_t));
				if (!dwg_build_sms_res_ack(&item->hdr, &output->content))
				{
					LOG(L_ERROR, "%s: error building response", __FUNCTION__);

					free(output);
					output	= NULL;
				}

				break;
			case DWG_TYPE_RECV_SMS:
				LOG(L_DEBUG, "%s: received DWG_TYPE_RECV_SMS\n", __FUNCTION__);

				dwg_sms_received_t *received	= malloc(sizeof(dwg_sms_received_t));

				if (!dwg_deserialize_sms_received(&item->body, received))
				{
					LOG(L_ERROR, "%s: error deserializing received message\n", __FUNCTION__);
					hexdump(item->body.s, item->body.len);
					break;
				}

				DWG_CALL_IF_NOT_NULL(_callbacks->msg_sms_recv_callback, ip_from, received);

				output	= malloc(sizeof(dwg_outqueue_t));
				if (!dwg_build_sms_recv_ack(&item->hdr, &output->content))
				{
					LOG(L_ERROR, "%s: error building response", __FUNCTION__);

					free(output);
					output	= NULL;
				}
				break;
			case DWG_TYPE_RECV_USSD:
				LOG(L_DEBUG, "%s: received DWG_TYPE_RECV_USSD\n", __FUNCTION__);

				dwg_ussd_received_t *ussd_rcv	= malloc(sizeof(dwg_ussd_received_t));

				if (!dwg_deserialize_ussd_received(&item->body, ussd_rcv))
				{
					LOG(L_ERROR, "%s: error deserializing received USSD message\n", __FUNCTION__);
					hexdump(item->body.s, item->body.len);
					break;
				}

				DWG_CALL_IF_NOT_NULL(_callbacks->msg_ussd_recv_callback, ip_from, ussd_rcv);

				output	= malloc(sizeof(dwg_outqueue_t));
				if (!dwg_build_ussd_recv_ack(&item->hdr, &output->content))
				{
					LOG(L_ERROR, "%s: error building response", __FUNCTION__);

					free(output);
					output	= NULL;
				}
				break;

			case DWG_TYPE_RECV_AUTH:
				LOG(L_DEBUG, "%s: received DWG_TYPE_RECV_AUTH\n", __FUNCTION__);

				output	= malloc(sizeof(dwg_outqueue_t));
				if (!dwg_build_auth_response(&item->hdr, &output->content))
				{
					LOG(L_ERROR, "%s: error building response", __FUNCTION__);
					free(output);
					output	= NULL;
				}
				_is_api_2_0	= TRUE;

				break;
			case DWG_TYPE_RECV_RSSI:
				LOG(L_DEBUG, "%s: received DWG_TYPE_RECV_RSSI\n", __FUNCTION__);

				output	= malloc(sizeof(dwg_outqueue_t));
				if (!dwg_build_rssi_response(&item->hdr, &output->content))
				{
					LOG(L_ERROR, "%s: error building response", __FUNCTION__);

					free(output);
					output	= NULL;
				}

				break;

			default:
				LOG(L_DEBUG, "%s: Received unknown code %d\n", __FUNCTION__, item->hdr.type);

				hexdump(item->body.s, item->body.len);
				break;
		}

//		printf("A\n");
		if (output != NULL)
		{
			clist_append(outqueue, output, next, prev);
		}

		clist_rm(item, next, prev);
//		printf("B\n");

//		printf("C %p %d\n", item->body.s, item->body.len);

		if (item->body.s != NULL)
			free(item->body.s);

		//printf("D\n");
		free(item);

//		printf("end of iteration\n");
    }