| 1 /* |
|
| 2 * An example plugin that demonstrates usage of a cipher object type |
|
| 3 * registered in another plugin. |
|
| 4 * |
|
| 5 * This plugin requires the caesarcipher plugin to be loaded to use the |
|
| 6 * CaesarCipher type. |
|
| 7 * |
|
| 8 * Copyright (C) 2013, Ankit Vani <a@nevitus.org> |
|
| 9 * |
|
| 10 * This program is free software; you can redistribute it and/or |
|
| 11 * modify it under the terms of the GNU General Public License as |
|
| 12 * published by the Free Software Foundation; either version 2 of the |
|
| 13 * License, or (at your option) any later version. |
|
| 14 * |
|
| 15 * This program is distributed in the hope that it will be useful, but |
|
| 16 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 18 * General Public License for more details. |
|
| 19 * |
|
| 20 * You should have received a copy of the GNU General Public License |
|
| 21 * along with this program; if not, write to the Free Software |
|
| 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
| 23 * 02111-1301, USA. |
|
| 24 */ |
|
| 25 |
|
| 26 /* When writing a third-party plugin, do not include libpurple's internal.h |
|
| 27 * included below. This file is for internal libpurple use only. We're including |
|
| 28 * it here for our own convenience. */ |
|
| 29 #include "internal.h" |
|
| 30 |
|
| 31 /* This file defines PURPLE_PLUGINS and includes all the libpurple headers */ |
|
| 32 #include <purple.h> |
|
| 33 |
|
| 34 #include "caesarcipher.h" |
|
| 35 |
|
| 36 static void |
|
| 37 debug_cipher(PurpleCipher *cipher, const gchar *input) |
|
| 38 { |
|
| 39 gchar ciphertext[512], plaintext[512]; |
|
| 40 |
|
| 41 purple_debug_info("caesarcipher_consumer", "Encrypting..."); |
|
| 42 |
|
| 43 purple_debug_info("caesarcipher_consumer", "INPUT: %s\n", input); |
|
| 44 purple_cipher_encrypt(cipher, (const guchar *)input, strlen(input), |
|
| 45 (guchar *)ciphertext, 512); |
|
| 46 purple_debug_info("caesarcipher_consumer", "OUTPUT: %s\n", ciphertext); |
|
| 47 |
|
| 48 purple_debug_info("caesarcipher_consumer", "Decrypting..."); |
|
| 49 |
|
| 50 purple_debug_info("caesarcipher_consumer", "INPUT: %s\n", ciphertext); |
|
| 51 purple_cipher_decrypt(cipher, (const guchar *)ciphertext, |
|
| 52 strlen(ciphertext), (guchar *)plaintext, 512); |
|
| 53 purple_debug_info("caesarcipher_consumer", "OUTPUT: %s\n", plaintext); |
|
| 54 } |
|
| 55 |
|
| 56 static PurplePluginInfo * |
|
| 57 plugin_query(GError **error) |
|
| 58 { |
|
| 59 const gchar * const authors[] = { |
|
| 60 "Ankit Vani <a@nevitus.org>", |
|
| 61 NULL |
|
| 62 }; |
|
| 63 |
|
| 64 /* we need to ensure the object provider is loaded for its type to be |
|
| 65 * registered in the type system. */ |
|
| 66 const gchar * const dependencies[] = { |
|
| 67 "core-caesarcipher", |
|
| 68 NULL |
|
| 69 }; |
|
| 70 |
|
| 71 return purple_plugin_info_new( |
|
| 72 "id", "core-caesarcipher_consumer", |
|
| 73 "name", N_("Caesar Cipher Consumer Example"), |
|
| 74 "version", DISPLAY_VERSION, |
|
| 75 "category", N_("Example"), |
|
| 76 "summary", N_("An example plugin that demonstrates usage of a " |
|
| 77 "loaded cipher type."), |
|
| 78 "description", N_("An example plugin that demonstrates usage of " |
|
| 79 "a cipher object type registered in another " |
|
| 80 "plugin."), |
|
| 81 "authors", authors, |
|
| 82 "website", PURPLE_WEBSITE, |
|
| 83 "abi-version", PURPLE_ABI_VERSION, |
|
| 84 "dependencies", dependencies, |
|
| 85 |
|
| 86 NULL |
|
| 87 ); |
|
| 88 } |
|
| 89 |
|
| 90 static gboolean |
|
| 91 plugin_load(PurplePlugin *plugin, GError **error) |
|
| 92 { |
|
| 93 PurpleCipher *cipher = caesar_cipher_new(); |
|
| 94 purple_debug_info("caesarcipher_consumer", "Created caesar cipher " |
|
| 95 "object.\n"); |
|
| 96 |
|
| 97 debug_cipher(cipher, "Input string for cipher!"); |
|
| 98 |
|
| 99 purple_cipher_set_key(cipher, NULL, 13); |
|
| 100 purple_debug_info("caesarcipher_consumer", "Offset set to 13.\n"); |
|
| 101 |
|
| 102 debug_cipher(cipher, "An0ther input 4 cipher.."); |
|
| 103 |
|
| 104 g_object_unref(cipher); |
|
| 105 purple_debug_info("caesarcipher_consumer", "Destroyed caesar cipher " |
|
| 106 "object.\n"); |
|
| 107 |
|
| 108 return TRUE; |
|
| 109 } |
|
| 110 |
|
| 111 static gboolean |
|
| 112 plugin_unload(PurplePlugin *plugin, GError **error) |
|
| 113 { |
|
| 114 return TRUE; |
|
| 115 } |
|
| 116 |
|
| 117 PURPLE_PLUGIN_INIT(caesarcipher_consumer, plugin_query, plugin_load, plugin_unload); |
|