2 * - by Richard W.M. Jones <rich@annexia.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: message.c,v 1.4 2003/02/22 12:56:26 rich Exp $
40 #include <pthr_iolib.h>
43 #include <ml_smarttext.h>
48 type_posting, type_enter, type_leave, type_blank
53 enum message_type type; /* Type of message. */
56 int hh, mm; /* Time of posting. */
57 const char *body; /* Message body (turned to HTML). */
58 int authorid; /* Author user ID (0 == anonymous). */
59 const char *original_ip; /* IP address as a string. */
62 const char *username; /* Printable username (null == anonymous). */
66 new_message_posting (pool pool, int hh, int mm,
67 int authorid, const char *username,
68 const char *original_ip,
71 message m = pmalloc (pool, sizeof *m);
73 m->type = type_posting;
76 m->u.posting.authorid = authorid;
77 m->u.posting.original_ip = pstrdup (pool, original_ip);
78 m->u.posting.body = ml_smarttext_to_html (pool, body);
79 m->username = username ? pstrdup (pool, username) : 0;
85 new_message_enter (pool pool, const char *username)
87 message m = pmalloc (pool, sizeof *m);
90 m->username = username ? pstrdup (pool, username) : 0;
96 new_message_leave (pool pool, const char *username)
98 message m = pmalloc (pool, sizeof *m);
100 m->type = type_leave;
101 m->username = username ? pstrdup (pool, username) : 0;
107 new_message_blank (pool pool)
109 message m = pmalloc (pool, sizeof *m);
111 m->type = type_blank;
117 colour_for_user (int userid)
121 case 0: return "#990033"; /* Also used for anonymous users. */
122 case 1: return "#ff0066";
123 case 2: return "#cc00cc";
124 case 3: return "#6600cc";
125 case 4: return "#3333ff";
126 case 5: return "#003366";
127 case 6: return "#009999";
128 case 7: return "#ff9900";
135 message_show (const message m, io_handle io)
137 const char *username;
139 const char *anon = "anonymous";
144 /* Construct the username. */
145 if (m->u.posting.authorid)
146 /* Ugh. We promise not to modify it! */
147 username = m->username;
150 int len = strlen (anon) + strlen (m->u.posting.original_ip) + 2;
154 snprintf (u, len, "%s@%s", anon, m->u.posting.original_ip);
159 colour = colour_for_user (m->u.posting.authorid);
164 "<span class=\"ml_chat_time\">%02d:%02d</span> "
165 "<span class=\"ml_chat_username\"><%s></span> "
166 "<span class=\"ml_chat_message\" "
167 "style=\"color: %s\">%s</span><br>",
168 m->u.posting.hh, m->u.posting.mm, username, colour,
177 "<span class=\"ml_chat_enterleave\">"
178 "<span class=\"ml_chat_username\">%s</span> "
179 "has entered the room</span><br>",
185 "<span class=\"ml_chat_enterleave\">"
186 "an anonymous user has entered the room</span><br>");
196 "<span class=\"ml_chat_enterleave\">"
197 "<span class=\"ml_chat_username\">%s</span> "
198 "has left the room</span><br>",
204 "<span class=\"ml_chat_enterleave\">"
205 "an anonymous user has left the room</span><br>");