Example #1
0
/**
 *  * Performs the actual refresh operations.
 *  */
static void
banlist_do_refresh (struct session *sess)
{
	char tbuf[256];
	if (sess->server->connected)
	{
		GtkListStore *store;

		gtk_widget_set_sensitive (sess->res->banlist_butRefresh, FALSE);

		snprintf (tbuf, sizeof tbuf, "XChat: Ban List (%s, %s)",
						sess->channel, sess->server->servername);
		mg_set_title (sess->res->banlist_window, tbuf);

		store = get_store (sess);
		gtk_list_store_clear (store);

		handle_command (sess, "ban", FALSE);
#ifdef WIN32
		if (0)
#else
		if (supports_exempt (sess->server))
#endif
		{
			snprintf (tbuf, sizeof (tbuf), "quote mode %s +e", sess->channel);
			handle_command (sess, tbuf, FALSE);
		}

	} else
	{
		fe_message (_("Not connected."), FE_MSG_ERROR);
	}
}
Example #2
0
static void
irc_init (session *sess)
{
	static int done_init = FALSE;
	char *buf;

	if (done_init)
		return;

	done_init = TRUE;

	plugin_add (sess, NULL, NULL, timer_plugin_init, NULL, NULL, FALSE);
	plugin_add (sess, NULL, NULL, identd_plugin_init, identd_plugin_deinit, NULL, FALSE);

#ifdef USE_PLUGIN
	if (!arg_skip_plugins)
		plugin_auto_load (sess);	/* autoload ~/.xchat *.so */
#endif

#ifdef USE_DBUS
	plugin_add (sess, NULL, NULL, dbus_plugin_init, NULL, NULL, FALSE);
#endif

	if (prefs.hex_notify_timeout)
		notify_tag = fe_timeout_add (prefs.hex_notify_timeout * 1000,
											  notify_checklist, 0);

	fe_timeout_add (prefs.hex_away_timeout * 1000, away_check, 0);
	fe_timeout_add (500, hexchat_misc_checks, 0);

	if (arg_url != NULL)
	{
		buf = g_strdup_printf ("server %s", arg_url);
		g_free (arg_url);	/* from GOption */
		handle_command (sess, buf, FALSE);
		g_free (buf);
	}
	
	if (arg_urls != NULL)
	{
		guint i;
		for (i = 0; i < g_strv_length (arg_urls); i++)
		{
			buf = g_strdup_printf ("%s %s", i==0? "server" : "newserver", arg_urls[i]);
			handle_command (sess, buf, FALSE);
			g_free (buf);
		}
		g_strfreev (arg_urls);
	}

	if (arg_command != NULL)
	{
		handle_command (sess, arg_command, FALSE);
		g_free (arg_command);
	}

	/* load -e <xdir>/startup.txt */
	load_perform_file (sess, "startup.txt");
}
Example #3
0
File: test.c Project: skn/tasknc
void test_set_var() /* {{{ */
{
	/* test the ability to set a variable */
	char *teststr = strdup("  set \t task_version   0.6.9  ");
	char *testint = strdup("  set \t nc_timeout \t 6969\t\t \n ");

	stdout = devnull;
	handle_command(teststr);
	handle_command(testint);
	stdout = out;
	test_result("set string var", strcmp(cfg.version, "0.6.9")==0);
	test_result("set int var", cfg.nc_timeout==6969);
} /* }}} */
Example #4
0
void handle_binding(enum term_key_type type, unsigned int key)
{
	int i;

	pressed_keys.types[pressed_keys.count] = type;
	pressed_keys.keys[pressed_keys.count] = key;
	pressed_keys.count++;

	for (i = bindings.count; i > 0; i--) {
		struct binding *b = bindings.ptrs[i - 1];
		struct key_chain *c = &b->chain;

		if (c->count < pressed_keys.count)
			continue;

		if (memcmp(c->keys, pressed_keys.keys, pressed_keys.count * sizeof(pressed_keys.keys[0])))
			continue;
		if (memcmp(c->types, pressed_keys.types, pressed_keys.count * sizeof(pressed_keys.types[0])))
			continue;

		if (c->count > pressed_keys.count)
			return;

		handle_command(commands, b->command);
		break;
	}
	clear(&pressed_keys);
}
Example #5
0
/* toggle state changed via mouse click */
static void
menu_toggle_cb (GtkCheckMenuItem *item, menu_entry *me)
{
	me->state = 0;
	if (item->active)
		me->state = 1;

	/* update the state, incase this was changed via right-click. */
	/* This will update all other windows and menu bars */
	menu_foreach_gui (me, menu_update_cb);

	if (me->state)
		handle_command (current_sess, me->cmd, FALSE);
	else
		handle_command (current_sess, me->ucmd, FALSE);
}
Example #6
0
File: tasknc.c Project: skn/tasknc
void key_command(const char *arg) /* {{{ */
{
	/* accept and attemt to execute a command string */
	char *cmdstr;

	if (arg==NULL)
	{
		/* prepare prompt */
		statusbar_message(-1, ":");
		set_curses_mode(NCURSES_MODE_STRING);

		/* get input */
		statusbar_getstr(&cmdstr, ":");
		wipe_statusbar();

		/* reset */
		set_curses_mode(NCURSES_MODE_STD);
	}
	else
		cmdstr = strdup(arg);

	/* run input command */
	if (cmdstr[0]!=0)
		handle_command(cmdstr);
	free(cmdstr);
} /* }}} */
Example #7
0
void ForkWrapper::run()
{
	int result = 0;
	const int debug = 0;

	while(!done)
	{
		if(debug) printf("ForkWrapper::run %d this=%p parent_fd=%d child_fd=%d\n", 
			__LINE__, this, parent_fd, child_fd);

		result = read_command();



		if(debug) printf("ForkWrapper::run %d this=%p result=%d command_token=%d\n", 
			__LINE__, this, result, command_token);

		if(!result && command_token == EXIT_CODE) 
			done = 1;
		else
		if(!result)
		{
			handle_command();
		}
	}
}
Example #8
0
static int
process_commands_stream(struct cfg *cf, struct rtpp_cmd_connection *rcc,
  double dtime, struct rtpp_command_stats *csp, struct rtpp_stats_obj *rsc)
{
    int rval;
    struct rtpp_command *cmd;

    rval = rtpp_command_stream_doio(cf, rcc);
    if (rval <= 0) {
        return (-1);
    }
    do {
        cmd = rtpp_command_stream_get(cf, rcc, &rval, dtime, csp);
        if (cmd == NULL) {
            if (rval != 0) {
                break;
            }
            continue;
        }
        cmd->laddr = sstosa(&rcc->csock->bindaddr);
        if (cmd->cca.op == GET_STATS) {
            flush_cstats(rsc, csp);
        }
        if (cmd->no_glock == 0) {
            pthread_mutex_lock(&cf->glock);
        }
        rval = handle_command(cf, cmd);
        if (cmd->no_glock == 0) {
            pthread_mutex_unlock(&cf->glock);
        }
        free_command(cmd);
    } while (rval == 0);
    return (rval);
}
Example #9
0
static void
plugingui_unload (GtkWidget * wid, gpointer unused)
{
	char *modname, *file, *buf;
	GtkTreeView *view;
	GtkTreeIter iter;
	
	view = g_object_get_data (G_OBJECT (plugin_window), "view");
	if (!gtkutil_treeview_get_selected (view, &iter, NAME_COLUMN, &modname,
	                                    FILE_COLUMN, &file, -1))
		return;

	if (g_str_has_suffix (file, "."G_MODULE_SUFFIX))
	{
		if (plugin_kill (modname, FALSE) == 2)
			fe_message (_("That plugin is refusing to unload.\n"), FE_MSG_ERROR);
	} else
	{
		/* let python.so or perl.so handle it */
		buf = malloc (strlen (file) + 10);
		if (strchr (file, ' '))
			sprintf (buf, "UNLOAD \"%s\"", file);
		else
			sprintf (buf, "UNLOAD %s", file);
		handle_command (current_sess, buf, FALSE);
		free (buf);
	}

	g_free (modname);
	g_free (file);
}
Example #10
0
int
handle_client(int socket) {

    // Get the client registered to the socket
    Client *client = search_client(socket);
    if (client == NULL) {
        perror("Unregistered client socket found! This is not in the list!");
        return EXIT_FAILURE;
    }
    // Read the complete input of the client
    int res = read_from_client(client);
    if (res != EXIT_SUCCESS)
        return res;
        
    // Try to extract a single message from the buffer
    StringBuffer *msg = extract_message(client);
    if (msg == NULL) {
        return EXIT_SUCCESS;
    }
    if (is_command(client, msg) == EXIT_SUCCESS) {
        handle_command(client, msg);
    }
    else {
        broadcast_message(client, msg);
    }
    
    StringBuffer_free(msg);
    return EXIT_SUCCESS;
}
Example #11
0
static void handle_read(struct bufferevent *bev, void *ctx)
{
    // Get the buffer
    struct evbuffer *buf = bufferevent_get_input(bev);

    // Get the client
    client_t *c = ctx;

    // Get the message
    char *request_line;
    size_t len;

    // Read all lines if more than 1 have arrived
    for (;;) {
        request_line = evbuffer_readln(buf, &len, EVBUFFER_EOL_CRLF_STRICT);

        // If we got a messsage, handle it
        if (request_line) {
            handle_command(request_line, c);
            free(request_line);
        } else {
            return;
        }
    }
}
Example #12
0
void Users::process(){
    int n = SDLNet_CheckSockets(set, 0);
    if (n < 1) return;

    if (SDLNet_SocketReady(sock)){
        printf("new user...\n");
        TCPsocket newuser = SDLNet_TCP_Accept(sock);

        printf("Accepted...\n");
        User *u = new User(newuser);
        push_back(u);
        SDLNet_TCP_AddSocket(set,newuser);
    }

    User *u;
    for( iterator i = begin(); i != end(); i++ ){
        u = *i;
        if (SDLNet_SocketReady(u->sock)){
            int len;
            char buf[MAXLEN];
            if ((len = readLine(u->sock,buf,sizeof(buf))) > 0){
                fprintf(stderr,"got len=%d text from '%s': '%s'\n",len,u->name,buf);
                handle_command(buf,u);
            } else {
                printf("dead connection\n");
                SDLNet_TCP_DelSocket(set, u->sock);
                SDLNet_TCP_Close(u->sock);
                i = erase(i);
            }
        }
    }
}
Example #13
0
void
inbound_login_end (session *sess, char *text)
{
	server *serv = sess->server;

	if (!serv->end_of_motd)
	{
		if (prefs.ip_from_server)
		{
			serv->skip_next_who = TRUE;
			serv->p_get_ip (serv, serv->nick);	/* sends WHO mynick */
		}
		set_default_modes (serv);
		if (serv->eom_cmd)
			handle_command (sess, serv->eom_cmd, TRUE);
		check_willjoin_channels (serv);
		if (serv->supports_watch)
			notify_send_watches (serv);
		serv->end_of_motd = TRUE;
	}
	if (prefs.skipmotd && !serv->motd_skipped)
	{
		serv->motd_skipped = TRUE;
		EMIT_SIGNAL (XP_TE_MOTDSKIP, serv->server_session, NULL, NULL,
						 NULL, NULL, 0);
		return;
	}
	EMIT_SIGNAL (XP_TE_MOTD, serv->server_session, text, NULL,
					 NULL, NULL, 0);
}
void command_loop(Socket *client) {
    char buffer[64];

    while (true) {
        if (client->Receive(buffer, 8, 0) != 8) {
            return;
        }

        uint64_t length = ExtractMessageLength(buffer);
        if (length > 64) {
            ALOGE("Wrong message length: %" PRId64, length);
            return;
        }

        ssize_t read = client->Receive(buffer, length, 0);
        if (read != (ssize_t)length) {
            ALOGE("Failed to retrive command.");
            return;
        }

        std::vector<std::string> cmd = android::base::Split(std::string(buffer, read), ":");
        if (handle_command(client, cmd[0], std::vector<std::string>(cmd.begin() + 1, cmd.end())) != true) {
            return;
        }
    }
}
Example #15
0
static void check_command(TeleUser *u)
{
	if (tserver_poll(u)) {
		handle_command(u);
		busy++;
	}
}
Example #16
0
static void handle_line(const char *line, struct line_buffer *stdin_buf)
{
	const char *arg = strchr(line, ' ');
	if (!arg)
		die("no argument in line: %s", line);
	handle_command(line, arg + 1, stdin_buf);
}
Example #17
0
void usart_dostuff() {
  if (flag_command_ready)
    handle_command();

  if (flag_read_flash) {
    bool_t verified = false;
    while (!verified) {
      flash_read(flash_addr);
      verified = flash_verify(flash_addr);
    }

    while (!verified) {
      _delay_ms(25);
      flash_read(flash_addr);
      verified = flash_verify(flash_addr);
    }

    flash_addr++;
    flag_read_flash = false;
  }

  if (flag_xmodem_next_packet) {
    prepare_packet();
    usart_send();
  }
}
Example #18
0
int
main (int original_argc, char **original_argv)
{
	const char **argv = (const char **) original_argv;
	int argc = original_argc;

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	argv++;
	argc--;

	if (argc > 0) {
		/* For cases like --version */
		if (g_str_has_prefix (argv[0], "--")) {
			argv[0] += 2;
		}
	} else {
		/* The user didn't specify a command; give them help */
		print_usage ();
		exit (1);
	}

	handle_command (argc, argv);

	if ((char **) argv != original_argv) {
		g_strfreev ((char **) argv);
	}

	return EXIT_FAILURE;
}
Example #19
0
static void open_url_cb(GtkWidget *item, char *url) {
	char buf[512];

	/* pass this to /URL so it can handle irc:// */
	snprintf(buf, sizeof(buf), "URL %s", url);
	handle_command(current_sess, buf, FALSE);
}
Example #20
0
File: config.c Project: ffa7a7/sway
bool read_config(FILE *file, bool is_active) {
	struct sway_config *temp_config = malloc(sizeof(struct sway_config));
	config_defaults(temp_config);
	if (is_active) {
		sway_log(L_DEBUG, "Performing configuration file reload");
		temp_config->reloading = true;
		temp_config->active = true;
	}

	bool success = true;

	int temp_depth = 0; // Temporary: skip all config sections with depth

	while (!feof(file)) {
		int _;
		char *line = read_line(file);
		line = strip_whitespace(line, &_);
		line = strip_comments(line);
		if (!line[0]) {
			goto _continue;
		}
		if (temp_depth && line[0] == '}') {
			temp_depth--;
			goto _continue;
		}

		// Any command which would require wlc to be initialized
		// should be queued for later execution
		list_t *args = split_string(line, " ");
		if (!is_active && (
			strcmp("exec", args->items[0]) == 0 ||
			strcmp("exec_always", args->items[0]) == 0 )) {
			sway_log(L_DEBUG, "Deferring command %s", line);

			char *cmd = malloc(strlen(line) + 1);
			strcpy(cmd, line);
			list_add(temp_config->cmd_queue, cmd);
		} else if (!temp_depth && !handle_command(temp_config, line)) {
			sway_log(L_DEBUG, "Config load failed for line %s", line);
			success = false;
			temp_config->failed = true;
		}
		list_free(args);

_continue:
		if (line && line[strlen(line) - 1] == '{') {
			temp_depth++;
		}
		free(line);
	}

	if (is_active) {
		temp_config->reloading = false;
		container_map(&root_container, reset_gaps, NULL);
		arrange_windows(&root_container, -1, -1);
	}
	config = temp_config;

	return success;
}
Example #21
0
void nslp_tick(void)
{
  uint8_t* packet;
  uint16_t packetLength;
  nslp_query* query;

  nslp_binary_transport_tick();

  packetLength = nslp_binary_transport_receive(&packet);
  if (packetLength > 0)
  {
    handle_command(packet, packetLength);
  }

  for (query = queries; query < (queries + NSLP_MAXIMUM_CONCURRENT_QUERIES); query++)
  {
    if (query->state == NSLP_QUERY_STATE_COMPLETE)
    {
      uint8_t* responseData = NULL;
      uint16_t responseDataLength = 0;
      nslp_query_status status;

      status = end_nslp_query(query, &responseData, &responseDataLength);

      send_query_response(0, status, responseData, responseDataLength);

      query->state = NSLP_QUERY_STATE_IDLE;
    }
  }
}
Example #22
0
void source_fp(const FILE *fp) /* {{{ */
{
	/* given an open file handle, run the commands read from it */
	char *line;

	/* read file */
	line = calloc(TOTALLENGTH, sizeof(char));
	while (fgets(line, TOTALLENGTH, (FILE *)fp))
	{
		char *val;

		/* discard comment lines or blank lines */
		if (line[0]=='#' || line[0]=='\n')
			continue;

		/* handle comments that are mid-line */
		if((val = strchr(line, '#')))
			*val = '\0';

		/* handle commands */
		else
			handle_command(line);

		/* get memory for a new line */
		free(line);
		line = calloc(TOTALLENGTH, sizeof(char));
	}
	free(line);
} /* }}} */
Example #23
0
static void
irc_init (session *sess)
{
	static int done_init = FALSE;

	if (done_init)
		return;

	done_init = TRUE;

	if (!arg_skip_plugins)
		plugin_autoload();	/* autoload ~/.xchat *.so */

	if (prefs.notify_timeout)
		notify_tag = g_timeout_add (prefs.notify_timeout * 1000, (GSourceFunc) notify_checklist, 0);

	g_timeout_add (prefs.away_timeout * 1000, (GSourceFunc) away_check, 0);
	g_timeout_add (500, (GSourceFunc) xchat_misc_checks, 0);

	if (arg_url != NULL)
	{
		char buf[512];
		snprintf (buf, sizeof (buf), "server %s", arg_url);
		handle_command (sess, buf, FALSE);
		g_free (arg_url);	/* from GOption */
	}
}
Example #24
0
void BC_Synchronous::handle_command_base(BC_SynchronousCommand *command)
{

	if(command)
	{
//printf("BC_Synchronous::handle_command_base 1 %d\n", command->command);
		switch(command->command)
		{
			case BC_SynchronousCommand::QUIT:
				done = 1;
				break;

			default:
				handle_command(command);
				break;
		}
	}

	handle_garbage();

	if(command)
	{
		command->command_done->unlock();
	}
}
Example #25
0
static void
irc_init (session *sess)
{
	static int done_init = FALSE;

	if (done_init)
		return;

	done_init = TRUE;

#ifdef USE_PLUGIN
	if (!skip_plugins)
		plugin_auto_load (sess);	/* autoload ~/.xchat *.so */
#endif
	plugin_add (sess, NULL, NULL, timer_plugin_init, NULL, NULL, FALSE);

	if (prefs.notify_timeout)
		notify_tag = fe_timeout_add (prefs.notify_timeout * 1000,
											  notify_checklist, 0);

	fe_timeout_add (prefs.away_timeout * 1000, away_check, 0);
	fe_timeout_add (500, xchat_misc_checks, 0);

	if (connect_url != NULL)
	{
		char buf[512];
		snprintf (buf, sizeof (buf), "server %s", connect_url);
		handle_command (sess, buf, FALSE);
		free (connect_url);
	}
}
void CEasyCommHandler::update()
{
  // Handle serial input
  if (Serial.available())
  {
    int32_t read_val = 0;
    while ((read_val = Serial.read()) >= 0)
    {
      mReceiveBuffer[mBufferIndex] = static_cast<uint8_t>(read_val);
      if (mBufferIndex == BUF_SIZE-1)
      {
        Serial.write("ERR buffer is full\n");
        mBufferIndex = 0;
        break;
      }
      if (mReceiveBuffer[mBufferIndex] == '\n' || mReceiveBuffer[mBufferIndex] == '\r' || mReceiveBuffer[mBufferIndex] == ' ')
      {
        // Command seperator detected, process command
        handle_command();
        mBufferIndex = 0;
        break;
      }
      mBufferIndex++;
    }
  }
}
static int dfs_write(const char *path, const char *buf, size_t size, off_t offset,
		struct fuse_file_info *info)
{
	DMSG("%s(%ld)",path,(long)size);
	//int w_size = 0;

	if(is_special_path(path))
	{
		return handle_command((char *)buf, size, offset);
	}

	DfsFile *file = dfsDir.find(path + 1);
	if(!is_file_exist(file))
		return -ENOENT;

	switch(file->status)
	{
		case DfsFile::REMOVED:
			return -ENOENT;

		case DfsFile::SYNCED:
			file->status = DfsFile::MODIFIED;
			/* no break */

		case DfsFile::MODIFIED:
		case DfsFile::CREATED:
			DMSG("offset: %ld", (long)offset);
			return file->write(buf, size, offset);
	}

	DMSG("unreachable");
	return -1;
}
Example #28
0
static void server_run(void)
{
	int pid = main_pid;
	int status;

	if (TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)) == -1)
		fatal("waitpid");

	if (WIFEXITED(status))
		fatal("WIFEXITED");

	if (ptrace(PTRACE_SETOPTIONS, pid, 0, PTRACE_O_TRACECLONE | PTRACE_O_TRACEEXEC | PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACEVFORKDONE) == -1)
		fatal("%s:%d ptrace SETOPTIONS (%s)", __FUNCTION__, __LINE__, strerror(errno));

	if (ptrace(PTRACE_CONT, pid, 0, 0) == -1)
		fatal("%s:%d ptrace CONT (%s)", __FUNCTION__, __LINE__, strerror(errno));

	for (;;) {
		int stop_sig = 0;

		pid = TEMP_FAILURE_RETRY(waitpid(-1, &status, __WALL));
		if (!pid)
			continue;

		if (pid == -1) {
			if (errno == ECHILD)
				break;
			fatal("waitpid (%s)", strerror(errno));
		}

		pthread_mutex_lock(&mutex);
		if (pid == wakeup_pid) {
			handle_command();
			wakeup_pid = -1;
			pthread_cond_broadcast(&cond);
		}
		pthread_mutex_unlock(&mutex);

		if (WIFEXITED(status))
			continue;

		if (WIFSTOPPED(status)) {
			stop_sig = WSTOPSIG(status);

			if (stop_sig == SIGTRAP)
				stop_sig = 0;
			else
			if (stop_sig == SIGSTOP)
				stop_sig = 0;
		}

		if (ptrace(PTRACE_CONT, pid, 0, stop_sig) == -1) {
			if (errno != ESRCH)
				fatal("%s:%d ptrace CONT (%s)", __FUNCTION__, __LINE__, strerror(errno));
		}
	}

	printf("No more childs.\n");
}
Example #29
0
static void
sigusr2_handler (int signal, siginfo_t *si, void *un)
{
	session *sess = current_sess;

	if (sess)
		handle_command (sess, "SIGUSR2", FALSE);
}
Example #30
0
static void
ctcp_reply (session *sess, char *tbuf, char *nick, char *word[],
				char *word_eol[], char *conf)
{
	auto_insert (tbuf, conf, word, word_eol, "", "", word_eol[5], "", "", nick);

	handle_command (tbuf, sess, 0, 0);
}