annotate src/util.c @ 6579:9714538226f0

[gaim-migrate @ 7101] (20:25:50) Robot101: LSchiere: eek (20:25:54) Robot101: LSchiere: that's garbled (20:26:10) Robot101: I said move the c=, not the b=.. committer: Tailor Script <tailor@pidgin.im>
author Luke Schierer <lschiere@pidgin.im>
date Sat, 23 Aug 2003 00:27:10 +0000
parents 338147ea6896
children 060aa79a733e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1 /*
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 * gaim
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 * (at your option) any later version.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 * GNU General Public License for more details.
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 *
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20 */
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5826
diff changeset
22 #include "internal.h"
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
23
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5826
diff changeset
24 #include "conversation.h"
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5826
diff changeset
25 #include "debug.h"
1575
427e1409917c [gaim-migrate @ 1585]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1560
diff changeset
26 #include "prpl.h"
5545
7a64114641c3 [gaim-migrate @ 5946]
Christian Hammond <chipx86@chipx86.com>
parents: 5532
diff changeset
27 #include "prefs.h"
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
29 static char home_dir[MAXPATHLEN];
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
30
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
31 char *full_date()
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
32 {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
33 char *date;
70
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
34 time_t tme;
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
35
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
36 time(&tme);
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
37 date = ctime(&tme);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
38 date[strlen(date) - 1] = '\0';
70
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
39 return date;
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
40 }
dead1eb6d654 [gaim-migrate @ 80]
Rob Flynn <gaim@robflynn.com>
parents: 26
diff changeset
41
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
42 G_GNUC_CONST static gint badchar(char c)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
44 switch (c) {
970
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
45 case ' ':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
46 case ',':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
47 case '(':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
48 case ')':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
49 case '\0':
976
2586b2a3725e [gaim-migrate @ 986]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 970
diff changeset
50 case '\n':
970
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
51 case '<':
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
52 case '>':
1706
e6671b80a1f2 [gaim-migrate @ 1716]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1622
diff changeset
53 case '"':
5176
6911a84cbab1 [gaim-migrate @ 5540]
Nathan Walp <nwalp@pidgin.im>
parents: 5160
diff changeset
54 case '\'':
413
7ea55575cc01 [gaim-migrate @ 423]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 373
diff changeset
55 return 1;
970
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
56 default:
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
57 return 0;
9eb07b383df4 [gaim-migrate @ 980]
Rob Flynn <gaim@robflynn.com>
parents: 967
diff changeset
58 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61
1376
730a1a19b4cc [gaim-migrate @ 1386]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1293
diff changeset
62 gchar *sec_to_text(guint sec)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 {
4834
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
64 guint daze, hrs, min;
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
65 char *ret = NULL;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
67 daze = sec / (60 * 60 * 24);
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
68 hrs = (sec % (60 * 60 * 24)) / (60 * 60);
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
69 min = (sec % (60 * 60)) / 60;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
70 sec = min % 60;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
72 if (daze) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
73 if (hrs || min) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
74 if (hrs) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
75 if (min) {
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
76 ret = g_strdup_printf(
4834
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
77 "%d %s, %d %s, %d %s.",
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
78 daze, ngettext("day","days",daze),
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
79 hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min));
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
80 } else {
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
81 ret = g_strdup_printf(
4834
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
82 "%d %s, %d %s.",
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
83 daze, ngettext("day","days",daze), hrs, ngettext("hour","hours",hrs));
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
84 }
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
85 } else {
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
86 ret = g_strdup_printf(
4834
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
87 "%d %s, %d %s.",
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
88 daze, ngettext("day","days",daze), min, ngettext("minute","minutes",min));
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
89 }
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
90 } else
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
91 ret = g_strdup_printf("%d %s.", daze, ngettext("day","days",daze));
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
92 } else {
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
93 if (hrs) {
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
94 if (min) {
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
95 ret = g_strdup_printf(
4834
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
96 "%d %s, %d %s.",
0ed37c803503 [gaim-migrate @ 5159]
Luke Schierer <lschiere@pidgin.im>
parents: 4793
diff changeset
97 hrs, ngettext("hour","hours",hrs), min, ngettext("minute","minutes",min));
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
98 } else {
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
99 ret = g_strdup_printf("%d %s.", hrs, ngettext("hour","hours",hrs));
1826
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
100 }
7f889cdfa03e [gaim-migrate @ 1836]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1815
diff changeset
101 } else {
5341
ccec8893c1be [gaim-migrate @ 5717]
Mark Doliner <mark@kingant.net>
parents: 5302
diff changeset
102 ret = g_strdup_printf("%d %s.", min, ngettext("minute","minutes",min));
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
103 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
104 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
106 return ret;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
109 char *linkify_text(const char *text)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 {
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
111 const char *c, *t, *q = NULL;
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
112 char *tmp;
1622
1acef460964a [gaim-migrate @ 1632]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1609
diff changeset
113 char url_buf[BUF_LEN * 4];
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
114 GString *ret = g_string_new("");
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
115 /* Assumes you have a buffer able to cary at least BUF_LEN * 2 bytes */
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
117 c = text;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
118 while (*c) {
5093
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5084
diff changeset
119 if(!q && (*c == '\"' || *c == '\'')) {
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5084
diff changeset
120 q = c;
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5084
diff changeset
121 } else if(q) {
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5084
diff changeset
122 if(*c == *q)
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5084
diff changeset
123 q = NULL;
89c0c811befa [gaim-migrate @ 5455]
Nathan Walp <nwalp@pidgin.im>
parents: 5084
diff changeset
124 } else if (!g_ascii_strncasecmp(c, "<A", 2)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
125 while (1) {
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
126 if (!g_ascii_strncasecmp(c, "/A>", 3)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
127 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
128 }
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
129 ret = g_string_append_c(ret, *c);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
130 c++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
131 if (!(*c))
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
132 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
133 }
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
134 } else if ((*c=='h') && (!g_ascii_strncasecmp(c, "http://", 7) ||
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
135 (!g_ascii_strncasecmp(c, "https://", 8)))) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
136 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
137 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
138 if (badchar(*t)) {
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
139
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
140 if (*(t) == ',' && (*(t + 1) != ' ')) {
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
141 t++;
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
142 continue;
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
143 }
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
144
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
145 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
146 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
147 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
148 url_buf[t - c] = 0;
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
149 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
150 url_buf, url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
151 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
152 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
153 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
154 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
155 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
156 t++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
158 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
159 } else if (!g_ascii_strncasecmp(c, "www.", 4)) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
160 if (c[4] != '.') {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
161 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
162 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
163 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
164 if (t - c == 4) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
165 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
166 }
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
167
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
168 if (*(t) == ',' && (*(t + 1) != ' ')) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
169 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
170 continue;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
171 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
172
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
173 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
174 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
175 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
176 url_buf[t - c] = 0;
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
177 g_string_append_printf(ret,
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
178 "<A HREF=\"http://%s\">%s</A>", url_buf,
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
179 url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
180 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
181 break;
925
1ff824e6bc19 [gaim-migrate @ 935]
Rob Flynn <gaim@robflynn.com>
parents: 924
diff changeset
182 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
183 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
184 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
185 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
186 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
187 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
188 } else if (!g_ascii_strncasecmp(c, "ftp://", 6)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
189 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
190 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
191 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
192 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
193 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
194 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
195 url_buf[t - c] = 0;
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
196 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
197 url_buf, url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
198 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
199 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
200 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
201 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
202 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
203 t++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
204
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
205 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
206 } else if (!g_ascii_strncasecmp(c, "ftp.", 4)) {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
207 if (c[4] != '.') {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
208 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
209 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
210 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
211 if (t - c == 4) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
212 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
213 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
214 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
215 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
216 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
217 url_buf[t - c] = 0;
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
218 g_string_append_printf(ret,
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
219 "<A HREF=\"ftp://%s\">%s</A>", url_buf,
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
220 url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
221 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
222 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
223 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
224 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
225 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
226 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
227 }
924
f6aa60716419 [gaim-migrate @ 934]
Rob Flynn <gaim@robflynn.com>
parents: 915
diff changeset
228 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
229 } else if (!g_ascii_strncasecmp(c, "mailto:", 7)) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
230 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
231 while (1) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
232 if (badchar(*t)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
233 if (*(t - 1) == '.')
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
234 t--;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
235 strncpy(url_buf, c, t - c);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
236 url_buf[t - c] = 0;
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
237 g_string_append_printf(ret, "<A HREF=\"%s\">%s</A>",
2614
3e2f455cb924 [gaim-migrate @ 2627]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2603
diff changeset
238 url_buf, url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
239 c = t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
240 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
241 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
242 if (!t)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
243 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
244 t++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
245
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
246 }
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
247 } else if (c != text && (*c == '@')) {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
248 char *tmp;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
249 int flag;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
250 int len = 0;
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
251 const char illegal_chars[] = "!@#$%^&*()[]{}/|\\<>\":;\r\n \0";
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
252 url_buf[0] = 0;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
253
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
254 if (strchr(illegal_chars,*(c - 1)) || strchr(illegal_chars, *(c + 1)))
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
255 flag = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
256 else
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
257 flag = 1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
258
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
259 t = c;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
260 while (flag) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
261 if (badchar(*t)) {
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
262 ret = g_string_truncate(ret, ret->len - (len - 1));
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
263 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
264 } else {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
265 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
266 tmp = g_malloc(len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
267 tmp[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
268 tmp[0] = *t;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
269 strncpy(tmp + 1, url_buf, len - 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
270 strcpy(url_buf, tmp);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
271 url_buf[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
272 g_free(tmp);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
273 t--;
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
274 if (t < text) {
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
275 ret = g_string_assign(ret, "");
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
276 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
277 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
278 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
279 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
280
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
281 t = c + 1;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
282
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
283 while (flag) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
284 if (badchar(*t)) {
3331
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
285 char *d;
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
286
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
287 for (d = url_buf + strlen(url_buf) - 1; *d == '.'; d--, t--)
8f69ff64f0bf [gaim-migrate @ 3349]
Christian Hammond <chipx86@chipx86.com>
parents: 3330
diff changeset
288 *d = '\0';
3330
af52fdf06166 [gaim-migrate @ 3348]
Christian Hammond <chipx86@chipx86.com>
parents: 3279
diff changeset
289
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
290 g_string_append_printf(ret, "<A HREF=\"mailto:%s\">%s</A>",
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
291 url_buf, url_buf);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
292 c = t;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
293
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
294 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
295 } else {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
296 strncat(url_buf, t, 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
297 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
298 url_buf[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
299 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
300
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
301 t++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
302 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
303 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
304
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
305 if (*c == 0)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
306 break;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
307
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
308 ret = g_string_append_c(ret, *c);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
309 c++;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
310
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
311 }
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
312 tmp = ret->str;
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
313 g_string_free(ret, FALSE);
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
314 return tmp;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
315 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
316
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
317
4888
912294585edf [gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents: 4853
diff changeset
318 static const char alphabet[] =
912294585edf [gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents: 4853
diff changeset
319 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
912294585edf [gaim-migrate @ 5218]
Christian Hammond <chipx86@chipx86.com>
parents: 4853
diff changeset
320 "0123456789+/";
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
321
5426
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
322 /* This was borrowed from the Kame source, and then tweaked to our needs */
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
323 char *tobase64(const unsigned char *buf, size_t len)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
324 {
5531
10920646988f [gaim-migrate @ 5931]
Luke Schierer <lschiere@pidgin.im>
parents: 5515
diff changeset
325 char *s = NULL, *rv = NULL;
6087
6e24de5efdb2 [gaim-migrate @ 6546]
Mark Doliner <mark@kingant.net>
parents: 6053
diff changeset
326 unsigned long tmp;
5426
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
327
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
328 s = g_malloc((4 * (len + 1)) / 3 + 1);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
329
5426
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
330 rv = s;
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
331 while (len >= 3) {
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
332 tmp = buf[0] << 16 | buf[1] << 8 | buf[2];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
333 s[0] = alphabet[tmp >> 18];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
334 s[1] = alphabet[(tmp >> 12) & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
335 s[2] = alphabet[(tmp >> 6) & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
336 s[3] = alphabet[tmp & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
337 len -= 3;
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
338 buf += 3;
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
339 s += 4;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
340 }
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
341
5426
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
342 /* RFC 1521 enumerates these three possibilities... */
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
343 switch(len) {
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
344 case 2:
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
345 tmp = buf[0] << 16 | buf[1] << 8;
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
346 s[0] = alphabet[(tmp >> 18) & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
347 s[1] = alphabet[(tmp >> 12) & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
348 s[2] = alphabet[(tmp >> 6) & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
349 s[3] = '=';
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
350 s[4] = '\0';
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
351 break;
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
352 case 1:
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
353 tmp = buf[0] << 16;
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
354 s[0] = alphabet[(tmp >> 18) & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
355 s[1] = alphabet[(tmp >> 12) & 077];
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
356 s[2] = s[3] = '=';
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
357 s[4] = '\0';
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
358 break;
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
359 case 0:
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
360 s[0] = '\0';
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
361 break;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
362 }
5426
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
363
8d8bf0d31a23 [gaim-migrate @ 5805]
Nathan Walp <nwalp@pidgin.im>
parents: 5341
diff changeset
364 return rv;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
365 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
366
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
367
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
368 void frombase64(const char *text, char **data, int *size)
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
369 {
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
370 char *out = NULL;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
371 char tmp = 0;
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
372 const char *c;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
373 gint32 tmp2 = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
374 int len = 0, n = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
375
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
376 if (!text || !data)
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
377 return;
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
378
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
379 c = text;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
380
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
381 while (*c) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
382 if (*c >= 'A' && *c <= 'Z') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
383 tmp = *c - 'A';
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
384 } else if (*c >= 'a' && *c <= 'z') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
385 tmp = 26 + (*c - 'a');
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
386 } else if (*c >= '0' && *c <= 57) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
387 tmp = 52 + (*c - '0');
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
388 } else if (*c == '+') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
389 tmp = 62;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
390 } else if (*c == '/') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
391 tmp = 63;
5289
cfbd0cb3f18b [gaim-migrate @ 5661]
Nathan Walp <nwalp@pidgin.im>
parents: 5247
diff changeset
392 } else if (*c == '\r' || *c == '\n') {
cfbd0cb3f18b [gaim-migrate @ 5661]
Nathan Walp <nwalp@pidgin.im>
parents: 5247
diff changeset
393 c++;
cfbd0cb3f18b [gaim-migrate @ 5661]
Nathan Walp <nwalp@pidgin.im>
parents: 5247
diff changeset
394 continue;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
395 } else if (*c == '=') {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
396 if (n == 3) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
397 out = g_realloc(out, len + 2);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
398 out[len] = (char)(tmp2 >> 10) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
399 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
400 out[len] = (char)(tmp2 >> 2) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
401 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
402 } else if (n == 2) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
403 out = g_realloc(out, len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
404 out[len] = (char)(tmp2 >> 4) & 0xff;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
405 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
406 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
407 break;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
408 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
409 tmp2 = ((tmp2 << 6) | (tmp & 0xff));
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
410 n++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
411 if (n == 4) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
412 out = g_realloc(out, len + 3);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
413 out[len] = (char)((tmp2 >> 16) & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
414 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
415 out[len] = (char)((tmp2 >> 8) & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
416 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
417 out[len] = (char)(tmp2 & 0xff);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
418 len++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
419 tmp2 = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
420 n = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
421 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
422 c++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
423 }
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
424
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
425 out = g_realloc(out, len + 1);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
426 out[len] = 0;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
427
1920
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
428 *data = out;
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
429 if (size)
5bed3bc833b5 [gaim-migrate @ 1930]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1878
diff changeset
430 *size = len;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
431 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
432
4853
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
433 /*
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
434 * Converts raw data to a pretty, null-terminated base16 string.
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
435 */
5451
e1cc0c67e123 [gaim-migrate @ 5839]
Nathan Walp <nwalp@pidgin.im>
parents: 5450
diff changeset
436 unsigned char *tobase16(const unsigned char *data, int length)
4853
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
437 {
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
438 int i;
5450
bb1e160467b6 [gaim-migrate @ 5838]
Nathan Walp <nwalp@pidgin.im>
parents: 5435
diff changeset
439 unsigned char *ascii = NULL;
4853
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
440
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
441 if (!data || !length)
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
442 return NULL;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
443
6053
74b281b4ae29 [gaim-migrate @ 6503]
Nathan Walp <nwalp@pidgin.im>
parents: 5943
diff changeset
444 ascii = g_malloc(length*2 + 1);
4853
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
445
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
446 for (i=0; i<length; i++)
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
447 snprintf(&ascii[i*2], 3, "%02hhx", data[i]);
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
448
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
449 return ascii;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
450 }
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
451
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
452 /*
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
453 * Converts a null-terminated string of hexidecimal to raw data.
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
454 */
5497
3c7748b24410 [gaim-migrate @ 5893]
Mark Doliner <mark@kingant.net>
parents: 5451
diff changeset
455 int frombase16(const char *ascii, unsigned char **raw)
4853
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
456 {
5078
19814ecb23e0 [gaim-migrate @ 5431]
Mark Doliner <mark@kingant.net>
parents: 5024
diff changeset
457 int len, i, accumulator=0;
5497
3c7748b24410 [gaim-migrate @ 5893]
Mark Doliner <mark@kingant.net>
parents: 5451
diff changeset
458 unsigned char *data;
4853
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
459
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
460 if (!ascii || !(len = strlen(ascii)) || (len % 2))
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
461 return 0;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
462
6053
74b281b4ae29 [gaim-migrate @ 6503]
Nathan Walp <nwalp@pidgin.im>
parents: 5943
diff changeset
463 data = g_malloc(len/2);
4853
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
464 for (i=0; i<len; i++) {
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
465 if (!(i % 2))
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
466 accumulator = 0;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
467 else
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
468 accumulator = accumulator << 4;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
469 if (isdigit(ascii[i]))
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
470 accumulator |= ascii[i]-48;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
471 else switch(ascii[i]) {
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
472 case 'a': case 'A': accumulator|=10; break;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
473 case 'b': case 'B': accumulator|=11; break;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
474 case 'c': case 'C': accumulator|=12; break;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
475 case 'd': case 'D': accumulator|=13; break;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
476 case 'e': case 'E': accumulator|=14; break;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
477 case 'f': case 'F': accumulator|=15; break;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
478 }
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
479 if (i % 2)
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
480 data[(i-1)/2] = accumulator;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
481 }
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
482
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
483 *raw = data;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
484 return len/2;
fbfdacf7c611 [gaim-migrate @ 5180]
Mark Doliner <mark@kingant.net>
parents: 4834
diff changeset
485 }
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
486
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
487 char *normalize(const char *s)
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
488 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
489 static char buf[BUF_LEN];
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
490 char *tmp;
4282
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
491 int i, j;
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
492
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
493 g_return_val_if_fail((s != NULL), NULL);
26
b9e90a914e20 [gaim-migrate @ 35]
Rob Flynn <gaim@robflynn.com>
parents: 25
diff changeset
494
4282
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
495 strncpy(buf, s, BUF_LEN);
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
496 for (i=0, j=0; buf[j]; i++, j++) {
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
497 while (buf[j] == ' ')
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
498 j++;
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
499 buf[i] = buf[j];
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
500 }
aa20cc16dc08 [gaim-migrate @ 4533]
Mark Doliner <mark@kingant.net>
parents: 4184
diff changeset
501 buf[i] = '\0';
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
502
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
503 tmp = g_utf8_strdown(buf, -1);
4899
347070472ed6 [gaim-migrate @ 5231]
Nathan Walp <nwalp@pidgin.im>
parents: 4890
diff changeset
504 g_snprintf(buf, sizeof(buf), "%s", tmp);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
505 g_free(tmp);
5247
60983a46700e [gaim-migrate @ 5618]
Luke Schierer <lschiere@pidgin.im>
parents: 5234
diff changeset
506 tmp = g_utf8_normalize(buf, -1, G_NORMALIZE_DEFAULT);
60983a46700e [gaim-migrate @ 5618]
Luke Schierer <lschiere@pidgin.im>
parents: 5234
diff changeset
507 g_snprintf(buf, sizeof(buf), "%s", tmp);
60983a46700e [gaim-migrate @ 5618]
Luke Schierer <lschiere@pidgin.im>
parents: 5234
diff changeset
508 g_free(tmp);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
509
1
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
510 return buf;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
511 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
512
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
513 char *date()
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
514 {
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
515 static char date[80];
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
516 time_t tme;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
517 time(&tme);
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
518 strftime(date, sizeof(date), "%H:%M:%S", localtime(&tme));
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
519 return date;
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
520 }
2846a03bda67 [gaim-migrate @ 10]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
521
3806
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
522 void clean_pid(void)
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
523 {
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
524 #ifndef _WIN32
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
525 int status;
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
526 pid_t pid;
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
527
3890
271ca53950e6 [gaim-migrate @ 4042]
Luke Schierer <lschiere@pidgin.im>
parents: 3867
diff changeset
528 do {
271ca53950e6 [gaim-migrate @ 4042]
Luke Schierer <lschiere@pidgin.im>
parents: 3867
diff changeset
529 pid = waitpid(-1, &status, WNOHANG);
3891
a611ec77d1d2 [gaim-migrate @ 4043]
Luke Schierer <lschiere@pidgin.im>
parents: 3890
diff changeset
530 } while (pid != 0 && pid != (pid_t)-1);
3890
271ca53950e6 [gaim-migrate @ 4042]
Luke Schierer <lschiere@pidgin.im>
parents: 3867
diff changeset
531 if(pid == (pid_t)-1 && errno != ECHILD) {
3806
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
532 char errmsg[BUFSIZ];
5435
a2f26666de42 [gaim-migrate @ 5817]
Mark Doliner <mark@kingant.net>
parents: 5426
diff changeset
533 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid);
3806
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
534 perror(errmsg);
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
535 }
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
536 #endif
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
537 }
b7a6aa99ee7c [gaim-migrate @ 3949]
Sean Egan <seanegan@gmail.com>
parents: 3802
diff changeset
538
206
610b7ffc4821 [gaim-migrate @ 216]
Rob Flynn <gaim@robflynn.com>
parents: 194
diff changeset
539
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
540 /* Look for %n, %d, or %t in msg, and replace with the sender's name, date,
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
541 or time */
4890
89cb14edf8cf [gaim-migrate @ 5220]
Christian Hammond <chipx86@chipx86.com>
parents: 4888
diff changeset
542 char *away_subs(const char *msg, const char *name)
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
543 {
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
544 char *c;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
545 static char cpy[BUF_LONG];
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
546 int cnt = 0;
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
547 time_t t = time(0);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
548 struct tm *tme = localtime(&t);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
549 char tmp[20];
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
550
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
551 cpy[0] = '\0';
4921
d5c136474f26 [gaim-migrate @ 5255]
Nathan Walp <nwalp@pidgin.im>
parents: 4899
diff changeset
552 c = (char *)msg;
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
553 while (*c) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
554 switch (*c) {
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
555 case '%':
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
556 if (*(c + 1)) {
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
557 switch (*(c + 1)) {
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
558 case 'n':
1976
24aed1c31342 [gaim-migrate @ 1986]
Rob Flynn <gaim@robflynn.com>
parents: 1949
diff changeset
559 /* append name */
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
560 strcpy(cpy + cnt, name);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
561 cnt += strlen(name);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
562 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
563 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
564 case 'd':
1976
24aed1c31342 [gaim-migrate @ 1986]
Rob Flynn <gaim@robflynn.com>
parents: 1949
diff changeset
565 /* append date */
2161
757e10018950 [gaim-migrate @ 2171]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2155
diff changeset
566 strftime(tmp, 20, "%m/%d/%Y", tme);
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
567 strcpy(cpy + cnt, tmp);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
568 cnt += strlen(tmp);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
569 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
570 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
571 case 't':
1976
24aed1c31342 [gaim-migrate @ 1986]
Rob Flynn <gaim@robflynn.com>
parents: 1949
diff changeset
572 /* append time */
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
573 strftime(tmp, 20, "%r", tme);
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
574 strcpy(cpy + cnt, tmp);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
575 cnt += strlen(tmp);
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
576 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
577 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
578 default:
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
579 cpy[cnt++] = *c;
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
580 }
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
581 }
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
582 break;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
583 default:
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
584 cpy[cnt++] = *c;
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
585 }
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
586 c++;
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
587 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
588 cpy[cnt] = '\0';
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
589 return (cpy);
592
7c75d69a1129 [gaim-migrate @ 602]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 470
diff changeset
590 }
603
9b0717b4a490 [gaim-migrate @ 613]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 592
diff changeset
591
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
592 GSList *message_split(char *message, int limit)
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
593 {
1100
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
594 static GSList *ret = NULL;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
595 int lastgood = 0, curgood = 0, curpos = 0, len = strlen(message);
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
596 gboolean intag = FALSE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
597
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
598 if (ret) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
599 GSList *tmp = ret;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
600 while (tmp) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
601 g_free(tmp->data);
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
602 tmp = g_slist_remove(tmp, tmp->data);
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
603 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
604 ret = NULL;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
605 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
606
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
607 while (TRUE) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
608 if (lastgood >= len)
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
609 return ret;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
610
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
611 if (len - lastgood < limit) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
612 ret = g_slist_append(ret, g_strdup(&message[lastgood]));
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
613 return ret;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
614 }
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
615
1100
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
616 curgood = curpos = 0;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
617 intag = FALSE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
618 while (curpos <= limit) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
619 if (isspace(message[curpos + lastgood]) && !intag)
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
620 curgood = curpos;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
621 if (message[curpos + lastgood] == '<')
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
622 intag = TRUE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
623 if (message[curpos + lastgood] == '>')
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
624 intag = FALSE;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
625 curpos++;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
626 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
627
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
628 if (curgood) {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
629 ret = g_slist_append(ret, g_strndup(&message[lastgood], curgood));
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
630 if (isspace(message[curgood + lastgood]))
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
631 lastgood += curgood + 1;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
632 else
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
633 lastgood += curgood;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
634 } else {
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
635 /* whoops, guess we have to fudge it here */
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
636 ret = g_slist_append(ret, g_strndup(&message[lastgood], limit));
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
637 lastgood += limit;
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
638 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
639 }
f168625b63fe [gaim-migrate @ 1110]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1087
diff changeset
640 }
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
641
3867
43e396e94095 [gaim-migrate @ 4019]
Rob Flynn <gaim@robflynn.com>
parents: 3806
diff changeset
642 const gchar *gaim_home_dir()
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
643 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
644 if(g_get_home_dir())
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
645 return g_get_home_dir();
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
646 else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
647 #ifndef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
648 return NULL;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
649 #else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
650 /* Win9x and WinME don't have a home dir */
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
651 return "C:";
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
652 #endif
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
653
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
654 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
655
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
656 /* returns a string of the form ~/.gaim, where ~ is replaced by the user's home
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
657 * dir. Note that there is no trailing slash after .gaim. */
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
658 gchar *gaim_user_dir()
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
659 {
4160
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
660 const gchar *hd = gaim_home_dir();
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
661 if(hd) {
fcc6db86f5c7 [gaim-migrate @ 4389]
Luke Schierer <lschiere@pidgin.im>
parents: 3891
diff changeset
662 strcpy( (char*)&home_dir, hd );
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
663 strcat( (char*)&home_dir, G_DIR_SEPARATOR_S ".gaim" );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
664 return (gchar*)&home_dir;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
665 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
666 else {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
667 return NULL;
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
668 }
1238
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
669 }
78c4f497db2b [gaim-migrate @ 1248]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1202
diff changeset
670
1292
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
671 /*
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
672 * rcg10312000 This could be more robust, but it works for my current
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
673 * goal: to remove those annoying <BR> tags. :)
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
674 * dtf12162000 made the loop more readable. i am a neat freak. ;) */
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
675 void strncpy_nohtml(gchar *dest, const gchar *src, size_t destsize)
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
676 {
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
677 gchar *ptr;
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
678 g_snprintf(dest, destsize, "%s", src);
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
679
1815
f15d449b3167 [gaim-migrate @ 1825]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1805
diff changeset
680 while ((ptr = strstr(dest, "<BR>")) != NULL) {
1292
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
681 /* replace <BR> with a newline. */
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
682 *ptr = '\n';
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
683 memmove(ptr + 1, ptr + 4, strlen(ptr + 4) + 1);
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
684 }
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
685 }
cb84b5c6d9ab [gaim-migrate @ 1302]
Rob Flynn <gaim@robflynn.com>
parents: 1269
diff changeset
686
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
687 void strncpy_withhtml(gchar *dest, const gchar *src, size_t destsize)
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
688 {
1202
d5146df6d2ab [gaim-migrate @ 1212]
Rob Flynn <gaim@robflynn.com>
parents: 1197
diff changeset
689 gchar *end = dest + destsize;
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
690
1293
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
691 while (dest < end) {
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
692 if (*src == '\n' && dest < end - 5) {
1202
d5146df6d2ab [gaim-migrate @ 1212]
Rob Flynn <gaim@robflynn.com>
parents: 1197
diff changeset
693 strcpy(dest, "<BR>");
1252
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
694 src++;
46c09828e929 [gaim-migrate @ 1262]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1250
diff changeset
695 dest += 4;
6397
b6d204635cd2 [gaim-migrate @ 6902]
Nathan Walp <nwalp@pidgin.im>
parents: 6087
diff changeset
696 } else if(*src == '\r') {
b6d204635cd2 [gaim-migrate @ 6902]
Nathan Walp <nwalp@pidgin.im>
parents: 6087
diff changeset
697 src++;
1293
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
698 } else {
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
699 *dest++ = *src;
2372
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
700 if (*src == '\0')
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
701 return;
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
702 else
2927c2c26fe6 [gaim-migrate @ 2385]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2371
diff changeset
703 src++;
1293
fbc0cbf24a62 [gaim-migrate @ 1303]
Rob Flynn <gaim@robflynn.com>
parents: 1292
diff changeset
704 }
1191
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
705 }
4fd0d35826fe [gaim-migrate @ 1201]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1152
diff changeset
706 }
1254
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
707
9da444224f0e [gaim-migrate @ 1264]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1252
diff changeset
708
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
709 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
710 * Like strncpy_withhtml (above), but malloc()'s the necessary space
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
711 *
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
712 * The caller is responsible for freeing the space pointed to by the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
713 * return value.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
714 */
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
715
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
716 gchar *strdup_withhtml(const gchar *src)
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
717 {
3279
86fdd015f40e [gaim-migrate @ 3297]
Sean Egan <seanegan@gmail.com>
parents: 3233
diff changeset
718 gchar *sp, *dest;
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
719 gulong destsize;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
720
4771
912bacf989d7 [gaim-migrate @ 5089]
Nathan Walp <nwalp@pidgin.im>
parents: 4695
diff changeset
721 if(!src)
912bacf989d7 [gaim-migrate @ 5089]
Nathan Walp <nwalp@pidgin.im>
parents: 4695
diff changeset
722 return NULL;
912bacf989d7 [gaim-migrate @ 5089]
Nathan Walp <nwalp@pidgin.im>
parents: 4695
diff changeset
723
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
724 /*
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
725 * All we need do is multiply the number of newlines by 3 (the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
726 * additional length of "<BR>" over "\n"), account for the
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
727 * terminator, malloc the space and call strncpy_withhtml.
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
728 */
3279
86fdd015f40e [gaim-migrate @ 3297]
Sean Egan <seanegan@gmail.com>
parents: 3233
diff changeset
729 for(destsize = 0, sp = (gchar *)src; (sp = strchr(sp, '\n')) != NULL; ++sp, ++destsize)
2956
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
730 ;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
731 destsize *= 3;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
732 destsize += strlen(src) + 1;
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
733 dest = g_malloc(destsize);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
734 strncpy_withhtml(dest, src, destsize);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
735
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
736 return(dest);
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
737 }
b68c648618a3 [gaim-migrate @ 2969]
Rob Flynn <gaim@robflynn.com>
parents: 2823
diff changeset
738
2603
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
739 void strip_linefeed(gchar *text)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
740 {
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
741 int i, j;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
742 gchar *text2 = g_malloc(strlen(text) + 1);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
743
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
744 for (i = 0, j = 0; text[i]; i++)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
745 if (text[i] != '\r')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
746 text2[j++] = text[i];
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
747 text2[j] = '\0';
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
748
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
749 strcpy(text, text2);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
750 g_free(text2);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
751 }
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
752
5136
381da05cb5ed [gaim-migrate @ 5500]
Nathan Walp <nwalp@pidgin.im>
parents: 5093
diff changeset
753 char *add_cr(const char *text)
2603
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
754 {
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
755 char *ret = NULL;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
756 int count = 0, i, j;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
757
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
758 if (text[0] == '\n')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
759 count++;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
760 for (i = 1; i < strlen(text); i++)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
761 if (text[i] == '\n' && text[i - 1] != '\r')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
762 count++;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
763
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
764 if (count == 0)
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
765 return g_strdup(text);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
766
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
767 ret = g_malloc0(strlen(text) + count + 1);
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
768
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
769 i = 0; j = 0;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
770 if (text[i] == '\n')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
771 ret[j++] = '\r';
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
772 ret[j++] = text[i++];
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
773 for (; i < strlen(text); i++) {
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
774 if (text[i] == '\n' && text[i - 1] != '\r')
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
775 ret[j++] = '\r';
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
776 ret[j++] = text[i];
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
777 }
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
778
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
779 gaim_debug(GAIM_DEBUG_INFO, "add_cr", "got: %s, leaving with %s\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
780 text, ret);
2603
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
781
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
782 return ret;
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
783 }
24664768a739 [gaim-migrate @ 2616]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 2596
diff changeset
784
1805
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
785 time_t get_time(int year, int month, int day, int hour, int min, int sec)
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
786 {
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
787 struct tm tm;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
788
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
789 tm.tm_year = year - 1900;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
790 tm.tm_mon = month - 1;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
791 tm.tm_mday = day;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
792 tm.tm_hour = hour;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
793 tm.tm_min = min;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
794 tm.tm_sec = sec >= 0 ? sec : time(NULL) % 60;
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
795 return mktime(&tm);
caa605e70917 [gaim-migrate @ 1815]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1753
diff changeset
796 }
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
797
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
798 /*
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
799 * Like mkstemp() but returns a file pointer, uses a pre-set template,
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
800 * uses the semantics of tempnam() for the directory to use and allocates
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
801 * the space for the filepath.
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
802 *
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
803 * Caller is responsible for closing the file and removing it when done,
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
804 * as well as freeing the space pointed-to by "path" with g_free().
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
805 *
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
806 * Returns NULL on failure and cleans up after itself if so.
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
807 */
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
808 static const char *gaim_mkstemp_templ = {"gaimXXXXXX"};
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
809
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
810 FILE *gaim_mkstemp(gchar **fpath)
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
811 {
3466
7a3f16a375a5 [gaim-migrate @ 3516]
Sean Egan <seanegan@gmail.com>
parents: 3457
diff changeset
812 const gchar *tmpdir;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
813 #ifndef _WIN32
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
814 int fd;
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
815 #endif
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
816 FILE *fp = NULL;
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
817
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
818 if((tmpdir = (gchar*)g_get_tmp_dir()) != NULL) {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
819 if((*fpath = g_strdup_printf("%s" G_DIR_SEPARATOR_S "%s", tmpdir, gaim_mkstemp_templ)) != NULL) {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
820 #ifdef _WIN32
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
821 char* result = _mktemp( *fpath );
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
822 if( result == NULL )
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
823 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
824 "Problem creating the template\n");
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
825 else
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
826 {
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
827 if( (fp = fopen( result, "w+" )) == NULL ) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
828 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
829 "Couldn't fopen() %s\n", result);
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
830 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
831 }
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
832 #else
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
833 if((fd = mkstemp(*fpath)) == -1) {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
834 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
835 "Couldn't make \"%s\", error: %d\n",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
836 *fpath, errno);
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
837 } else {
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
838 if((fp = fdopen(fd, "r+")) == NULL) {
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
839 close(fd);
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
840 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
841 "Couldn't fdopen(), error: %d\n", errno);
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
842 }
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
843 }
3630
9682c0e022c6 [gaim-migrate @ 3753]
Rob Flynn <gaim@robflynn.com>
parents: 3572
diff changeset
844 #endif
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
845 if(!fp) {
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
846 g_free(*fpath);
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
847 *fpath = NULL;
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
848 }
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
849 }
3233
96e215745dc0 [gaim-migrate @ 3250]
Jim Seymour <jseymour>
parents: 3232
diff changeset
850 } else {
5211
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
851 gaim_debug(GAIM_DEBUG_ERROR, "gaim_mkstemp",
0241d6b6702d [gaim-migrate @ 5581]
Christian Hammond <chipx86@chipx86.com>
parents: 5205
diff changeset
852 "g_get_tmp_dir() failed!");
3230
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
853 }
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
854
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
855 return fp;
d05dc05bde8a [gaim-migrate @ 3247]
Jim Seymour <jseymour>
parents: 3153
diff changeset
856 }
3478
3da42b64304e [gaim-migrate @ 3532]
Sean Egan <seanegan@gmail.com>
parents: 3474
diff changeset
857
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
858 char *gaim_try_conv_to_utf8(const char *str)
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
859 {
6478
338147ea6896 [gaim-migrate @ 6991]
Christian Hammond <chipx86@chipx86.com>
parents: 6439
diff changeset
860 gsize converted;
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
861 char *utf8;
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
862
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
863 if (str == NULL) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
864 return NULL;
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
865 }
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
866
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
867 if (g_utf8_validate(str, -1, NULL)) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
868 return g_strdup(str);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
869 }
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
870
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
871 utf8 = g_locale_to_utf8(str, -1, &converted, NULL, NULL);
6439
650e9b73ba38 [gaim-migrate @ 6947]
Sean Egan <seanegan@gmail.com>
parents: 6397
diff changeset
872 if (utf8)
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
873 return(utf8);
6439
650e9b73ba38 [gaim-migrate @ 6947]
Sean Egan <seanegan@gmail.com>
parents: 6397
diff changeset
874
650e9b73ba38 [gaim-migrate @ 6947]
Sean Egan <seanegan@gmail.com>
parents: 6397
diff changeset
875 g_free(utf8);
650e9b73ba38 [gaim-migrate @ 6947]
Sean Egan <seanegan@gmail.com>
parents: 6397
diff changeset
876
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
877 utf8 = g_convert(str, -1, "UTF-8", "ISO-8859-15", &converted, NULL, NULL);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
878 if (utf8 && converted == strlen (str)) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
879 return(utf8);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
880 } else if (utf8) {
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
881 g_free(utf8);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
882 }
3698
507eb0a2c7b2 [gaim-migrate @ 3829]
Rob Flynn <gaim@robflynn.com>
parents: 3668
diff changeset
883
4458
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
884 return(NULL);
a46c57f2d58b [gaim-migrate @ 4733]
Luke Schierer <lschiere@pidgin.im>
parents: 4359
diff changeset
885 }
4650
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
886
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
887 char *gaim_getip_from_fd(int fd)
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
888 {
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
889 struct sockaddr addr;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
890 socklen_t namelen = sizeof(addr);
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
891
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
892 if (getsockname(fd, &addr, &namelen))
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
893 return NULL;
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
894
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
895 return g_strdup(inet_ntoa(((struct sockaddr_in *)&addr)->sin_addr));
4938d12f6d48 [gaim-migrate @ 4961]
Mark Doliner <mark@kingant.net>
parents: 4635
diff changeset
896 }
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
897
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
898 gint gaim_utf8_strcasecmp(const gchar *a, const gchar *b) {
5915
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
899 gchar *a_norm=NULL;
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
900 gchar *b_norm=NULL;
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
901 gint ret=-1;
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
902
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
903 if(!g_utf8_validate(a, -1, NULL) || !g_utf8_validate(b, -1, NULL)) {
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
904 gaim_debug(GAIM_DEBUG_ERROR, "gaim_utf8_strcasecmp", "One or both parameters are invalid UTF8\n");
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
905 return ret;
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
906 }
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
907
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
908 a_norm = g_utf8_casefold(a, -1);
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
909 b_norm = g_utf8_casefold(b, -1);
124ca6f5e895 [gaim-migrate @ 6347]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 5874
diff changeset
910 ret = g_utf8_collate(a_norm, b_norm);
4793
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
911 g_free(a_norm);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
912 g_free(b_norm);
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
913 return ret;
677d3cb193a1 [gaim-migrate @ 5113]
Nathan Walp <nwalp@pidgin.im>
parents: 4771
diff changeset
914 }
5515
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
915
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
916 gchar *gaim_strreplace(const gchar *string, const gchar *delimiter, const gchar *replacement) {
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
917 gchar **split;
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
918 gchar *ret;
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
919
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
920 split = g_strsplit(string, delimiter, 0);
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
921 ret = g_strjoinv(replacement, split);
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
922 g_strfreev(split);
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
923
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
924 return ret;
439a05a6b409 [gaim-migrate @ 5914]
Mark Doliner <mark@kingant.net>
parents: 5497
diff changeset
925 }
5826
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
926
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
927 char *gaim_get_size_string(size_t size)
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
928 {
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
929 static const char *size_str[4] = { "bytes", "KB", "MB", "GB" };
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
930 float size_mag;
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
931 int size_index = 0;
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
932
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
933 if (size == -1) {
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
934 return g_strdup(_("Calculating..."));
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
935 }
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
936 else if (size == 0) {
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
937 return g_strdup(_("Unknown."));
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
938 }
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
939 else {
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
940 size_mag = (float)size;
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
941
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
942 while ((size_index < 4) && (size_mag > 1024)) {
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
943 size_mag /= 1024;
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
944 size_index++;
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
945 }
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
946
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
947 return g_strdup_printf("%.2f %s", size_mag, size_str[size_index]);
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
948 }
bd0d0e89cac3 [gaim-migrate @ 6256]
Sean Egan <seanegan@gmail.com>
parents: 5676
diff changeset
949 }