summary refs log blame commit diff stats
path: root/src/common/dbus/README
blob: d61cf4e0ee1a4283c91d1db6942f11e88ec22e9e (plain) (tree)





































































































































































































                                                                               
For more help you can see the xchat plugin interface documentation.
http://www.xchat.org/docs/plugin20.html
WARNING: The dbus interface may change in the future.

You can use the "/org/xchat/Remote" object with interface "org.xchat.plugin",
but his context can be changed by other clients at any moment and
you may receive signal asked by other clients. So for more complex usage it's
better to get your own remote object. Using "Connect" method on interface
"org.xchat.connection"

Available methods on org.xchat.connection interface:

"Connect"
  - Parameters:
    - gchar*: filename
    - gchar*: name
    - gchar*: description
    - gchar*: version
  - Returns:
    - gchar*: Your own object's path.

"Disconnect"
  No parameter, no return value. It frees your remote object.

Available methods on org.xchat.plugin interface:

"Command"
  - Parameters:
    - gchar*: the command name without the "/". (e.g. "nick pseudo")

"Print"
  - Parameters:
    - gchar*: text to print on the xchat window.

"FindContext"
  - Parameters:
    - gchar*: the server name. Can be NULL.
    - gchar*: the channel name. Can be NULL.
  - Returns:
    - guint: context ID

"GetContext"
  - Returns:
    - guint: current context's ID

"SetContext"
  - Parameters:
    - guint: context ID to switch, returned by "FindContext" or "GetContext"
  - Returns:
    - gboolean: 1 for success, 0 for failure.

"GetInfo"
  - Parameters:
    - gchar*: ID of the information you want.
  - Returns:
    - gchar*: information you requested.

"GetPrefs"
  - Parameters:
    - gchar*: Setting name required.
  - Returns:
    - int: 0-Failed 1-Returned a string 2-Returned an Integer
           3-Returned a Boolean.
    - gchar*: the information requested if it's a string.
    - int: the information requested if it's a integer or boolean.

"HookCommand"
  - Parameters:
    - gchar*: Name of the command (without the forward slash).
    - int: Priority of this command.
    - gchar*: String of text to display when the user executes /help
              for this command. May be NULL if you're lazy.
    - int: Value to returns when the command is catched. See XCHAT_EAT_*.
  - Returns:
    - guint: The ID of the hook.

"HookServer"
  - Parameters:
    - gchar*: Name of the server event.
    - int: Priority of this command.
    - int: Value to returns when the command is catched. See XCHAT_EAT_*.
  - Returns:
    - guint: The ID of the hook.

"HookPrint"
  - Parameters:
    - gchar*: Name of the print event.
    - int: Priority of this command.
    - int: Value to returns when the command is catched. See XCHAT_EAT_*.
  - Returns:
    - guint: The ID of the hook.

"Unhook"
  - Parameters:
    - guint: ID of the hook to unhook.
      (the return value of "HookCommand", "HookServer" or "HookPrint")

"ListGet"
  - Parameters:
    - gchar*: The list name.
  - Returns:
    - guint: List ID.

"ListNext"
  - Parameters:
    - guint: List ID returned by "ListGet".
  - Returns:
    - gboolean: says if there is no more item in the list.

"ListStr"
  - Parameters:
    - guint: List ID returned by "ListGet".
    - gchar*: Name of the information needed.
  - Returns:
    - gchar*: The information requested.
Warning: "context" attribut of "channels" list should be get with "ListInt"

"ListInt"
  - Parameters:
    - guint: List ID returned by "ListGet".
    - gchar*: Name of the information needed.
  - Returns:
    - guint: The information requested.

"ListTime"
  - Parameters:
    - guint: List ID returned by "ListGet".
    - gchar*: Name of the information needed.
  - Returns:
    - guint64: The information requested.

"ListFields"
  - Parameters:
    - gchar*: The list name.
  - Returns:
    - gchar**: information names in this list.

"ListFree"
  - Parameters:
    - guint: List ID returned by "ListGet".

"EmitPrint"
  - Parameters:
    - gchar*: Text event to print.
    - gchar**: NULL terminated array of string.
  - Returns:
    - gboolean: 1-Success 0-Failure.

"Nickcmp"
  - Parameters:
    - gchar*: String to compare.
    - gchar*: String to compare.
  - Returns:
    - int: An integer less than, equal to, or greater than zero if s1 is found,
           respectively, to be less than, to match, or be greater than s2. 

"Strip"
  - Parameters:
    - gchar*: String to strip.
    - int: Length of the string (or -1 for NULL terminated).
    - int: Bit-field of flags: 0-Strip mIRC colors, 1-Strip text attributes. 
  - Returns:
    - gchar*: striped string.

"SendModes"
  - Parameters:
    - gchar**: NULL terminated array of targets (strings). The names of people
               whom the action will be performed on.
    - int: Maximum modes to send per line.
    - gchar: Mode sign, '-' or '+'.
    - gchar: Mode char, e.g. 'o' for Ops.


Available signals:

"ServerSignal"
  - Parameters:
    - gchar**: word returned by xchat.
    - gchar**: word_eol returned bu xchat.
    - guint: the ID of the hook. (the return value of "HookServer").
    - guint: the ID of the context where the event come from.

"CommandSignal"
  - Parameters:
    - gchar**: word returned by xchat.
    - gchar**: word_eol returned bu xchat.
    - guint: the ID of the hook. (the return value of "HookCommand").
    - guint: the ID of the context where the event come from.

"PrintSignal"
  - Parameters:
    - gchar**: word returned by xchat.
    - guint: the ID of the hook. (the return value of "HookPrint").
    - guint: the ID of the context where the event come from.

"UnloadSignal"
  emited when the user asks to unload your program.
  Please exit(0); when received !
<password>, sets the key for a channel or nick"; static const char usage_delkey[] = "Usage: DELKEY <nick or #channel>, deletes the key for a channel or nick"; static hexchat_plugin *ph; /** * Returns the path to the key store file. */ gchar *get_config_filename() { return g_build_filename(hexchat_get_info(ph, "configdir"), "addon_fishlim.conf", NULL); } /** * Appends data to a string. Returns true if there was sufficient memory. * Frees *s and returns false if an error occurs. */ static bool append(char **s, size_t *length, const char *data) { size_t datalen = strlen(data); char *extended = realloc(*s, *length + datalen + 1); if (!extended) { free(*s); return false; } memcpy(extended + *length, data, datalen + 1); *s = extended; *length += datalen; return true; } /*static int handle_debug(char *word[], char *word_eol[], void *userdata) { hexchat_printf(ph, "debug incoming: "); for (size_t i = 1; word[i] != NULL && word[i][0] != '\0'; i++) { hexchat_printf(ph, ">%s< ", word[i]); } hexchat_printf(ph, "\n"); return HEXCHAT_EAT_NONE; }*/ /** * Called when a message is to be sent. */ static int handle_outgoing(char *word[], char *word_eol[], void *userdata) { const char *own_nick; // Encrypt the message if possible const char *channel = hexchat_get_info(ph, "channel"); char *encrypted = fish_encrypt_for_nick(channel, word_eol[1]); if (!encrypted) return HEXCHAT_EAT_NONE; // Display message own_nick = hexchat_get_info(ph, "nick"); hexchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL); // Send message hexchat_commandf(ph, "PRIVMSG %s :+OK %s", channel, encrypted); free(encrypted); return HEXCHAT_EAT_HEXCHAT; } /** * Called when a channel message or private message is received. */ static int handle_incoming(char *word[], char *word_eol[], void *userdata) { const char *prefix; const char *command; const char *recipient; const char *encrypted; const char *peice; char *sender_nick; char *decrypted; char *message; size_t w; size_t ew; size_t uw; size_t length; if (!irc_parse_message((const char **)word, &prefix, &command, &w)) return HEXCHAT_EAT_NONE; // Topic (command 332) has an extra parameter if (!strcmp(command, "332")) w++; // Look for encrypted data for (ew = w+1; ew < HEXCHAT_MAX_WORDS-1; ew++) { const char *s = (ew == w+1 ? word[ew]+1 : word[ew]); if (strcmp(s, "+OK") == 0 || strcmp(s, "mcps") == 0) goto has_encrypted_data; } return HEXCHAT_EAT_NONE; has_encrypted_data: ; // Extract sender nick and recipient nick/channel sender_nick = irc_prefix_get_nick(prefix); recipient = word[w]; // Try to decrypt with these (the keys are searched for in the key store) encrypted = word[ew+1]; decrypted = fish_decrypt_from_nick(recipient, encrypted); if (!decrypted) decrypted = fish_decrypt_from_nick(sender_nick, encrypted); // Check for error if (!decrypted) goto decrypt_error; // Build unecrypted message message = NULL; length = 0; if (!append(&message, &length, "RECV")) goto decrypt_error; for (uw = 1; uw < HEXCHAT_MAX_WORDS; uw++) { if (word[uw][0] != '\0' && !append(&message, &length, " ")) goto decrypt_error; if (uw == ew) { // Add the encrypted data peice = decrypted; uw++; // Skip "OK+" if (ew == w+1) { // Prefix with colon, which gets stripped out otherwise if (!append(&message, &length, ":")) goto decrypt_error; } } else { // Add unencrypted data (for example, a prefix from a bouncer or bot) peice = word[uw]; } if (!append(&message, &length, peice)) goto decrypt_error; } free(decrypted); // Simulate unencrypted message //hexchat_printf(ph, "simulating: %s\n", message); hexchat_command(ph, message); free(message); free(sender_nick); return HEXCHAT_EAT_HEXCHAT; decrypt_error: free(decrypted); free(sender_nick); return HEXCHAT_EAT_NONE; } /** * Command handler for /setkey */ static int handle_setkey(char *word[], char *word_eol[], void *userdata) { const char *nick; const char *key; // Check syntax if (*word[2] == '\0') { hexchat_printf(ph, "%s\n", usage_setkey); return HEXCHAT_EAT_HEXCHAT; } if (*word[3] == '\0') { // /setkey password nick = hexchat_get_info(ph, "channel"); key = word_eol[2]; } else { // /setkey #channel password nick = word[2]; key = word_eol[3]; } // Set password if (keystore_store_key(nick, key)) { hexchat_printf(ph, "Stored key for %s\n", nick); } else { hexchat_printf(ph, "\00305Failed to store key in blow.ini\n", nick, key); } return HEXCHAT_EAT_HEXCHAT; } /** * Command handler for /delkey */ static int handle_delkey(char *word[], char *word_eol[], void *userdata) { const char *nick; // Check syntax if (*word[2] == '\0' || *word[3] != '\0') { hexchat_printf(ph, "%s\n", usage_delkey); return HEXCHAT_EAT_HEXCHAT; } nick = word_eol[2]; // Delete the given nick from the key store if (keystore_delete_nick(nick)) { hexchat_printf(ph, "Deleted key for %s\n", nick); } else { hexchat_printf(ph, "\00305Failed to delete key in blow.ini!\n", nick); } return HEXCHAT_EAT_HEXCHAT; } /** * Returns the plugin name version information. */ void hexchat_plugin_get_info(const char **name, const char **desc, const char **version, void **reserved) { *name = plugin_name; *desc = plugin_desc; *version = plugin_version; } /** * Plugin entry point. */ int hexchat_plugin_init(hexchat_plugin *plugin_handle, const char **name, const char **desc, const char **version, char *arg) { ph = plugin_handle; /* Send our info to HexChat */ *name = plugin_name; *desc = plugin_desc; *version = plugin_version; /* Register commands */ hexchat_hook_command(ph, "SETKEY", HEXCHAT_PRI_NORM, handle_setkey, usage_setkey, NULL); hexchat_hook_command(ph, "DELKEY", HEXCHAT_PRI_NORM, handle_delkey, usage_delkey, NULL); /* Add handlers */ hexchat_hook_command(ph, "", HEXCHAT_PRI_NORM, handle_outgoing, NULL, NULL); hexchat_hook_server(ph, "NOTICE", HEXCHAT_PRI_NORM, handle_incoming, NULL); hexchat_hook_server(ph, "PRIVMSG", HEXCHAT_PRI_NORM, handle_incoming, NULL); //hexchat_hook_server(ph, "RAW LINE", HEXCHAT_PRI_NORM, handle_debug, NULL); hexchat_hook_server(ph, "TOPIC", HEXCHAT_PRI_NORM, handle_incoming, NULL); hexchat_hook_server(ph, "332", HEXCHAT_PRI_NORM, handle_incoming, NULL); hexchat_printf(ph, "%s plugin loaded\n", plugin_name); /* Return success */ return 1; } int hexchat_plugin_deinit(void) { hexchat_printf(ph, "%s plugin unloaded\n", plugin_name); return 1; }