1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
|
/*
* EveryBuddy
*
* Copyright (C) 2003, the Ayttm team
*
* Ayttm is derivative of Everybuddy
* Copyright (C) 1999-2002, Torrey Searle <tsearle@uci.edu>
*
* 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
*
*/
#include "intl.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef __MINGW32__
#define __IN_PLUGIN__
#endif
#include "externs.h"
#include "plugin_api.h"
#include "prefs.h"
#include "platform_defs.h"
#include "conversation.h"
/*******************************************************************************
* Begin Module Code
******************************************************************************/
/* Module defines */
#ifndef USE_POSIX_DLOPEN
#define plugin_info rainbow_LTX_plugin_info
#define plugin_init rainbow_LTX_plugin_init
#define plugin_finish rainbow_LTX_plugin_finish
#define module_version rainbow_LTX_module_version
#endif
/* Function Prototypes */
/* ebmCallbackData is a parent struct, the child of which will be an ebmContactData */
static char *dorainbow(Conversation *conv, const char *s);
static int rainbow_init();
static int rainbow_finish();
static int doRainbow = 0;
static char sstart_r[MAX_PREF_LEN] = "255";
static char sstart_g[MAX_PREF_LEN] = "0";
static char sstart_b[MAX_PREF_LEN] = "0";
static char send_r[MAX_PREF_LEN] = "0";
static char send_g[MAX_PREF_LEN] = "0";
static char send_b[MAX_PREF_LEN] = "255";
static char *html_tags[] =
{ "html", "body", "font", "p", "i", "b", "u", "img", "a", "br", "hr",
"head"
};
static int num_tags = 12;
static int ref_count = 0;
/* Module Exports */
PLUGIN_INFO plugin_info = {
PLUGIN_FILTER,
"Rainbow",
"Turns all outgoing messages into rainbow colours using HTML",
"$Revision: 1.10 $",
"$Date: 2009/09/17 12:04:59 $",
&ref_count,
rainbow_init,
rainbow_finish,
NULL
};
/* End Module Exports */
unsigned int module_version()
{
return CORE_VERSION;
}
static int rainbow_init()
{
input_list *il = calloc(1, sizeof(input_list));
plugin_info.prefs = il;
il->widget.checkbox.value = &doRainbow;
il->name = "doRainbow";
il->label = strdup(_("Enable rainbow conversion"));
il->type = EB_INPUT_CHECKBOX;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.entry.value = sstart_r;
il->name = "sstart_r";
il->label = strdup(_("Starting R value:"));
il->type = EB_INPUT_ENTRY;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.entry.value = sstart_g;
il->name = "sstart_g";
il->label = strdup(_("Starting G value:"));
il->type = EB_INPUT_ENTRY;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.entry.value = sstart_b;
il->name = "sstart_b";
il->label = strdup(_("Starting B value:"));
il->type = EB_INPUT_ENTRY;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.entry.value = send_r;
il->name = "send_r";
il->label = strdup(_("Ending R value:"));
il->type = EB_INPUT_ENTRY;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.entry.value = send_g;
il->name = "send_g";
il->label = strdup(_("Ending G value:"));
il->type = EB_INPUT_ENTRY;
il->next = calloc(1, sizeof(input_list));
il = il->next;
il->widget.entry.value = send_b;
il->name = "send_b";
il->label = strdup(_("Ending B value:"));
il->type = EB_INPUT_ENTRY;
eb_debug(DBG_MOD, "Rainbow initialised\n");
outgoing_message_filters_local =
l_list_append(outgoing_message_filters_local, &dorainbow);
outgoing_message_filters_remote =
l_list_append(outgoing_message_filters_remote, &dorainbow);
return 0;
}
static int rainbow_finish()
{
eb_debug(DBG_MOD, "Rainbow shutting down\n");
outgoing_message_filters_local =
l_list_remove(outgoing_message_filters_local, &dorainbow);
outgoing_message_filters_remote =
l_list_remove(outgoing_message_filters_remote, &dorainbow);
while (plugin_info.prefs) {
input_list *il = plugin_info.prefs->next;
free(plugin_info.prefs);
plugin_info.prefs = il;
}
return 0;
}
/*******************************************************************************
* End Module Code
******************************************************************************/
static char *dorainbow(Conversation *conv, const char *s)
{
char *retval;
char *wptr;
int pos = 0;
int start_r = atoi(sstart_r);
int start_g = atoi(sstart_g);
int start_b = atoi(sstart_b);
int end_r = atoi(send_r);
int end_g = atoi(send_g);
int end_b = atoi(send_b);
int len = strlen(s);
if (!doRainbow) {
return g_strdup(s);
}
if (start_r > 255 || start_r < 0) {
start_r = 0;
}
if (start_g > 255 || start_g < 0) {
start_g = 0;
}
if (start_b > 255 || start_b < 0) {
start_b = 0;
}
if (end_r > 255 || end_r < 0) {
end_r = 0;
}
if (end_g > 255 || end_g < 0) {
end_g = 0;
}
if (end_b > 255 || end_b < 0) {
end_b = 0;
}
wptr = retval = g_new0(char, 23 * len);
while (s[pos] != '\0') {
if (s[pos] == '<') {
int p2 = pos + 1;
int a, found = 0;
while (s[p2] == ' ' || s[p2] == '/') {
p2++;
} /* strip space before HTML tag */
for (a = 0; a < num_tags; a++) {
if (!strncasecmp
(s + p2, html_tags[a],
strlen(html_tags[a]))) {
found = 1;
break;
}
}
if (found) {
while (1) {
*(wptr++) = s[pos++];
if (s[pos - 1] == '\0'
|| s[pos - 1] == '>') {
break;
}
}
*wptr = '\0'; /* in case this is the last char */
continue;
}
}
wptr += snprintf(wptr, 22 * (len - pos),
"<font color=#%02x%02x%02x>%c",
(pos * end_r + (len - pos) * start_r) / len,
(pos * end_g + (len - pos) * start_g) / len,
(pos * end_b + (len - pos) * start_b) / len, s[pos]);
pos++;
}
return retval;
}
|