2 aim.c - FireTalk generic AIM definitions
3 Copyright (C) 2000 Ian Gulliver
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of version 2 of the GNU General Public License as
7 published by the Free Software Foundation.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "firetalk-int.h"
27 char *aim_interpolate_variables(const char *const input
, const char *const nickname
) {
28 static char output
[16384]; /* 2048 / 2 * 16 + 1 (max size with a string full of %n's, a 16-char nick and a null at the end) */
29 int o
= 0,gotpercent
= 0;
31 char date
[15],tim
[15];
33 { /* build the date and time */
49 snprintf(tim
, sizeof(tim
), "%d:%02d:%02d %s", hour
, t
->tm_min
, t
->tm_sec
, (am
== 1)?"AM":"PM");
50 snprintf(date
, sizeof(date
), "%d/%d/%d", t
->tm_mon
+1, t
->tm_mday
, t
->tm_year
+1900);
52 nl
= strlen(nickname
);
56 for (i
= 0; i
< l
; i
++)
59 if (gotpercent
== 1) {
67 if (gotpercent
== 1) {
69 memcpy(&output
[o
],nickname
,nl
);
75 if (gotpercent
== 1) {
77 memcpy(&output
[o
],date
,dl
);
83 if (gotpercent
== 1) {
85 memcpy(&output
[o
],tim
,tl
);
91 if (gotpercent
== 1) {
95 output
[o
++] = input
[i
];
101 const char *aim_normalize_room_name(const char *const name
) {
102 static char newname
[2048];
106 if (strchr(name
+1, ':') != NULL
)
108 if (strlen(name
) >= (sizeof(newname
)-2))
111 strcpy(newname
, "4:");
112 strcpy(newname
+2, name
);
117 #define STRNCMP(x,y) (strncmp((x), (y), sizeof(y)-1))
119 *htmlclean(const char *str
) {
124 for (i
= 0; (str
[i
] != 0) && (b
< sizeof(buf
)-1); i
++)
125 if (STRNCMP(str
+i
, ">") == 0) {
127 i
+= sizeof(">")-2;
128 } else if (STRNCMP(str
+i
, "<") == 0) {
130 i
+= sizeof("<")-2;
131 } else if (STRNCMP(str
+i
, """) == 0) {
133 i
+= sizeof(""")-2;
134 } else if (STRNCMP(str
+i
, " ") == 0) {
136 i
+= sizeof(" ")-2;
137 } else if (STRNCMP(str
+i
, "&") == 0) {
139 i
+= sizeof("&")-2;
148 #define ECT_TOKEN "<font ECT=\""
149 #define ECT_ENDING "\"></font>"
150 char *aim_handle_ect(void *conn
, const char *const from
,
151 char *message
, const int reply
) {
152 char *ectbegin
, *ectend
, *textbegin
, *textend
;
154 while ((ectbegin
= strstr(message
, ECT_TOKEN
)) != NULL
) {
155 textbegin
= ectbegin
+sizeof(ECT_TOKEN
)-1;
157 if ((textend
= strstr(textbegin
, ECT_ENDING
)) != NULL
) {
161 ectend
= textend
+sizeof(ECT_ENDING
)-1;
163 if ((arg
= strchr(textbegin
, ' ')) != NULL
) {
167 firetalk_callback_subcode_reply(conn
, from
, textbegin
, htmlclean(arg
));
169 firetalk_callback_subcode_request(conn
, from
, textbegin
, htmlclean(arg
));
172 firetalk_callback_subcode_reply(conn
, from
, textbegin
, NULL
);
174 firetalk_callback_subcode_request(conn
, from
, textbegin
, NULL
);
176 memmove(ectbegin
, ectend
, strlen(ectend
)+1);
183 const char *firetalk_nhtmlentities(const char *str
, int len
) {
184 static char buf
[1024];
187 for (i
= 0; (str
[i
] != 0) && (b
< sizeof(buf
)-6-1) && ((len
< 0) || (i
< len
)); i
++)
230 const char *firetalk_htmlentities(const char *str
) {
231 return(firetalk_nhtmlentities(str
, -1));