示例#1
0
文件: xchat.c 项目: arinity/gchat2
session *
new_ircwindow (server *serv, char *name, int type, int focus)
{
	session *sess;

	switch (type)
	{
	case SESS_SERVER:
		serv = server_new ();
		if (prefs.use_server_tab)
			sess = session_new (serv, name, SESS_SERVER, focus);
		else
			sess = session_new (serv, name, SESS_CHANNEL, focus);
		serv->server_session = sess;
		serv->front_session = sess;
		break;
	case SESS_DIALOG:
		sess = session_new (serv, name, type, focus);
		if (prefs.logging)
			log_open (sess);
		break;
	default:
/*	case SESS_CHANNEL:
	case SESS_NOTICES:
	case SESS_SNOTICES:*/
		sess = session_new (serv, name, type, focus);
		break;
	}

	irc_init (sess);
	if (prefs.text_replay)
		scrollback_load (sess);

	return sess;
}
示例#2
0
文件: irssi.c 项目: svn2github/irssi
void noui_init(void)
{
	static struct poptOption options[] = {
		POPT_AUTOHELP
		{ "load", 'l', POPT_ARG_STRING, &autoload_module, 0, "Module to load (default = bot)", "MODULE" },
		{ NULL, '\0', 0, NULL }
	};

	autoload_module = NULL;
	args_register(options);

	irssi_gui = IRSSI_GUI_NONE;
	core_init();
	irc_init();

	module_register("core", "fe-none");

	signal_add("reload", (SIGNAL_FUNC) sig_reload);
	signal_add("gui exit", (SIGNAL_FUNC) sig_exit);

#ifdef HAVE_STATIC_PERL
        perl_core_init();
#endif

	signal_emit("irssi init finished", 0);
}
示例#3
0
session *
new_ircwindow (server *serv, char *name, int type, int focus)
{
	session *sess;

	switch (type)
	{
	case SESS_SERVER:
		serv = server_new ();
		if (prefs.hex_gui_tab_server)
			sess = session_new (serv, name, SESS_SERVER, focus);
		else
			sess = session_new (serv, name, SESS_CHANNEL, focus);
		serv->server_session = sess;
		serv->front_session = sess;
		break;
	case SESS_DIALOG:
		sess = session_new (serv, name, type, focus);
		log_open_or_close (sess);
		break;
	default:
/*	case SESS_CHANNEL:
	case SESS_NOTICES:
	case SESS_SNOTICES:*/
		sess = session_new (serv, name, type, focus);
		break;
	}

	irc_init (sess);
	chanopt_load (sess);
	scrollback_load (sess);
	plugin_emit_dummy_print (sess, "Open Context");

	return sess;
}
示例#4
0
int t_irc_user_inchannel__user_in_channel__returns_true() {
	struct irc_globdata *irc = irc_init();
	struct ircuser* user = _irc_register_withnick(irc, 1, "pepe");
	struct ircchan* chan = _irc_create_chan(irc, "#test", 1, user);

	mu_assert_eq(irc_user_inchannel(chan, user), OK, "User is in channel, incorrect result");

	irc_destroy(irc);
	mu_end;
}
示例#5
0
文件: test-796.c 项目: dequis/irssi
static void server_destroy_flood_set_up(ServerDestroyFloodData *fixture, const void *data)
{
	args_execute(0, NULL);
	core_init();
	irc_init();
	fe_common_core_init();
	fe_common_irc_init();
	signal_emit("irssi init finished", 0);
	command_bind("echo", NULL, (SIGNAL_FUNC) cmd_echo);
	signal_add("message public", (SIGNAL_FUNC) sig_public);
	signal_add("server destroyed", (SIGNAL_FUNC) print_destroyed);
	signal_add_first("server disconnected", (SIGNAL_FUNC) print_disconnect);
}
示例#6
0
session *
new_ircwindow (server *serv, char *name, int type, int focus)
{
	session *sess;

	switch (type)
	{
	case SESS_SERVER:
		serv = server_new ();
		if (prefs.hex_gui_tab_server)
			sess = session_new (serv, name, SESS_SERVER, focus);
		else
			sess = session_new (serv, name, SESS_CHANNEL, focus);
		serv->server_session = sess;
		serv->front_session = sess;
		break;
	case SESS_DIALOG:
		sess = session_new (serv, name, type, focus);
		break;
	default:
/*	case SESS_CHANNEL:
	case SESS_NOTICES:
	case SESS_SNOTICES:*/
		sess = session_new (serv, name, type, focus);
		break;
	}

	irc_init (sess);
	chanopt_load (sess);
	scrollback_load (sess);
	if (sess->scrollwritten && sess->scrollback_replay_marklast)
		sess->scrollback_replay_marklast (sess);
	if (type == SESS_DIALOG)
	{
		struct User *user;

		log_open_or_close (sess);

		user = userlist_find_global (serv, name);
		if (user && user->hostname)
			set_topic (sess, user->hostname, user->hostname);
	}
	plugin_emit_dummy_print (sess, "Open Context");

	return sess;
}
示例#7
0
文件: main.c 项目: yy-nm/irc-client
void handle_client(int client_fd, char *ip, short port)
{
	irc_data_t irc_channels;
	char buf[MAX_CLIENT_SEND_BUFF_SZ];
	int retn = 0;
	irc_init(&irc_channels);
	if (0 != get_ip_from_hostname(ip, buf, sizeof(buf))) {
		perror("get ip from host error\n");
		goto err;
	}
	printf("connect to irc server: %s[%s] %d\n", ip, buf, port);
	irc_channels.socket_fd = create_client_socket(buf, port);
	if (0 > irc_channels.socket_fd) {
		goto err;
	}
	if (0 != pthread_create(&irc_channels.thread_recv, NULL
		, thread_recv_msg_from_server, &irc_channels)) {
		perror("create recv thread error!");
		goto err;
	}
	if (0 != pthread_create(&irc_channels.thread_send, NULL
		, thread_send_msg_to_server, &irc_channels)) {
		perror("create send thread error!");
		goto err;
	}

	for(;;) {
		retn = recv(client_fd, buf, sizeof(buf) - 1, 0);
		if (retn > 0) {
			buf[retn - 1] = '\0';
			fprintf(stdout, "[local-client]: recv: %s\n",buf);
			handle_msg_remove_illegal_ch(buf, retn);
			handle_msg_from_client(&irc_channels, buf, retn - 1);
		} else if (0 == retn) {
			fprintf(stdout, "client offline");
			break;
		} else {
			fprintf(stderr, "client error");
			break;
		}
	}

err:
	close(client_fd);
	irc_free(&irc_channels);
}
示例#8
0
文件: irssi.c 项目: svn2github/irssi
static void textui_init(void)
{
	static struct poptOption options[] = {
		POPT_AUTOHELP
		{ NULL, '\0', 0, NULL }
	};

	args_register(options);

	irssi_gui = IRSSI_GUI_TEXT;
	core_init();
	irc_init();
	fe_common_core_init();
	fe_common_irc_init();

        theme_register(gui_text_formats);
	signal_add("gui exit", (SIGNAL_FUNC) sig_exit);
}
示例#9
0
文件: irssi.c 项目: irssi/irssi
void noui_init(void)
{
	srand(time(NULL));

	irssi_gui = IRSSI_GUI_NONE;
	core_init();
	irc_init();

	module_register("core", "fe-none");

	signal_add("reload", (SIGNAL_FUNC) sig_reload);
	signal_add("gui exit", (SIGNAL_FUNC) sig_exit);

#ifdef HAVE_STATIC_PERL
        perl_core_init();
#endif

	signal_emit("irssi init finished", 0);
}
示例#10
0
文件: irssi.c 项目: svn2github/irssi
static void textui_init(void)
{
#ifdef SIGTRAP
	struct sigaction act;

	sigemptyset(&act.sa_mask);
	act.sa_flags = 0;
	act.sa_handler = SIG_IGN;
	sigaction(SIGTRAP, &act, NULL);
#endif

	irssi_gui = IRSSI_GUI_TEXT;
	core_init();
	irc_init();
	fe_common_core_init();
	fe_common_irc_init();

	theme_register(gui_text_formats);
	signal_add_last("gui exit", (SIGNAL_FUNC) sig_exit);
}
示例#11
0
session *
new_ircwindow (server *serv, char *name, int type)
{
	session *sess;

	switch (type)
	{
	case SESS_SERVER:
		serv = new_server ();
		if (prefs.use_server_tab)
		{
			register unsigned int oldh = prefs.hideuserlist;
			prefs.hideuserlist = 1;
			sess = new_session (serv, name, SESS_SERVER);
			prefs.hideuserlist = oldh;
		} else
		{
			sess = new_session (serv, name, SESS_CHANNEL);
		}
		serv->server_session = sess;
		serv->front_session = sess;
		break;
	case SESS_DIALOG:
		sess = new_session (serv, name, type);
		if (prefs.logging)
			log_open (sess);
		break;
	default:
/*	case SESS_CHANNEL:
	case SESS_NOTICES:
	case SESS_SNOTICES:*/
		sess = new_session (serv, name, type);
		break;
	}

	irc_init (sess);
	plugin_emit_dummy_print (sess, "Open Context");

	return sess;
}
示例#12
0
int ircparty_LTX_start(egg_module_t *modinfo)
{
	void *config_root;

	irc_generic_owner.module = irc_sock_owner.module = irc_pm_owner.module = modinfo;

	modinfo->name = "ircparty";
	modinfo->author = "eggdev";
	modinfo->version = "1.0.0";
	modinfo->description = "irc client support for the partyline";
	modinfo->close_func = ircparty_close;

	/* Set defaults. */
	memset(&irc_config, 0, sizeof(irc_config));

	/* Link our vars in. */
	config_root = config_get_root("eggdrop");
	config_link_table(irc_config_vars, config_root, "ircparty", 0, NULL);
	config_update_table(irc_config_vars, config_root, "ircparty", 0, NULL);

	irc_init();
	return(0);
}
示例#13
0
int16_t parse_cmd_irc(char *cmd, char *output, uint16_t len) 
{
  irc_init(); 
  return snprintf_P(cmd, len, PSTR("irc init"));
}
示例#14
0
static void
init(int *argc, char ***argv, struct settings_s *sett)
{
	if (setvbuf(stdin, NULL, _IOLBF, 0) != 0)
		WE("setvbuf stdin");

	if (setvbuf(stdout, NULL, _IOLBF, 0) != 0)
		WE("setvbuf stdout");

	g_irc = irc_init();

	irc_set_track(g_irc, true);

	irc_set_nick(g_irc, "iwat");
	irc_set_uname(g_irc, "iwat");
	irc_set_fname(g_irc, "irc netwat");
	irc_set_conflags(g_irc, 0);
	irc_regcb_conread(g_irc, conread, 0);

	sett->heartbeat_us = DEF_HEARTBEAT_MS * 1000u;
	sett->cfwait_s = DEF_CONFAILWAIT_S;
	sett->verb = DEF_VERB;
	sett->scto_us = DEF_CONTO_SOFT_MS * 1000u;
	sett->hcto_us = DEF_CONTO_HARD_MS * 1000u;

	process_args(argc, argv, sett);

	if (!*argc)
		C("no server given");

	for (int i = 0; i < *argc; i++) {
		char host[256];
		uint16_t port;
		bool ssl = false;
		lsi_ut_parse_hostspec(host, sizeof host, &port, &ssl, (*argv)[i]);

		/* we choke on all other sorts of invalid addrs/hosts later */

		struct srvlist_s *node = MALLOC(sizeof *node);
		if (!node)
			CE("malloc failed");

		node->host = STRDUP(host);
		node->port = port;
		node->ssl = ssl;
		node->next = NULL;

		if (!g_srvlist)
			g_srvlist = node;
		else {
			struct srvlist_s *n = g_srvlist;
			while (n->next)
				n = n->next;
			n->next = node;
		}
	}

	irc_set_connect_timeout(g_irc, g_sett.scto_us, g_sett.hcto_us);

	D("initialized");
	return;
}
示例#15
0
int main(int argc, char **argv) {
   int ret, opt, conn, plugins_loaded = 0, banner_displayed = 0;
   unsigned long now, lastconn = time(NULL);
   FILE *urandom;

   runlevel = RL_OFFLINE;   

   while ((opt = getopt(argc, argv, "c:dj:u:vh")) != -1) {
      switch(opt) {
         case 'c':
            settings.config = optarg;
            break;
         case 'd':
            settings.daemonize = 1;
            break;
         case 'j':
            settings.chroot = optarg;
            break;
         case 'u':
            settings.chuser = optarg;
            break;
         case 'v':
            print_version();
            break;
         case 'h':
         default:
            print_usage(argv[0]);
            break;
      }
   }

   srand(time(NULL));
   
   urandom = fopen("/dev/urandom", "r");
   srrand(time(NULL) ^ getpid(), urandom);

   if (config_parse(settings.config)) {
      fprintf(stderr, "Unable to load configuration file '%s'.\n",
	settings.config);
      return -1;
   }

   if (checkconfig())
      return -1;

   if (settings.daemonize) {
      ret = fork();
      switch(ret) {
         case -1:
            fprintf(stderr, "Unable to fork to background\n");
            return -1;
        default:
            return 0;
      }
   }

   if (secure_it(settings.chroot, settings.chuser)) {
      fprintf(stderr, "Failed to chroot/setuid\n");
      return -1;
   }

#ifdef TLS
  if (gnutls_global_init() == GNUTLS_E_SUCCESS)
    atexit(gnutls_global_deinit);
  else
    fprintf(stderr, "Unable to initialize TLS library\n");
#endif

  if (dns_init() == -1)
      warn("Unable to initialize dns resolver\n");
  
   for(runlevel = RL_RUNNING; runlevel;) {
      if (irc_init() == -1) {
         warn("Unable to init irc data structure");
         return -1;
      }

      if(!plugins_loaded) {
         plugins_load();
         plugins_loaded = 1;
      }

      if(!banner_displayed) {
         banner_displayed = banner("Welcome to " PACKAGE_STRING
#ifdef SVN_REV
            "." SVN_REV
#endif
         );
      }

      while ((runlevel == RL_RUNNING) && (irc_conn() == -1)) {
         warn("Unable to establish irc connection\n");
         sleep(RECONNECT_DELAY);
      }

      lastconn = time(NULL);
      while(runlevel == RL_RUNNING)
         io_loop(100);
      
      irc_free();

      if((runlevel != RL_RUNNING) && plugins_loaded) { 
         plugins_unload();
         plugins_loaded = 0;
      }
      
      if(runlevel == RL_RELOAD) {
         printc("Reloading config file '%s'...\n", settings.config);
         if(config_parse(settings.config)) {
            warn("Error reloading config file.\n");
            runlevel = RL_OFFLINE;
         } else if(checkconfig()) {
            runlevel = RL_OFFLINE;
         }
         runlevel = RL_RUNNING;
      }

      conn = 0;
      now = time(NULL);
      if(runlevel != RL_OFFLINE) {
        runlevel = RL_RUNNING;
        if (now < lastconn + RECONNECT_DELAY)
          sleep(lastconn + RECONNECT_DELAY - now);
      }
   }

   if(urandom)
      fclose(urandom);
   return 0;
}
示例#16
0
文件: main.c 项目: larsivsi/cbot
int main(int argc, char **argv)
{
	tic();

	char *conf_file = NULL;
	socket_fd = -1;
	for (int i=1; i<argc; i++) {
		if (!strcmp(argv[i], "-c")) {
			if (argc <= i) {
				print_usage();
			}
			conf_file = argv[++i];
		} else if (!strcmp(argv[i], "-fd")) {
			if (argc <= i) {
				print_usage();
			}
			socket_fd = atoi(argv[++i]);
		} else {
			printf(" >> unknown option: %s\n", argv[i]);
		}
	}

	if (!conf_file)
		conf_file = "cbot.conf";
	load_config(conf_file);

	// Set rand seed
	srand(time(NULL));

	// Set up cURL
	curl_global_init(CURL_GLOBAL_ALL);

	// Set up db connection for logging
	if (config->enabled_modules & MODULE_LOG) {
		log_init();
	}

	// Parse markov corpus
	if (config->enabled_modules & MODULE_MARKOV) {
		markov_init(config->markovcorpus);
	}

	irc_init();

	if (socket_fd == -1) {
		printf(" - Connecting to %s:%s with nick %s, joining channels...\n",
			config->host, config->port, config->nick);
		net_connect();
	} else { // In-place upgrade yo
		printf(" >> Already connected, upgraded in-place!\n");
		join_channels();
	}

	struct recv_data *irc = malloc(sizeof(struct recv_data));
	patterns = malloc(sizeof(*patterns));
	compile_patterns(patterns);

	// Select param
	fd_set socket_set;
	FD_ZERO(&socket_set);
	FD_SET(STDIN_FILENO, &socket_set);
	FD_SET(socket_fd, &socket_set);


	int recv_size;
	char buffer[BUFFER_SIZE];
	char input[BUFFER_SIZE];
	memset(buffer, 0, BUFFER_SIZE);
	size_t buffer_length = 0;
	while (1) {
		int ret = select(socket_fd+1, &socket_set, 0, 0, 0);
		if (ret == -1) {
			printf(" >> Disconnected, reconnecting...\n");
			close(socket_fd);
			net_connect();
		}
		if (FD_ISSET(STDIN_FILENO, &socket_set)) {
			if (fgets(input, BUFFER_SIZE, stdin) == NULL) {
				printf(" >> Error while reading from stdin!\n");
				continue;
			}

			if (strcmp(input, "quit\n") == 0) {
				printf(" >> Bye!\n");
				break;
			} else if (strcmp(input, "reload\n") == 0) {
				terminate();
				free(irc);
				free_patterns(patterns);
				free(patterns);

				// Set up arguments
				char * arguments[6];
				arguments[0] = argv[0];
				arguments[1] = "-c";
				arguments[2] = conf_file;
				arguments[3] = "-fd";
				char fdstring[snprintf(NULL, 0, "%d", socket_fd)];
				sprintf(fdstring, "%d", socket_fd);
				arguments[4] = fdstring;
				arguments[5] = NULL;

				printf(" >> Upgrading...\n");
				execvp(argv[0], arguments);

				printf(" !!! Execvp failing, giving up...\n");
				exit(-1);
			} else if (strncmp(input, "say ", 4) == 0) {
				int offsets[30];
				int offsetcount = pcre_exec(patterns->command_say, 0, input, strlen(input), 0, 0, offsets, 30);
				if (offsetcount > 0) {
					char channel[BUFFER_SIZE];
					char message[BUFFER_SIZE];
					pcre_copy_substring(input, offsets, offsetcount, 1, channel, BUFFER_SIZE);
					pcre_copy_substring(input, offsets, offsetcount, 2, message, BUFFER_SIZE);
					char sendbuf[strlen("PRIVMSG  : ") + strlen(channel) + strlen(message)];
					sprintf(sendbuf, "PRIVMSG %s :%s\n", channel, message);
					irc_send_str(sendbuf);
				}
			} else if (strncmp(input, "kick ", 5) == 0) {
				int offsets[30];
				int offsetcount = pcre_exec(patterns->command_kick, 0, input, strlen(input), 0, 0, offsets, 30);
				if (offsetcount > 0) {
					char channel[BUFFER_SIZE];
					char user[BUFFER_SIZE];
					pcre_copy_substring(input, offsets, offsetcount, 1, channel, BUFFER_SIZE);
					pcre_copy_substring(input, offsets, offsetcount, 2, user, BUFFER_SIZE);
					char sendbuf[strlen("KICK   :Gene police! You! Out of the pool, now!\n") + strlen(channel) + strlen(user)];
					sprintf(sendbuf, "KICK %s %s :Gene police! You! Out of the pool, now!\n", channel, user);
					irc_send_str(sendbuf);
				}
			} else {
				printf(" >> Unrecognized command. Try 'quit'\n");
			}
			FD_SET(socket_fd, &socket_set);
		} else {
			if (buffer_length >= BUFFER_SIZE - 1) {
				printf(" >> what the f**k, IRCd, a line longer than 4k? dropping some buffer\n");
				memset(buffer, 0, BUFFER_SIZE);
				buffer_length = 0;
				continue;
			}

			recv_size = recv(socket_fd, buffer + buffer_length, BUFFER_SIZE - buffer_length - 1, 0);
			buffer_length += recv_size;
			buffer[buffer_length] = '\0';
			if (recv_size == 0) {
				printf(" >> recv_size is 0, assuming closed remote socket, reconnecting\n");
				close(socket_fd);
				printf("closed\n");
				net_connect();
				printf("reconnected\n");
			}
			char *newlinepos = 0;
			char *bufbegin = buffer;
			while ((newlinepos = strchr(bufbegin, '\n'))) {
				*newlinepos = 0;
				printf(" ~ %s\n", bufbegin);
				// Only handle privmsg
				if (irc_parse_input(bufbegin, irc, patterns)) {
					irc_handle_input(irc, patterns);
				}
				bufbegin = newlinepos + 1;
			}
			size_t bytes_removed = bufbegin - buffer;
			memmove(buffer, bufbegin, buffer_length - bytes_removed);
			buffer_length -= bytes_removed;
			memset(buffer + buffer_length, 0, BUFFER_SIZE - buffer_length);

			FD_SET(STDIN_FILENO, &socket_set);
		}
	}
	printf(" >> Socket closed, quitting...\n");

	close(socket_fd);

	free(irc);
	free_patterns(patterns);
	free(patterns);

	terminate();

	return 0;
}
示例#17
0
void
irc_periodic(void)
{
  if (! irc_conn)
      irc_init();
}