* Header file adjustments to make it work on FreeBSD
[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 #ifdef HAVE_UNISTD_H
11 #include <unistd.h>
12 #endif
13 #include <stdio.h>
14 #ifdef HAVE_FCNTL_H
15 #include <fcntl.h>
16 #endif
17 #include <signal.h>
18 #include <sys/types.h>
19 #include <sys/wait.h>
20 #include <sys/socket.h>
21 #ifdef HAVE_SYS_TIME_H
22 #include <sys/time.h>
23 #endif
24 #ifdef HAVE_LIMITS_H
25 #include <limits.h>
26 #endif
27 #include <netinet/in.h>
28 #include <arpa/inet.h>
29 #include <netdb.h>
30 #include <string.h>
31 #include <pwd.h>
32 #include <errno.h>
33 #include <stdarg.h>
34 #include <pthread.h>
35 #include <signal.h>
36 #include "webcit.h"
37 #include "webserver.h"
38
39 void display_note(long msgnum) {
40         char buf[SIZ];
41         char notetext[SIZ];
42         char display_notetext[SIZ];
43         int in_text = 0;
44         int i;
45
46         wprintf("<IMG ALIGN=MIDDLE SRC=\"/static/storenotes_48x.gif\">\n");
47
48         serv_printf("MSG0 %ld", msgnum);
49         serv_getln(buf, sizeof buf);
50         if (buf[0] != '1') {
51                 wprintf("%s<br />\n", &buf[4]);
52                 return;
53         }
54
55         strcpy(notetext, "");
56         while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
57
58                 /* Fill the buffer to at least 256 characters */
59                 if ( (in_text) && (strlen(notetext) < 256) ) {
60                         strcat(notetext, buf);
61                 }
62
63                 if ( (!in_text) && (!strcasecmp(buf, "text")) ) {
64                         in_text = 1;
65                 }
66         }
67
68         /* Now sanitize the buffer, and shorten it to just a small snippet */
69         for (i=0; i<strlen(notetext); ++i) {
70                 if (isspace(notetext[i])) notetext[i] = ' ';
71         }
72         strcpy(&notetext[72], "...");
73
74         /* Make it HTML-happy and print it. */
75         stresc(display_notetext, notetext, 1, 1);
76         wprintf("%s<br />\n", display_notetext);
77 }