Esempio n. 1
0
/* 
 * lua:  func_name(data)
 * desc: the callback function for the registered timer hook, return
 *       true to keep this timer going, false to stop it
 * ret:  none
 * args: 
 *       * data (table): the table you gave the hook_timer() as last
 *           argument
 */
 static int lxc_run_timer(void *data)
{
	int ret;
	struct lxc_cbdata *cb = data;
	xchat_hook *hook      = cb->hook;
	lua_State *L          = cb->state;

	lua_pushstring(L, cb->func);
	lua_gettable(L, LUA_GLOBALSINDEX);

	if (lua_pcall(L, 0, 1, 0)) {
		xchat_printf(ph, "failed to call timer callback for '%s': %s", 
			cb->func, lua_tostring(L, -1));
		lua_pop(L, 1);
		lxc_unhook_timer(L, hook);
		return 0;
	}

	if (lua_type(L, -1) != LUA_TBOOLEAN) {
		xchat_printf(ph, 
			"timer callback for '%s' didn't return a boolean", cb->func);
		lua_pop(L, 1);
		lxc_unhook_timer(L, hook);
		return 0;
	}

	ret = (lua_toboolean(L, -1) == 0) ? 0 : 1;
	lua_pop(L, 1);

	if (ret == 0)
		lxc_unhook_timer(L, hook);

	return ret;
}
Esempio n. 2
0
/*
 * lua:  func_name(word, data)
 * desc: your previously hooked callback function for hook_print(), 
 *       you must return one of the xchat.EAT_* constants
 * ret:  none
 * args: 
 *       * word (table): the incoming line split into words (max 32)
 *         (see http://xchat.org/docs/plugin20.html#word)
 *       * data (table): the data table you passed to the hook_print() /
 *         as 4th arg
 */
static int lxc_run_print(char *word[], void *data)
{
	struct lxc_cbdata *cb = data;
	lua_State *L          = cb->state;
	int i;

	lua_pushstring(L, cb->func);
	lua_gettable(L, LUA_GLOBALSINDEX);

	strcpy(lxc_event_name, word[0]);
	lua_newtable(L);
	for (i=1; i<=31 && word[i][0]; i++) {
		lua_pushnumber(L, i);
		lua_pushstring(L, word[i]);
		lua_settable(L, -3);
	}

	if (lua_pcall(L, 1, 1, 0)) {
		xchat_printf(ph, "failed to call callback for '%s': %s", 
			word[1], lua_tostring(L, -1));
		lua_pop(L, 1);
		return 0;
	}

	if (lua_type(L, -1) != LUA_TNUMBER) {
		xchat_printf(ph, "callback for '%s' didn't return number...", word[1]);
		return XCHAT_EAT_NONE;
	}
	i = (int)lua_tonumber(L, -1);
	lua_pop(L, 1);
	return i;
}
Esempio n. 3
0
static int lxc_cb_lua(char *word[], char *word_eol[], void *userdata)
{
	lua_State *L = lxc_new_state();
	if (word[2][0] == '\0') {
		xchat_printf(ph, "LUA: Usage: /LUA LUA_CODE... execute LUA_CODE");
		return XCHAT_EAT_ALL;
	}
	if (luaL_loadbuffer(L, word_eol[2], strlen(word_eol[2]), "/LUA")) {
		xchat_printf(ph, "LUA: error loading line %s", lua_tostring(L, -1));
		lua_pop(L, 1);
	}

#define LXC_HOOK_DISABLE "xchat.hook_command = nil\n" \
								 "xchat.hook_server  = nil\n" \
								 "xchat.hook_print   = nil\n" \
								 "xchat.hook_timer   = nil\n"

#if defined(LUA_VERSION_NUM) && (LUA_VERSION_NUM >= 501)
	(void)luaL_dostring(L, LXC_HOOK_DISABLE);
#else
	lua_dostring(L, LXC_HOOK_DISABLE);
#endif

	if (lua_pcall(L, 0, 0, 0)) {
		xchat_printf(ph, "LUA: error executing line %s", lua_tostring(L, -1));
		lua_pop(L, 1);
	}

	lua_close(L);
	return XCHAT_EAT_ALL;
}
Esempio n. 4
0
/*
  this is used for autoload and shutdown callbacks
*/
static int
execute_perl (SV * function, char *args)
{

	int count, ret_value = 1;

	dSP;
	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (sv_2mortal (newSVpv (args, 0)));
	PUTBACK;

	count = call_sv (function, G_EVAL | G_SCALAR);
	SPAGAIN;
	if (SvTRUE (ERRSV)) {
		xchat_printf(ph, "Perl error: %s\n", SvPV_nolen (ERRSV));
		if (!SvOK (POPs)) {}		/* remove undef from the top of the stack */
	} else if (count != 1) {
		xchat_printf (ph, "Perl error: expected 1 value from %s, "
						  "got: %d\n", SvPV_nolen (function), count);
	} else {
		ret_value = POPi;
	}
	PUTBACK;
	FREETMPS;
	LEAVE;

	return ret_value;
}
Esempio n. 5
0
static int
dccoffer_cb (char *word[], void *userdata)
{
	int result;
	struct stat64 buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat64 (word[3], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[3], sum);						/* word[3] is the full filename */
			xchat_commandf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): %s", word[2], word[1], sum);
		}
		else
		{
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): (size limit reached, no checksum calculated)", word[2], word[1]);
		}
	}
	else
	{
		xchat_printf (ph, "File access error!\n");
	}

	return XCHAT_EAT_NONE;
}
Esempio n. 6
0
static int
dccrecv_cb (char *word[], void *userdata)
{
	int result;
	struct stat64 buffer;									/* buffer for storing file info */
	char sum[65];											/* buffer for checksum */

	result = stat64 (word[2], &buffer);
	if (result == 0)										/* stat returns 0 on success */
	{
		if (buffer.st_size <= (unsigned long long) get_limit () * 1048576)
		{
			sha256_file (word[2], sum);						/* word[2] is the full filename */
			/* try to print the checksum in the privmsg tab of the sender */
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "SHA-256 checksum for %s (local):  %s\n", word[1], sum);
		}
		else
		{
			xchat_set_context (ph, xchat_find_context (ph, NULL, word[3]));
			xchat_printf (ph, "SHA-256 checksum for %s (local):  (size limit reached, no checksum calculated, you can increase it with /CHECKSUM INC)\n", word[1]);
		}
	}
	else
	{
		xchat_printf (ph, "File access error!\n");
	}

	return XCHAT_EAT_NONE;
}
Esempio n. 7
0
int xchat_plugin_deinit(xchat_plugin *plug_handle) 
{
	struct lxc_States *state, *st;

	state = lxc_states;
	while (state) {
		lxc_unload_script(state);
		xchat_printf(ph, "Lua script %s unloaded", state->file);
		st    = state;
		state = state->next;
		free(st);
	}
	xchat_printf(plug_handle, "Lua interface unloaded");
	return 1;
}
Esempio n. 8
0
int
xchat_plugin_init (struct xchat_plugin *plugin_handle, char **plugin_name,
	char **plugin_desc, char **plugin_version, char *arg)
{
    if (!_xchat_plugin_init)
	{
		xchat_printf (plugin_handle, 
			"Error loading OS specific plugin library: %s - ", _real_plugin, _dlerror);
		return 0;
	}

	xchat_printf(plugin_handle, "OS Specific plugin loaded: %s\n", _real_plugin);
	
    return _xchat_plugin_init (plugin_handle, plugin_name, plugin_desc, plugin_version, arg);
}
Esempio n. 9
0
int
xchat_plugin_deinit (void)
{
	xchat_command (ph, "MENU DEL \"Window/Display System Info\"");
	xchat_printf (ph, "%s plugin unloaded\n", name);
	return 1;
}
Esempio n. 10
0
File: sasl.c Progetto: PChat/PChat
int
xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
	/* we need to save this for use with any xchat_* functions */
	ph = plugin_handle;

	/* tell xchat our info */
	*plugin_name = name;
	*plugin_desc = desc;
	*plugin_version = version;

	xchat_hook_command (ph, "SASL", XCHAT_PRI_NORM, sasl_cmd_cb, sasl_help, 0);
	xchat_hook_print (ph, "Connected", XCHAT_PRI_NORM, connect_cb, NULL);
	/* xchat_hook_print (ph, "Disconnected", XCHAT_PRI_NORM, disconnect_cb, NULL); */
	xchat_hook_server (ph, "CAP", XCHAT_PRI_NORM, cap_cb, NULL);
	xchat_hook_server (ph, "RAW LINE", XCHAT_PRI_NORM, server_cb, NULL);
	xchat_hook_server (ph, "903", XCHAT_PRI_NORM, authend_cb, NULL);
	xchat_hook_server (ph, "904", XCHAT_PRI_NORM, authend_cb, NULL);
	xchat_hook_server (ph, "905", XCHAT_PRI_NORM, authend_cb, NULL);
	xchat_hook_server (ph, "906", XCHAT_PRI_NORM, authend_cb, NULL);
	xchat_hook_server (ph, "907", XCHAT_PRI_NORM, authend_cb, NULL);

	xchat_printf (ph, "%s plugin loaded\n", name);

	return 1;
}
Esempio n. 11
0
static void
lxc_autoload_from_path(const char *path)
{
	DIR *dir;
	struct dirent *ent;
	char *file;
	int len;
	/* xchat_printf(ph, "loading from %s\n", path); */
	dir = opendir(path);
	if (dir) {
		while ((ent = readdir(dir))) {
			len = strlen(ent->d_name);
			if (len > 4 && strcasecmp(".lua", ent->d_name + len - 4) == 0) {
				file = malloc(len + strlen(path) + 2);
				if (file == NULL) {
					xchat_printf(ph, "lxc_autoload_from_path(): malloc failed: %s",
						strerror(errno));
					break;
				}
				sprintf(file, "%s/%s", path, ent->d_name);
				(void)lxc_load_file((const char *)file);
				free(file);
			}
		}
		closedir(dir);
	}
}
Esempio n. 12
0
void ScriptData::RunVM( bool reset )
{
   if ( reset )
   {
      // restart from beginning of the program
      if ( m_vm->mainModule()->module()->findGlobalSymbol( "__main__" ) == 0 )
      {
         Falcon::AutoCString name( m_module->name() );
         xchat_printf( the_plugin, PNAME ": the module %s has no main routine and cannot be launched\n",
            name.c_str() );
         return;
      }
      
      m_vm->launch();
   }
   else
      m_vm->run();

   // in case of error, the callers must catch us.

   if ( ! isSleeping() )
   {
      // if had not a sleep request...
      // ...and If the modue has not registered any hook, unload it.
      if( m_hooks->length() == 0 )
      {
         UnloadModule( this );
      }
   }

   // else everything went fine.
}
Esempio n. 13
0
static void
checksum (char *word[], void *userdata)
{
	if (!g_ascii_strcasecmp ("GET", word[2]))
	{
		print_limit ();
	}
	else if (!g_ascii_strcasecmp ("SET", word[2]))
	{
		set_limit (word[3]);
	}
	else
	{
		xchat_printf (ph, "Usage: /CHECKSUM GET|INC|DEC\n");
		xchat_printf (ph, "  GET - print the maximum file size (in MiB) to be hashed\n");
		xchat_printf (ph, "  SET <filesize> - set the maximum file size (in MiB) to be hashed\n");
	}
}
Esempio n. 14
0
static int
fd_cb (int fd, int flags, void *userdata)
{
	HookData *data = (HookData *) userdata;
	int retVal = 0;
	int count = 0;

	dSP;
	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (data->userdata);
	PUTBACK;

	set_current_package (data->package);
	count = call_sv (data->callback, G_EVAL);
	set_current_package (&PL_sv_undef);
	SPAGAIN;

	if (SvTRUE (ERRSV)) {
		xchat_printf (ph, "Error in fd callback %s", SvPV_nolen (ERRSV));
		if (!SvOK (POPs)) {}		  /* remove undef from the top of the stack */
		retVal = XCHAT_EAT_ALL;
	} else {
		if (count != 1) {
			xchat_print (ph, "Fd handler should only return 1 value.");
			retVal = XCHAT_EAT_NONE;
		} else {
			retVal = POPi;
			if (retVal == 0) {
				/* if 0 is returned, the fd is going to get unhooked */
				PUSHMARK (SP);
				XPUSHs (sv_2mortal (newSViv (PTR2IV (data->hook))));
				PUTBACK;

				call_pv ("Xchat::unhook", G_EVAL);
				SPAGAIN;

				SvREFCNT_dec (data->callback);

				if (data->userdata) {
					SvREFCNT_dec (data->userdata);
				}
				free (data);
			}
		}

	}

	PUTBACK;
	FREETMPS;
	LEAVE;

	return retVal;
}
Esempio n. 15
0
File: sasl.c Progetto: PChat/PChat
static int
connect_cb (char *word[], void *userdata)
{
	if (get_info ())
	{
		xchat_printf (ph, "%s\tSASL enabled\n", name);
		xchat_commandf (ph, "QUOTE CAP REQ :sasl");
	}

	return XCHAT_EAT_NONE;
}
Esempio n. 16
0
static int
timer_cb (void *userdata)
{
	HookData *data = (HookData *) userdata;
	int retVal = 0;
	int count = 0;

	dSP;
	ENTER;
	SAVETMPS;

	PUSHMARK (SP);
	XPUSHs (data->userdata);
	PUTBACK;

	if (data->ctx) {
		xchat_set_context (ph, data->ctx);
	}

	set_current_package (data->package);
	count = call_sv (data->callback, G_EVAL | G_KEEPERR);
	set_current_package (&PL_sv_undef);
	SPAGAIN;

	if (SvTRUE (ERRSV)) {
		xchat_printf (ph, "Error in timer callback %s", SvPV_nolen (ERRSV));
		if (!SvOK (POPs)) {}		  /* remove undef from the top of the stack */
		retVal = XCHAT_EAT_ALL;
	} else {
		if (count != 1) {
			xchat_print (ph, "Timer handler should only return 1 value.");
			retVal = XCHAT_EAT_NONE;
		} else {
			retVal = POPi;
			if (retVal == 0) {
				/* if 0 is return the timer is going to get unhooked */
				PUSHMARK (SP);
				XPUSHs (sv_2mortal (newSViv (PTR2IV (data->hook))));
				XPUSHs (sv_mortalcopy (data->package));
				PUTBACK;

				call_pv ("XChat::unhook", G_EVAL);
				SPAGAIN;
			}
		}

	}

	PUTBACK;
	FREETMPS;
	LEAVE;

	return retVal;
}
Esempio n. 17
0
File: sasl.c Progetto: PChat/PChat
static int
authend_cb (char *word[], char *word_eol[], void *userdata)
{
	if (get_info ())
	{
		/* omit cryptic server message parts */
		xchat_printf (ph, "%s\t%s\n", name, ++word_eol[4]);
		xchat_commandf (ph, "QUOTE CAP END");
	}

	return XCHAT_EAT_ALL;
}
Esempio n. 18
0
static void
set_limit (char* size)
{
	int buffer = atoi (size);

	if (buffer > 0 && buffer < INT_MAX)
	{
		if (xchat_pluginpref_set_int (ph, "limit", buffer))
		{
			xchat_printf (ph, "File size limit has successfully been set to: %d MiB\n", buffer);
		}
		else
		{
			xchat_printf (ph, "File access error while saving!\n");
		}
	}
	else
	{
		xchat_printf (ph, "Invalid input!\n");
	}
}
Esempio n. 19
0
static int
lxc_load_file(const char *script)
{
	lua_State *L;
	struct lxc_States *state;  /* pointer to lua states list */
	struct lxc_States *st;  /* pointer to lua states list */

	L = lxc_new_state();
	state = malloc(sizeof(struct lxc_States));
	if (state == NULL) {
		xchat_printf(ph, "malloc() failed: %s\n", strerror(errno));
		lua_close(L);
		return 0;
	}

	state->state = L;
	snprintf(state->file, PATH_MAX, script);
	state->next  = NULL;
	state->hooks = NULL;
	state->gui   = NULL;

	if (luaL_loadfile(L, script) || lua_pcall(L, 0, 0, 0)) {
		xchat_printf(ph, "Lua plugin: error loading script %s", 	
							lua_tostring(L, -1));
		lua_close(L);
		free(state);
		return 0;
	}

	if (!lxc_states) 
		lxc_states = state;
	else {
		st = lxc_states;
		while (st->next)
			st = st->next;
		st->next = state;
	}

	return 1;
}
Esempio n. 20
0
File: sasl.c Progetto: PChat/PChat
static void
print_info ()
{
	char list[512];
	char* token;

	if (xchat_pluginpref_list (ph, list))
	{
		xchat_printf (ph, "%s\tSASL-enabled networks:", name);
		xchat_printf (ph, "%s\t----------------------", name);
		token = strtok (list, ",");
		while (token != NULL)
		{
			xchat_printf (ph, "%s\t%s", name, token);
			token = strtok (NULL, ",");
		}
	}
	else
	{
		xchat_printf (ph, "%s\tThere are no SASL-enabled networks currently", name);
	}
}
Esempio n. 21
0
int
xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
	ph = plugin_handle;

	*plugin_name = name;
	*plugin_desc = desc;
	*plugin_version = version;

	xchat_hook_command (ph, "EXEC", XCHAT_PRI_NORM, run_command, "Usage: /EXEC [-O] - execute commands inside XChat", 0);
	xchat_printf (ph, "%s plugin loaded\n", name);

	return 1;       /* return 1 for success */
}
Esempio n. 22
0
char *readLine(FILE *f){
     //if (DEBUG==1) putlog("reading line from file");
     char *buffer=(char*)calloc(1024,sizeof(char)); //malloc(sizeof(char)*1024);
     int pos=0;
     int cc=0;
     while((cc!=EOF)&&(pos<1024)&&(cc!=10)){
          cc=fgetc(f);
          if ((cc!=10)&&(cc!=13)){
             if (cc==EOF) buffer[pos]=0;
             else buffer[pos]=(char)cc;pos++;
          }
     }
     if (buffer[pos]==EOF) xchat_printf(ph,"EOF: %i\n",pos);
     return buffer;
}
Esempio n. 23
0
static int
command_cb (char *word[], char *word_eol[], void *userdata)
{
	HookData *data = (HookData *) userdata;
	int retVal = 0;
	int count = 0;

	dSP;
	ENTER;
	SAVETMPS;
	
	if (data->depth)
		return XCHAT_EAT_NONE;

	/*               xchat_printf (ph, "Recieved %d words in command callback", */
	/*                               av_len (wd)); */
	PUSHMARK (SP);
	XPUSHs (newRV_noinc ((SV *) array2av (word)));
	XPUSHs (newRV_noinc ((SV *) array2av (word_eol)));
	XPUSHs (data->userdata);
	PUTBACK;

	data->depth++;
	set_current_package (data->package);
	count = call_sv (data->callback, G_EVAL);
	set_current_package (&PL_sv_undef);
	data->depth--;
	SPAGAIN;
	if (SvTRUE (ERRSV)) {
		xchat_printf (ph, "Error in command callback %s", SvPV_nolen (ERRSV));
		if (!SvOK (POPs)) {}		  /* remove undef from the top of the stack */
		retVal = XCHAT_EAT_XCHAT;
	} else {
		if (count != 1) {
			xchat_print (ph, "Command handler should only return 1 value.");
			retVal = XCHAT_EAT_NONE;
		} else {
			retVal = POPi;
		}

	}

	PUTBACK;
	FREETMPS;
	LEAVE;

	return retVal;
}
Esempio n. 24
0
int xchat_plugin_init(xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg){
	ph = plugin_handle;
	*plugin_name = "mpcInfo";
	*plugin_desc = "Information-Script for Media Player Classic"; 
	*plugin_version=VERSION;

	xchat_hook_command(ph, "mpc", XCHAT_PRI_NORM, mpc_tell,"no help text", 0);
	xchat_hook_command(ph, "mpc_themes", XCHAT_PRI_NORM, print_themes,"no help text", 0);
	xchat_hook_command(ph, "mpc_reloadthemes", XCHAT_PRI_NORM, mpc_themeReload,"no help text", 0);
	xchat_command (ph, "MENU -ietc\\music.png ADD \"Window/Display Current Song (MPC)\" \"MPC\"");

	themeInit();
	loadThemes();
	xchat_printf(ph, "%s %s plugin loaded\n",*plugin_name, VERSION);

	return 1;
}
Esempio n. 25
0
int
xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
	ph = plugin_handle;

	*plugin_name = name;
	*plugin_desc = desc;
	*plugin_version = version;

	firstRun = 1;

	xchat_hook_command (ph, "WINSYS", XCHAT_PRI_NORM, printInfo, NULL, NULL);
	xchat_command (ph, "MENU -ietc\\system.png ADD \"Window/Display System Info\" \"WINSYS\"");

	xchat_printf (ph, "%s plugin loaded\n", name);

	return 1;       /* return 1 for success */
}
Esempio n. 26
0
int
xchat_plugin_init (xchat_plugin *plugin_handle, char **plugin_name, char **plugin_desc, char **plugin_version, char *arg)
{
	gboolean success;

	xchat_plugin_get_info (plugin_name, plugin_desc, plugin_version, NULL);

	ph = plugin_handle;

	success = init_dbus ();
	if (success) {
		xchat_hook_print (ph, "Motd",         XCHAT_PRI_NORM, connected_cb, NULL);
		xchat_hook_print (ph, "MOTD Skipped", XCHAT_PRI_NORM, connected_cb, NULL);
		
		xchat_find_set_context (ph);
		xchat_printf (ph, _("%s loaded successfully\n"), NET_MONITOR_NAME);
	}
	return success;
}
Esempio n. 27
0
static void timer_del_ref(int ref, int quiet)
{
        GSList *list;
        timer *tim;

        list = timer_list;
        while (list) {
                tim = list->data;
                if (tim->ref == ref) {
                        timer_del(tim);
                        if (!quiet)
                                xchat_printf(ph, "Timer %d deleted.\n", ref);
                        return;
                }
                list = list->next;
        }
        if (!quiet)
                xchat_print(ph, "No such ref number found.\n");
}
Esempio n. 28
0
void lxc_unload_script(struct lxc_States *state)
{
	struct lxc_hooks *hooks, *h;
	struct lxc_cbdata *cb;
	struct lxc_userdata *ud, *u;
	lua_State *L = state->state;

	lua_pushstring(L, "xchat_unload");
	lua_gettable(L, LUA_GLOBALSINDEX);
	if (lua_type(L, -1) == LUA_TFUNCTION) {
		if (lua_pcall(L, 0, 0, 0)) {
			xchat_printf(ph, "Lua plugin: error while unloading script %s", 	
								lua_tostring(L, -1));
			lua_pop(L, 1);
		}
	}

	if (state->gui)
		xchat_plugingui_remove(ph, state->gui);
	state->gui = NULL;

	hooks = state->hooks;
	while (hooks) {
		h     = hooks;
		hooks = hooks->next;

		cb    = xchat_unhook(ph, h->hook);
		if (cb) {
			ud    = cb->data;
			while (ud) {
				u  = ud;
				ud = ud->next;
				free(u);
			}
			free(cb);
		}

		free(h);
	}
	lua_close(state->state);
}
Esempio n. 29
0
static
XS (XS_Xchat_register)
{
	char *name, *version, *desc, *filename;
	void *gui_entry;
	dXSARGS;
	if (items != 4) {
		xchat_printf (ph,
						  "Usage: Xchat::Internal::register(scriptname, version, desc, filename)");
	} else {
		name = SvPV_nolen (ST (0));
		version = SvPV_nolen (ST (1));
		desc = SvPV_nolen (ST (2));
		filename = SvPV_nolen (ST (3));

		gui_entry = xchat_plugingui_add (ph, filename, name,
													desc, version, NULL);

		XSRETURN_IV (PTR2IV (gui_entry));

	}
}
Esempio n. 30
0
static int lxc_cb_unload(char *word[], char *word_eol[], void *userdata)
{
	int len;
	struct lxc_States *state;
	struct lxc_States *prev = NULL;
	char *file;

	if (word_eol[2][0] == 0)
		return XCHAT_EAT_NONE;

	len = strlen(word[2]);
	if (len > 4 && strcasecmp(".lua", word[2] + len - 4) == 0) {
		state = lxc_states;
		while (state) {
			/* 
			 * state->file is the full or relative path, always with a '/' inside,
			 * even if loaded via '/LOAD script.lua'. So strrchr() will never
			 * be NULL.
			 * ... we just inspect the script name w/o path to see if it's the 
			 * right one to unload
			 */
			file = strrchr(state->file, '/') + 1; 
			if ((strcmp(state->file, word[2]) == 0) 
					|| (strcasecmp(file, word[2]) == 0)) {
				lxc_unload_script(state);
				if (prev) 
					prev->next = state->next;
				else
					lxc_states = state->next;
				xchat_printf(ph, "Lua script %s unloaded", file);
				free(state);
				return XCHAT_EAT_ALL;
			}
			prev  = state;
			state = state->next;
		}
	}
	return XCHAT_EAT_NONE;
}