/* dbus-plugin.c - xchat plugin for remote access using D-Bus * Copyright (C) 2006 Claessens Xavier * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * * Claessens Xavier * xclaesse@gmail.com */ #define DBUS_API_SUBJECT_TO_CHANGE #include #include #include #include #include "../xchat-plugin.h" #define PNAME _("remote access") #define PDESC _("plugin for remote access using DBUS") #define PVERSION "" #define DBUS_SERVICE "org.hexchat.service" #define DBUS_OBJECT_PATH "/org/hexchat" static xchat_plugin *ph; static guint last_context_id = 0; static GList *contexts = NULL; static GHashTable *clients = NULL; static DBusGConnection *connection; typedef struct RemoteObject RemoteObject; typedef struct RemoteObjectClass RemoteObjectClass; GType Remote_object_get_type (void); struct RemoteObject { GObject parent; guint last_hook_id; guint last_list_id; xchat_context *context; char *dbus_path; char *filename; GHashTable *hooks; GHashTable *lists; void *handle; }; struct RemoteObjectClass { GObjectClass parent; }; typedef struct { guint id; int return_value; xchat_hook *hook; RemoteObject *obj; } HookInfo; typedef struct { guint id; xchat_context *context; } ContextInfo; enum { SERVER_SIGNAL, COMMAND_SIGNAL, PRINT_SIGNAL, UNLOAD_SIGNAL, LAST_SIGNAL }; static guint signals[LAST_SIGNAL] = { 0 }; #define REMOTE_TYPE_OBJECT (remote_object_get_type ()) #define REMOTE_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), REMOTE_TYPE_OBJECT, RemoteObject)) #define REMOTE_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), REMOTE_TYPE_OBJECT, RemoteObjectClass)) #define REMOTE_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), REMOTE_TYPE_OBJECT)) #define REMOTE_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), REMOTE_TYPE_OBJECT)) #define REMOTE_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), REMOTE_TYPE_OBJECT, RemoteObjectClass)) #define REMOTE_OBJECT_ERROR (remote_object_error_quark ()) #define REMOTE_TYPE_ERROR (remote_object_error_get_type ()) G_DEFINE_TYPE (RemoteObject, remote_object, G_TYPE_OBJECT) /* Available services */ static gboolean remote_object_connect (RemoteObject *obj, const char *filename, const char *name, const char *desc, const char *version, DBusGMethodInvocation *context); static gboolean remote_object_disconnect (RemoteObject *obj, DBusGMethodInvocation *context); static gboolean remote_object_command (RemoteObject *obj, const char *command, GError **error); static gboolean remote_object_print (RemoteObject *obj, const char *text, GError **error); static gboolean remote_object_find_context (RemoteObject *obj, const char *server, const char *channel, guint *ret_id, GError **error); static gboolean remote_object_get_context (RemoteObject *obj, guint *ret_id, GError **error); static gboolean remote_object_set_context (RemoteObject *obj, guint id, gboolean *ret, GError **error); static gboolean remote_object_print (RemoteObject *obj, const char *text, GError **error); static gboolean remote_object_get_info (RemoteObject *obj, const char *id, char **ret_info, GError **error); static gboolean remote_object_get_prefs (RemoteObject *obj, const char *name, int *ret_type, char **ret_str, int *ret_int, GError **error); static gboolean remote_object_hook_command (RemoteObject *obj, const char *name, int pri, const char *help_text, int return_value, guint *ret_id, GError **error); static gboolean remote_object_hook_server (RemoteObject *obj, const char *name, int pri, int return_value, guint *ret_id, GError **error); static gboolean remote_object_hook_print (RemoteObject *obj, const char *name, int pri, int return_value, guint *ret_id, GError **error); static gboolean remote_object_unhook (RemoteObject *obj, guint id, GError **error); static gboolean remote_object_list_get (RemoteObject *obj, const char *name, guint *ret_id, GError **error); static gboolean remote_object_list_next (RemoteObject *obj, guint id, gboolean *ret, GError **error); static gboolean remote_object_list_str (RemoteObject *obj, guint id, const char *name, char **ret_str, GError **error); static gboolean remote_object_list_int (RemoteObject *obj, guint id, const char *name, int *ret_int, GError **error); static gboolean remote_object_list_time (RemoteObject *obj, guint id, const char *name, guint64 *ret_time, GError **error); static gboolean remote_object_list_fields (RemoteObject *obj, const char *name, char ***ret, GError **error); static gboolean remote_object_list_free (RemoteObject *obj, guint id, GError **error); static gboolean remote_object_emit_print (RemoteObject *obj, const char *event_name, const char *args[], gboolean *ret, GError **error); static gboolean remote_object_nickcmp (RemoteObject *obj, const char *nick1, const char *nick2, int *ret, GError **error); static gboolean remote_object_strip (RemoteObject *obj, const char *str, int len, int flag, char **ret_str, GError **error); static gboolean remote_object_send_modes (RemoteObject *obj, const char *targets[], int modes_per_line, char sign, char mode, GError **error); #include "remote-object-glue.h" #include "marshallers.h" /* Useful functions */ static char** build_list (char *word[]); static guint context_list_find_id (xchat_context *context); static xchat_context* context_list_find_context (guint id); /* Remote Object */ static void hook_info_destroy (gpointer data) { HookInfo *info = (HookInfo*)data; if (info == NULL) { return; } xchat_unhook (ph, info->hook); g_free (info); } static void list_info_destroy (gpointer data) { xchat_list_free (ph, (xchat_list*)data); } static void remote_object_finalize (GObject *obj) { RemoteObject *self = (RemoteObject*)obj; g_hash_table_destroy (self->lists); g_hash_table_destroy (self->hooks); g_free (self->dbus_path); g_free (self->filename); xchat_plugingui_remove (ph, self->handle); G_OBJECT_CLASS (remote_object_parent_class)->finalize (obj); } static void remote_object_init (RemoteObject *obj) { obj->hooks = g_hash_table_new_full (g_int_hash, g_int_equal, NULL, hook_info_destroy); obj->lists = g_hash_table_new_full (g_int_hash, g_int_equal, g_free, list_info_destroy); obj->dbus_path = NULL; obj->filename = NULL; obj->last_hook_id = 0; obj->last_list_id = 0; obj->context = xchat_get_context (ph); } static void remote_object_class_init (RemoteObjectClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = remote_object_finalize; signals[SERVER_SIGNAL] = g_signal_new ("server_signal", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__POINTER_POINTER_UINT_UINT, G_TYPE_NONE, 4, G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT); signals[COMMAND_SIGNAL] = g_signal_new ("command_signal", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__POINTER_POINTER_UINT_UINT, G_TYPE_NONE, 4, G_TYPE_STRV, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT); signals[PRINT_SIGNAL] = g_signal_new ("print_signal", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_VOID__POINTER_POINTER_UINT_UINT, G_TYPE_NONE, 3, G_TYPE_STRV, G_TYPE_UINT, G_TYPE_UINT); signals[UNLOAD_SIGNAL] = g_signal_new ("unload_signal", G_OBJECT_CLASS_TYPE (klass), G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); } /* Implementation of services */ static gboolean remote_object_connect (RemoteObject *obj, const char *filename, const char *name, const char *desc, const char *version, DBusGMethodInvocation *context) { static guint count = 0; char *sender, *path; RemoteObject *remote_object; sender = dbus_g_method_get_sender (context); remote_object = g_hash_table_lookup (clients, sender); if (remote_object != NULL) { dbus_g_method_return (context, remote_object->dbus_path); g_free (sender); return TRUE; } path = g_strdup_printf (DBUS_OBJECT_PATH"/%d", count++); remote_object = g_object_new (REMOTE_TYPE_OBJECT, NULL); remote_object->dbus_path = path; remote_object->filename = g_path_get_basename (filename); remote_object->handle = xchat_plugingui_add (ph, remote_object->filename, name, desc, version, NULL); dbus_g_connection_register_g_object (connection, path, G_OBJECT (remote_object)); g_hash_table_insert (clients, sender, remote_object); dbus_g_method_return (context, path); return TRUE; } static gboolean remote_object_disconnect (RemoteObject *obj, DBusGMethodInvocation *context) { char *sender; sender = dbus_g_method_get_sender (context); g_hash_table_remove (clients, sender); g_free (sender); dbus_g_method_return (context); return TRUE; } static gboolean remote_object_command (RemoteObject *obj, const char *command, GError **error) { if (xchat_set_context (ph, obj->context)) { xchat_command (ph, command); } return TRUE; } static gboolean remote_object_print (RemoteObject *obj, const char *text, GError **error) { if (xchat_set_context (ph, obj->context)) { xchat_print (ph, text); } return TRUE; } static gboolean remote_object_find_context (RemoteObject *obj, const char *server, const char *channel, guint *ret_id, GError **error) { xchat_context *context; if (*server == '\0') { server = NULL; } if (*channel == '\0') { channel = NULL; } context = xchat_find_context (ph, server, channel); *ret_id = context_list_find_id (contex
// Machine generated IDispatch wrapper class(es) created by Microsoft Visual C++

// NOTE: Do not modify the contents of this file.  If this class is regenerated by
//  Microsoft Visual C++, your modifications will be overwritten.


#include "stdafx.h"
#include "wmpsettings.h"


/////////////////////////////////////////////////////////////////////////////
// CWMPSettings properties

/////////////////////////////////////////////////////////////////////////////
// CWMPSettings operations

BOOL CWMPSettings::GetIsAvailable(LPCTSTR bstrItem)
{
	BOOL result;
	static BYTE parms[] =
		VTS_BSTR;
	InvokeHelper(0x71, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, parms,
		bstrItem);
	return result;
}

BOOL CWMPSettings::GetAutoStart()
{
	BOOL result;
	InvokeHelper(0x65, DISPATCH_PROPERTYGET, VT_BOOL, (void*)&result, NULL);
	return result;
}

void CWMPSettings::SetAutoStart(BOOL bNewValue)
{
	static BYTE parms[] =
		VTS_BOOL;
	InvokeHelper(0x65, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
		 bNewValue);
}

CString CWMPSettings::GetBaseURL()
{
	CString result;
	InvokeHelper(0x6c, DISPATCH_PROPERTYGET, VT_BSTR, (void*)&result, NULL);
	return result;
}

void CWMPSettings::SetBaseURL(LPCTSTR lpszNewValue)
{
	static BYTE parms[] =
		VTS_BSTR;
	InvokeHelper(0x6c, DISPATCH_PROPERTYPUT, VT_EMPTY, NULL, parms,
		 lpszNewValue);
}

CString CWMPSettings::GetDefaultFrame()
{
	CString result;
	InvokeHelper(0x6d, DISPATCH_PROPERTYGET,