perl.c

来自「Linux下的多协议即时通讯程序源代码」· C语言 代码 · 共 650 行 · 第 1/2 页

C
650
字号
			                    strlen("summary"), 0)))				info->summary = g_strdup(SvPV(*key, len));			if ((key = hv_fetch(plugin_info, "description",			                    strlen("description"), 0)))				info->description = g_strdup(SvPV(*key, len));			if ((key = hv_fetch(plugin_info, "version",			                    strlen("version"), 0)))				info->version = g_strdup(SvPV(*key, len));			/* We know this one exists. */			key = hv_fetch(plugin_info, "load", strlen("load"), 0);			gps->load_sub = g_strdup_printf("%s::%s", gps->package,			                                SvPV(*key, len));			if ((key = hv_fetch(plugin_info, "unload",			                    strlen("unload"), 0)))				gps->unload_sub = g_strdup_printf("%s::%s",				                                  gps->package,				                                  SvPV(*key, len));			if ((key = hv_fetch(plugin_info, "id",			                    strlen("id"), 0))) {				g_free(info->id);				info->id = g_strdup_printf("perl-%s",				                           SvPV(*key, len));			}		/********************************************************/		/* Only one of the next two options should be present   */		/*                                                      */		/* prefs_info - Uses non-GUI (read GTK) purple API calls  */		/*              and creates a PurplePluginPrefInfo type.  */		/*                                                      */		/* gtk_prefs_info - Requires gtk2-perl be installed by  */		/*                  the user and he must create a       */		/*                  GtkWidget the user and he must      */		/*                  create a GtkWidget representing the */		/*                  plugin preferences page.            */		/********************************************************/			if ((key = hv_fetch(plugin_info, "prefs_info",			                    strlen("prefs_info"), 0))) {				/* key now is the name of the Perl sub that				 * will create a frame for us */				gps->prefs_sub = g_strdup_printf("%s::%s",				                                 gps->package,				                                 SvPV(*key, len));				info->prefs_info = &ui_info;			}#ifdef PURPLE_GTKPERL			if ((key = hv_fetch(plugin_info, "gtk_prefs_info",			                    strlen("gtk_prefs_info"), 0))) {				/* key now is the name of the Perl sub that				 * will create a frame for us */				gps->gtk_prefs_sub = g_strdup_printf("%s::%s",				                                     gps->package,				                                     SvPV(*key, len));				info->ui_info = &gtk_ui_info;			}#endif			if ((key = hv_fetch(plugin_info, "plugin_action_sub",			                    strlen("plugin_action_sub"), 0))) {				gps->plugin_action_sub = g_strdup_printf("%s::%s",				                                         gps->package,				                                         SvPV(*key, len));				info->actions = purple_perl_plugin_actions;			}			plugin->info = info;			info->extra_info = gps;			status = purple_plugin_register(plugin);		}	}	PL_perl_destruct_level = 1;	PERL_SET_CONTEXT(prober);	perl_destruct(prober);	perl_free(prober);	return status;}static gbooleanload_perl_plugin(PurplePlugin *plugin){	PurplePerlScript *gps = (PurplePerlScript *)plugin->info->extra_info;	char *atmp[3] = { plugin->path, NULL, NULL };	if (gps == NULL || gps->load_sub == NULL)		return FALSE;	purple_debug(PURPLE_DEBUG_INFO, "perl", "Loading perl script\n");	if (my_perl == NULL)		perl_init();	plugin->handle = gps;	atmp[1] = gps->package;	PERL_SET_CONTEXT(my_perl);	execute_perl("Purple::PerlLoader::load_n_eval", 2, atmp);	{		dSP;		PERL_SET_CONTEXT(my_perl);		SPAGAIN;		ENTER;		SAVETMPS;		PUSHMARK(sp);		XPUSHs(sv_2mortal(purple_perl_bless_object(plugin,		                                         "Purple::Plugin")));		PUTBACK;		perl_call_pv(gps->load_sub, G_EVAL | G_SCALAR);		SPAGAIN;		if (SvTRUE(ERRSV)) {			STRLEN len;			purple_debug(PURPLE_DEBUG_ERROR, "perl",			           "Perl function %s exited abnormally: %s\n",			           gps->load_sub, SvPV(ERRSV, len));		}		PUTBACK;		FREETMPS;		LEAVE;	}	return TRUE;}static voiddestroy_package(const char *package){	dSP;	PERL_SET_CONTEXT(my_perl);	SPAGAIN;	ENTER;	SAVETMPS;	PUSHMARK(SP);	XPUSHs(sv_2mortal(newSVpv(package, strlen(package))));	PUTBACK;	perl_call_pv("Purple::PerlLoader::destroy_package",	             G_VOID | G_EVAL | G_DISCARD);	SPAGAIN;	PUTBACK;	FREETMPS;	LEAVE;}static gbooleanunload_perl_plugin(PurplePlugin *plugin){	PurplePerlScript *gps = (PurplePerlScript *)plugin->info->extra_info;	if (gps == NULL)		return FALSE;	purple_debug(PURPLE_DEBUG_INFO, "perl", "Unloading perl script\n");	if (gps->unload_sub != NULL) {		dSP;		PERL_SET_CONTEXT(my_perl);		SPAGAIN;		ENTER;		SAVETMPS;		PUSHMARK(sp);		XPUSHs(sv_2mortal(purple_perl_bless_object(plugin,		                                         "Purple::Plugin")));		PUTBACK;		perl_call_pv(gps->unload_sub, G_EVAL | G_SCALAR);		SPAGAIN;		if (SvTRUE(ERRSV)) {			STRLEN len;			purple_debug(PURPLE_DEBUG_ERROR, "perl",			           "Perl function %s exited abnormally: %s\n",			           gps->load_sub, SvPV(ERRSV, len));		}		PUTBACK;		FREETMPS;		LEAVE;	}	purple_perl_cmd_clear_for_plugin(plugin);	purple_perl_signal_clear_for_plugin(plugin);	purple_perl_timeout_clear_for_plugin(plugin);	destroy_package(gps->package);	return TRUE;}static voiddestroy_perl_plugin(PurplePlugin *plugin){	if (plugin->info != NULL) {		PurplePerlScript *gps;		g_free(plugin->info->name);		g_free(plugin->info->version);		g_free(plugin->info->summary);		g_free(plugin->info->description);		g_free(plugin->info->author);		g_free(plugin->info->homepage);		gps = (PurplePerlScript *)plugin->info->extra_info;		if (gps != NULL) {			g_free(gps->load_sub);			g_free(gps->unload_sub);			g_free(gps->package);			g_free(gps->prefs_sub);#ifdef PURPLE_GTKPERL			g_free(gps->gtk_prefs_sub);#endif			g_free(gps);			plugin->info->extra_info = NULL;		}	}}static gbooleanplugin_load(PurplePlugin *plugin){	return TRUE;}static gbooleanplugin_unload(PurplePlugin *plugin){	perl_end();	return TRUE;}static PurplePluginLoaderInfo loader_info ={	NULL,                                             /**< exts           */	probe_perl_plugin,                                /**< probe          */	load_perl_plugin,                                 /**< load           */	unload_perl_plugin,                               /**< unload         */	destroy_perl_plugin,                              /**< destroy        */		/* padding */	NULL,	NULL,	NULL,	NULL};static PurplePluginInfo info ={	PURPLE_PLUGIN_MAGIC,	PURPLE_MAJOR_VERSION,	PURPLE_MINOR_VERSION,	PURPLE_PLUGIN_LOADER,                             /**< type           */	NULL,                                             /**< ui_requirement */	0,                                                /**< flags          */	NULL,                                             /**< dependencies   */	PURPLE_PRIORITY_DEFAULT,                          /**< priority       */	PERL_PLUGIN_ID,                                   /**< id             */	N_("Perl Plugin Loader"),                         /**< name           */	VERSION,                                          /**< version        */	N_("Provides support for loading perl plugins."), /**< summary        */	N_("Provides support for loading perl plugins."), /**< description    */	"Christian Hammond <chipx86@gnupdate.org>",       /**< author         */	PURPLE_WEBSITE,                                   /**< homepage       */	plugin_load,                                      /**< load           */	plugin_unload,                                    /**< unload         */	NULL,                                             /**< destroy        */	NULL,                                             /**< ui_info        */	&loader_info,                                     /**< extra_info     */	NULL,	NULL,	/* padding */	NULL,	NULL,	NULL,	NULL};static voidinit_plugin(PurplePlugin *plugin){	loader_info.exts = g_list_append(loader_info.exts, "pl");}#ifdef __SUNPRO_C#pragma init (my_init)#elsevoid __attribute__ ((constructor)) my_init(void);#endifvoidmy_init(void){	/* Mostly evil hack... puts perl.so's symbols in the global table but	 * does not create a circular dependency because g_module_open will	 * only open the library once. */	/* Do we need to keep track of the returned GModule here so that we	 * can g_module_close it when this plugin gets unloaded?	 * At the moment I don't think this plugin can ever get unloaded but	 * in case that becomes possible this wants to get noted. */	g_module_open("perl.so", 0);}PURPLE_INIT_PLUGIN(perl, init_plugin, info)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?