* *** HUGE CHANGES *** *** WARNING: NOT FULLY FUNCTIONAL ***
[citadel.git] / webcit / notes.c
1 /*
2  * $Id$
3  *
4  * Functions which handle "sticky notes"
5  *
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <sys/socket.h>
17 #include <limits.h>
18 #include <string.h>
19 #include <pwd.h>
20 #include <errno.h>
21 #include <stdarg.h>
22 #include <time.h>
23 #include "webcit.h"
24 #include "webserver.h"
25
26 void display_note(long msgnum) {
27         char buf[SIZ];
28         char notetext[SIZ];
29         char display_notetext[SIZ];
30         int in_text = 0;
31         int i;
32
33         wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/note.gif\">\n");
34
35         serv_printf("MSG0 %ld", msgnum);
36         serv_gets(buf);
37         if (buf[0] != '1') {
38                 wprintf("%s<br />\n", &buf[4]);
39                 return;
40         }
41
42         strcpy(notetext, "");
43         while (serv_gets(buf), strcmp(buf, "000")) {
44
45                 /* Fill the buffer to at least 256 characters */
46                 if ( (in_text) && (strlen(notetext) < 256) ) {
47                         strcat(notetext, buf);
48                 }
49
50                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
51                         in_text = 1;
52                 }
53         }
54
55         /* Now sanitize the buffer, and shorten it to just a small snippet */
56         for (i=0; i<strlen(notetext); ++i) {
57                 if (isspace(notetext[i])) notetext[i] = ' ';
58         }
59         strcpy(&notetext[72], "...");
60
61         /* Make it HTML-happy and print it. */
62         stresc(display_notetext, notetext, 1, 1);
63         wprintf("%s<br />\n", display_notetext);
64 }