summary refs log blame commit diff stats
path: root/src/common/plugin.h
blob: b0c89d1b222fedb62ac83d251a1e6468e387434f (plain) (tree)



































































































































                                                                                                                                 
#ifndef XCHAT_COMMONPLUGIN_H
#define XCHAT_COMMONPLUGIN_H

#ifdef PLUGIN_C
struct _xchat_plugin
{
	/* Keep these insync with xchat-plugin.h */
	/* !!don't change the order, to keep binary compat!! */
	xchat_hook *(*xchat_hook_command) (xchat_plugin *ph,
		    const char *name,
		    int pri,
		    int (*callback) (char *word[], char *word_eol[], void *user_data),
		    const char *help_text,
		    void *userdata);
	xchat_hook *(*xchat_hook_server) (xchat_plugin *ph,
		   const char *name,
		   int pri,
		   int (*callback) (char *word[], char *word_eol[], void *user_data),
		   void *userdata);
	xchat_hook *(*xchat_hook_print) (xchat_plugin *ph,
		  const char *name,
		  int pri,
		  int (*callback) (char *word[], void *user_data),
		  void *userdata);
	xchat_hook *(*xchat_hook_timer) (xchat_plugin *ph,
		  int timeout,
		  int (*callback) (void *user_data),
		  void *userdata);
	xchat_hook *(*xchat_hook_fd) (xchat_plugin *ph,
		   int fd,
		   int flags,
		   int (*callback) (int fd, int flags, void *user_data),
		   void *userdata);
	void *(*xchat_unhook) (xchat_plugin *ph,
	      xchat_hook *hook);
	void (*xchat_print) (xchat_plugin *ph,
	     const char *text);
	void (*xchat_printf) (xchat_plugin *ph,
	      const char *format, ...);
	void (*xchat_command) (xchat_plugin *ph,
	       const char *command);
	void (*xchat_commandf) (xchat_plugin *ph,
		const char *format, ...);
	int (*xchat_nickcmp) (xchat_plugin *ph,
	       const char *s1,
	       const char *s2);
	int (*xchat_set_context) (xchat_plugin *ph,
		   xchat_context *ctx);
	xchat_context *(*xchat_find_context) (xchat_plugin *ph,
		    const char *servname,
		    const char *channel);
	xchat_context *(*xchat_get_context) (xchat_plugin *ph);
	const char *(*xchat_get_info) (xchat_plugin *ph,
		const char *id);
	int (*xchat_get_prefs) (xchat_plugin *ph,
		 const char *name,
		 const char **string,
		 int *integer);
	xchat_list * (*xchat_list_get) (xchat_plugin *ph,
		const char *name);
	void (*xchat_list_free) (xchat_plugin *ph,
		 xchat_list *xlist);
	const char * const * (*xchat_list_fields) (xchat_plugin *ph,
		   const char *name);
	int (*xchat_list_next) (xchat_plugin *ph,
		 xchat_list *xlist);
	const char * (*xchat_list_str) (xchat_plugin *ph,
		xchat_list *xlist,
		const char *name);
	int (*xchat_list_int) (xchat_plugin *ph,
		xchat_list *xlist,
		const char *name);
	void * (*xchat_plugingui_add) (xchat_plugin *ph,
		     const char *filename,
		     const char *name,
		     const char *desc,
		     const char *version,
		     char *reserved);
	void (*xchat_plugingui_remove) (xchat_plugin *ph,
			void *handle);
	int (*xchat_emit_print) (xchat_plugin *ph,
			const char *event_name, ...);
	void *(*xchat_read_fd) (xchat_plugin *ph);
	time_t (*xchat_list_time) (xchat_plugin *ph,
		xchat_list *xlist,
		const char *name);
	char *(*xchat_gettext) (xchat_plugin *ph,
		const char *msgid);
	void (*xchat_send_modes) (xchat_plugin *ph,
		  const char **targets,
		  int ntargets,
		  int modes_per_line,
		  char sign,
		  char mode);
	char *(*xchat_strip) (xchat_plugin *ph,
	     const char *str,
	     int len,
	     int flags);
	void (*xchat_free) (xchat_plugin *ph,
	    void *ptr);
	void *(*xchat_dummy4) (xchat_plugin *ph);
	void *(*xchat_dummy3) (xchat_plugin *ph);
	void *(*xchat_dummy2) (xchat_plugin *ph);
	void *(*xchat_dummy1) (xchat_plugin *ph);
	/* PRIVATE FIELDS! */
	void *handle;		/* from dlopen */
	char *filename;	/* loaded from */
	char *name;
	char *desc;
	char *version;
	session *context;
	void *deinit_callback;	/* pointer to xchat_plugin_deinit */
	unsigned int fake:1;		/* fake plugin. Added by xchat_plugingui_add() */
	unsigned int free_strings:1;		/* free name,desc,version? */
};
#endif

char *plugin_load (session *sess, char *filename, char *arg);
void plugin_add (session *sess, char *filename, void *handle, void *init_func, void *deinit_func, char *arg, int fake);
int plugin_kill (char *name, int by_filename);
void plugin_kill_all (void);
void plugin_auto_load (session *sess);
int plugin_emit_command (session *sess, char *name, char *word[], char *word_eol[]);
int plugin_emit_server (session *sess, char *name, char *word[], char *word_eol[]);
int plugin_emit_print (session *sess, char *word[]);
int plugin_emit_dummy_print (session *sess, char *name);
int plugin_emit_keypress (session *sess, unsigned int state, unsigned int keyval, int len, char *string);
GList* plugin_command_list(GList *tmp_list);
int plugin_show_help (session *sess, char *cmd);
void plugin_command_foreach (session *sess, void *userdata, void (*cb) (session *sess, void *userdata, char *name, char *usage));

#endif
">); return TRUE; } return FALSE; } /* check if a msg should be ignored by browsing our ignore list */ int ignore_check (char *host, int type) { struct ignore *ig; GSList *list = ignore_list; /* check if there's an UNIGNORE first, they take precendance. */ while (list) { ig = (struct ignore *) list->data; if (ig->type & IG_UNIG) { if (ig->type & type) { if (match (ig->mask, host)) return FALSE; } } list = list->next; } list = ignore_list; while (list) { ig = (struct ignore *) list->data; if (ig->type & type) { if (match (ig->mask, host)) { ignored_total++; if (type & IG_PRIV) ignored_priv++; if (type & IG_NOTI) ignored_noti++; if (type & IG_CHAN) ignored_chan++; if (type & IG_CTCP) ignored_ctcp++; if (type & IG_INVI) ignored_invi++; fe_ignore_update (2); return TRUE; } } list = list->next; } return FALSE; } static char * ignore_read_next_entry (char *my_cfg, struct ignore *ignore) { char tbuf[1024]; /* Casting to char * done below just to satisfy compiler */ if (my_cfg) { my_cfg = cfg_get_str (my_cfg, "mask", tbuf, sizeof (tbuf)); if (!my_cfg) return NULL; ignore->mask = strdup (tbuf); } if (my_cfg) { my_cfg = cfg_get_str (my_cfg, "type", tbuf, sizeof (tbuf)); ignore->type = atoi (tbuf); } return my_cfg; } void ignore_load () { struct ignore *ignore; struct stat st; char *cfg, *my_cfg; int fh, i; fh = xchat_open_file ("ignore.conf", O_RDONLY, 0, 0); if (fh != -1) { fstat (fh, &st); if (st.st_size) { cfg = malloc (st.st_size + 1); cfg[0] = '\0'; i = read (fh, cfg, st.st_size); if (i >= 0) cfg[i] = '\0'; my_cfg = cfg; while (my_cfg) { ignore = malloc (sizeof (struct ignore)); memset (ignore, 0, sizeof (struct ignore)); if ((my_cfg = ignore_read_next_entry (my_cfg, ignore))) ignore_list = g_slist_prepend (ignore_list, ignore); else free (ignore); } free (cfg); } close (fh); } } void ignore_save () { char buf[1024]; int fh; GSList *temp = ignore_list; struct ignore *ig; fh = xchat_open_file ("ignore.conf", O_TRUNC | O_WRONLY | O_CREAT, 0600, XOF_DOMODE); if (fh != -1) { while (temp) { ig = (struct ignore *) temp->data; if (!(ig->type & IG_NOSAVE)) { snprintf (buf, sizeof (buf), "mask = %s\ntype = %d\n\n", ig->mask, ig->type); write (fh, buf, strlen (buf)); } temp = temp->next; } close (fh); } } static gboolean flood_autodialog_timeout (gpointer data) { prefs.autodialog = 1; return FALSE; } int flood_check (char *nick, char *ip, server *serv, session *sess, int what) /*0=ctcp 1=priv */ { /* serv int ctcp_counter; time_t ctcp_last_time; prefs unsigned int ctcp_number_limit; unsigned int ctcp_time_limit; */ char buf[512]; char real_ip[132]; int i; time_t current_time; current_time = time (NULL); if (what == 0) { if (serv->ctcp_last_time == 0) /*first ctcp in this server */ { serv->ctcp_last_time = time (NULL); serv->ctcp_counter++; } else { if (difftime (current_time, serv->ctcp_last_time) < prefs.ctcp_time_limit) /*if we got the ctcp in the seconds limit */ { serv->ctcp_counter++; if (serv->ctcp_counter == prefs.ctcp_number_limit) /*if we reached the maximun numbers of ctcp in the seconds limits */ { serv->ctcp_last_time = current_time; /*we got the flood, restore all the vars for next one */ serv->ctcp_counter = 0; for (i = 0; i < 128; i++) if (ip[i] == '@') break; snprintf (real_ip, sizeof (real_ip), "*!*%s", &ip[i]); /*ignore_add (char *mask, int priv, int noti, int chan, int ctcp, int invi, int unignore, int no_save) */ snprintf (buf, sizeof (buf), _("You are being CTCP flooded from %s, ignoring %s\n"), nick, real_ip); PrintText (sess, buf); /*FIXME: only ignore ctcp or all?, its ignoring ctcps for now */ ignore_add (real_ip, IG_CTCP); return 0; } } } } else { if (serv->msg_last_time == 0) { serv->msg_last_time = time (NULL); serv->ctcp_counter++; } else { if (difftime (current_time, serv->msg_last_time) < prefs.msg_time_limit) { serv->msg_counter++; if (serv->msg_counter == prefs.msg_number_limit) /*if we reached the maximun numbers of ctcp in the seconds limits */ { snprintf (buf, sizeof (buf), _("You are being MSG flooded from %s, setting gui_auto_open_dialog OFF.\n"), ip); PrintText (sess, buf); serv->msg_last_time = current_time; /*we got the flood, restore all the vars for next one */ serv->msg_counter = 0; /*ignore_add (char *mask, int priv, int noti, int chan, int ctcp, int invi, int unignore, int no_save) */ if (prefs.autodialog) { /*FIXME: only ignore ctcp or all?, its ignoring ctcps for now */ prefs.autodialog = 0; /* turn it back on in 30 secs */ fe_timeout_add (30000, flood_autodialog_timeout, NULL); } return 0; } } } } return 1; }