annotate util.c @ 266:d3e2b2e58828

adapted for laconica 0.6.4 in identi.ca service.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Fri, 12 Dec 2008 17:43:56 +0900
parents c2944685ac8e
children 18e71951ff27
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
1 #include "pidgin-twitter.h"
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
2
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
3 extern GRegex *regp[];
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
4
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
5 /* prototypes */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
6 static gchar *twitter_memrchr(const gchar *s, int c, size_t n);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
7
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
8
265
c2944685ac8e - update README to meet 0.8.1.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 256
diff changeset
9 /* functions */
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
10
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
11 /* this function has been taken from autoaccept plugin */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
12 gboolean
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
13 ensure_path_exists(const char *dir)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
14 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
15 if (!g_file_test(dir, G_FILE_TEST_IS_DIR)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
16 if (purple_build_dir(dir, S_IRUSR | S_IWUSR | S_IXUSR))
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
17 return FALSE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
18 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
19
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
20 return TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
21 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
22
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
23 static gchar *
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
24 twitter_memrchr(const gchar *s, int c, size_t n)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
25 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
26 int nn = n;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
27
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
28 g_return_val_if_fail(s != NULL, NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
29
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
30 while(nn+1) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
31 if((int)*(s+nn) == c)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
32 return (gchar *)(s+nn);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
33 nn--;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
34 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
35 return NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
36 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
37
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
38 static gchar *html_tags[] = {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
39 "<a href=",
266
d3e2b2e58828 adapted for laconica 0.6.4 in identi.ca service.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 265
diff changeset
40 "<a class=",
254
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
41 "</a>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
42 "<b>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
43 "</b>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
44 "<p>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
45 "</p>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
46 "<div ",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
47 "</div>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
48 "<span ",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
49 "</span>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
50 "<body>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
51 "<body ",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
52 "</body>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
53 "<i>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
54 "</i>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
55 "<font ",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
56 "</font>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
57 "<br>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
58 "<br/>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
59 "<img ",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
60 "<html>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
61 "<html ",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
62 "</html>",
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
63 NULL
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
64 };
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
65
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
66 gchar *
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
67 strip_html_markup(const gchar *src)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
68 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
69 gchar *head, *tail; /* head and tail of html */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
70 gchar *begin, *end; /* begin:< end:> */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
71 gchar *html, *str; /* copied src and string to be returned */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
72 /* gchar *vis1, *vis2; */ /* begin and end of address part */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
73 gchar *startp; /* starting point marker */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
74 gchar **tagp; /* tag iterator */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
75 gchar *tmp, *tmp2; /* scratches */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
76
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
77 g_return_val_if_fail(src != NULL, NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
78
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
79 const gchar *ptr, *ent;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
80 gchar *ptr2;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
81 gint entlen;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
82
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
83 /* unescape &x; */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
84 html = g_malloc0(strlen(src) + 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
85 ptr2 = html;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
86 for(ptr = src; *ptr; ) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
87 if(*ptr == '&') {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
88 ent = purple_markup_unescape_entity(ptr, &entlen);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
89 if(ent != NULL) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
90 while(*ent) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
91 *ptr2++ = *ent++;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
92 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
93 ptr += entlen;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
94 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
95 else {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
96 *ptr2++ = *ptr++;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
97 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
98 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
99 else {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
100 *ptr2++ = *ptr++;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
101 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
102 } /* for */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
103
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
104 str = g_strdup("\0");
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
105
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
106 head = html;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
107 tail = head + strlen(html);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
108 startp = head;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
109
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
110 loop:
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
111 begin = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
112 end = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
113
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
114 if(startp >= tail) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
115 g_free(html);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
116 return str;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
117 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
118
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
119 end = strchr(startp, '>');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
120 if(end) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
121 begin = twitter_memrchr(startp, '<', end - startp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
122 if(begin < startp)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
123 begin = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
124
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
125 if(!begin) { /* '>' found but no corresponding '<' */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
126 tmp = g_strndup(startp, end - startp + 1); /* concat until '>' */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
127 tmp2 = g_strconcat(str, tmp, NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
128 g_free(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
129 g_free(tmp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
130 str = tmp2;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
131 startp = end + 1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
132 goto loop;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
133 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
134 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
135 else { /* neither '>' nor '<' were found */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
136 tmp = g_strconcat(str, startp, NULL); /* concat the rest */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
137 g_free(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
138 str = tmp;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
139 g_free(html);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
140 return str;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
141 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
142
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
143 /* here, both < and > are found */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
144 /* concatenate leading part to dest */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
145 tmp = g_strndup(startp, begin - startp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
146 tmp2 = g_strconcat(str, tmp, NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
147 g_free(tmp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
148 g_free(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
149 str = tmp2;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
150
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
151 /* find tag */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
152 for(tagp = html_tags; *tagp; tagp++) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
153 if(!g_ascii_strncasecmp(begin, *tagp, strlen(*tagp))) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
154 /* we found a valid tag */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
155 /* if tag is <a href=, extract address. */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
156 #if 0
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
157 if(!strcmp(*tagp, "<a href=")) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
158 vis1 = NULL; vis2 = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
159
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
160 vis1 = strchr(begin, '\'');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
161 if(vis1)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
162 vis2 = strchr(vis1+1, '\'');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
163 if(!vis1) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
164 vis1 = strchr(begin, '\"');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
165 if(vis1)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
166 vis2 = strchr(vis1+1, '\"');
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
167 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
168 if(vis1 && vis2) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
169 *vis2 = '\0';
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
170 /* generate "[ http://example.com/ ] anchor " */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
171 tmp = g_strconcat(str, "[ ", vis1+1, " ]", " ", NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
172 g_free(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
173 str = tmp;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
174 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
175 startp = end + 1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
176 goto loop;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
177 } /* <a href= */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
178 else {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
179 /* anything else: discard whole <>. */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
180 startp = end + 1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
181 goto loop;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
182 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
183 #else
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
184 /* anything else: discard whole <>. */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
185 startp = end + 1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
186 goto loop;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
187 #endif
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
188 } /* valid tag */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
189 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
190
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
191 /* no valid tag was found: copy <brabra> */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
192 tmp = g_strndup(begin, end - begin + 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
193 tmp2 = g_strconcat(str, tmp, NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
194 g_free(tmp);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
195 g_free(str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
196 str = tmp2;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
197 startp = end + 1;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
198 goto loop;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
199 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
200
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
201 /* string utilities */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
202 void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
203 escape(gchar **str)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
204 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
205 GMatchInfo *match_info = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
206 gchar *newstr = NULL, *match = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
207 gboolean flag = FALSE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
208
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
209 /* search genuine command */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
210 g_regex_match(regp[COMMAND], *str, 0, &match_info);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
211 while(g_match_info_matches(match_info)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
212 match = g_match_info_fetch(match_info, 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
213 twitter_debug("command = %s\n", match);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
214 g_free(match);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
215 g_match_info_next(match_info, NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
216 flag = TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
217 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
218 g_match_info_free(match_info);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
219 match_info = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
220
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
221 if(flag)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
222 return;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
223
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
224 /* if not found, check pseudo command */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
225 g_regex_match(regp[PSEUDO], *str, 0, &match_info);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
226 while(g_match_info_matches(match_info)) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
227 match = g_match_info_fetch(match_info, 1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
228 twitter_debug("pseudo = %s\n", match);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
229 g_free(match);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
230 g_match_info_next(match_info, NULL);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
231 flag = TRUE;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
232 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
233 g_match_info_free(match_info);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
234 match_info = NULL;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
235
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
236 /* if there is pseudo one, escape it */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
237 if(flag) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
238 /* put ". " to the beginning of buffer */
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
239 newstr = g_strdup_printf(". %s", *str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
240 twitter_debug("*str = %s newstr = %s\n", *str, newstr);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
241 g_free(*str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
242 *str = newstr;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
243 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
244 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
245
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
246 void
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
247 strip_markup(gchar **str, gboolean escape)
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
248 {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
249 gchar *plain;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
250
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
251 plain = strip_html_markup(*str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
252 g_free(*str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
253 if(escape) {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
254 *str = g_markup_escape_text(plain, -1);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
255 g_free(plain);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
256 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
257 else {
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
258 *str = plain;
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
259 }
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
260 twitter_debug("result=%s\n", *str);
c2620a99622b - divided the source file into several parts.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents:
diff changeset
261 }
256
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
262
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
263 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
264 is_twitter_account(PurpleAccount *account, const char *name)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
265 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
266 const gchar *proto = purple_account_get_protocol_id(account);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
267
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
268 if(g_strstr_len(name, 19, "twitter@twitter.com") &&
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
269 g_strstr_len(proto, 11, "prpl-jabber")) {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
270 return TRUE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
271 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
272
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
273 return FALSE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
274 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
275
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
276 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
277 is_twitter_conv(PurpleConversation *conv)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
278 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
279 g_return_val_if_fail(conv != NULL, FALSE);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
280
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
281 const char *name = purple_conversation_get_name(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
282 PurpleAccount *account = purple_conversation_get_account(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
283
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
284 return is_twitter_account(account, name);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
285 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
286
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
287 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
288 is_wassr_account(PurpleAccount *account, const char *name)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
289 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
290 const gchar *proto = purple_account_get_protocol_id(account);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
291
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
292 if(g_strstr_len(name, 18, "wassr-bot@wassr.jp") &&
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
293 g_strstr_len(proto, 11, "prpl-jabber")) {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
294 return TRUE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
295 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
296
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
297 return FALSE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
298 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
299
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
300 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
301 is_wassr_conv(PurpleConversation *conv)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
302 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
303 g_return_val_if_fail(conv != NULL, FALSE);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
304
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
305 const char *name = purple_conversation_get_name(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
306 PurpleAccount *account = purple_conversation_get_account(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
307
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
308 return is_wassr_account(account, name);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
309 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
310
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
311 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
312 is_identica_account(PurpleAccount *account, const char *name)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
313 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
314 const gchar *proto = purple_account_get_protocol_id(account);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
315
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
316 if(g_strstr_len(name, 16, "update@identi.ca") &&
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
317 g_strstr_len(proto, 11, "prpl-jabber")) {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
318 return TRUE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
319 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
320
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
321 return FALSE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
322 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
323
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
324 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
325 is_identica_conv(PurpleConversation *conv)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
326 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
327 g_return_val_if_fail(conv != NULL, FALSE);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
328
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
329 const char *name = purple_conversation_get_name(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
330 PurpleAccount *account = purple_conversation_get_account(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
331
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
332 return is_identica_account(account, name);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
333 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
334
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
335 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
336 is_jisko_account(PurpleAccount *account, const char *name)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
337 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
338 const gchar *proto = purple_account_get_protocol_id(account);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
339
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
340 if(g_strstr_len(name, 16, "bot@jisko.net") &&
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
341 g_strstr_len(proto, 11, "prpl-jabber")) {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
342 return TRUE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
343 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
344
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
345 return FALSE;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
346 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
347
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
348 gboolean
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
349 is_jisko_conv(PurpleConversation *conv)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
350 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
351 g_return_val_if_fail(conv != NULL, FALSE);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
352
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
353 const char *name = purple_conversation_get_name(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
354 PurpleAccount *account = purple_conversation_get_account(conv);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
355
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
356 return is_jisko_account(account, name);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
357 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
358
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
359 gint
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
360 get_service_type_by_account(PurpleAccount *account, const char *sender)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
361 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
362 gint service = unknown_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
363
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
364 g_return_val_if_fail(account != NULL, unknown_service);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
365 g_return_val_if_fail(sender != NULL, unknown_service);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
366
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
367 if(is_twitter_account(account, sender))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
368 service = twitter_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
369 else if(is_wassr_account(account, sender))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
370 service = wassr_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
371 else if(is_identica_account(account, sender))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
372 service = identica_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
373 else if(is_jisko_account(account, sender))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
374 service = jisko_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
375
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
376 return service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
377 }
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
378
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
379 gint
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
380 get_service_type(PurpleConversation *conv)
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
381 {
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
382 gint service = unknown_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
383
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
384 g_return_val_if_fail(conv != NULL, unknown_service);
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
385
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
386 if(is_twitter_conv(conv))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
387 service = twitter_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
388 else if(is_wassr_conv(conv))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
389 service = wassr_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
390 else if(is_identica_conv(conv))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
391 service = identica_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
392 else if(is_jisko_conv(conv))
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
393 service = jisko_service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
394
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
395 return service;
9fb8f597adf3 - moved is_*_account() functions to util.c.
Yoshiki Yazawa <yaz@honeyplanet.jp>
parents: 254
diff changeset
396 }