]> code.citadel.org Git - citadel.git/blobdiff - webcit/serv_func.c
* Updated message reading to use the new MSG4 command, so we can do output
[citadel.git] / webcit / serv_func.c
index 2ee6b39f0b6daf7993c70ce50243654b21abdc37..d8c41ad3904e3ff67481406ac2f547b0a8673017 100644 (file)
 struct serv_info serv_info;
 
 /*
- * get info about the server we've WC->connected to
+ * get info about the server we've connected to
  */
 void get_serv_info(char *browser_host, char *user_agent)
 {
-       char buf[256];
+       char buf[SIZ];
        int a;
 
+       /* Tell the server what kind of client is connecting */
        serv_printf("IDEN %d|%d|%d|%s|%s",
                DEVELOPER_ID,
                CLIENT_ID,
@@ -48,6 +49,11 @@ void get_serv_info(char *browser_host, char *user_agent)
        );
        serv_gets(buf);
 
+       /* Tell the server what kind of richtext we prefer */
+       serv_puts("MSGP text/html|text/plain");
+       serv_gets(buf);
+
+       /* Now ask the server to tell us a little bit about itself... */
        serv_puts("INFO");
        serv_gets(buf);
        if (buf[0] != '1')
@@ -100,14 +106,14 @@ void fmout(FILE * fp)
 
        int intext = 0;
        int bq = 0;
-       char buf[256];
+       char buf[SIZ];
 
        wprintf("<DIV ALIGN=JUSTIFY>\n");
        while (1) {
                if (fp == NULL)
                        serv_gets(buf);
                if (fp != NULL) {
-                       if (fgets(buf, 256, fp) == NULL)
+                       if (fgets(buf, SIZ, fp) == NULL)
                                strcpy(buf, "000");
                        buf[strlen(buf) - 1] = 0;
                }
@@ -149,23 +155,36 @@ void fmout(FILE * fp)
 
 
 /*
- * transmit message text (in memory) to the server
+ * Transmit message text (in memory) to the server.
+ * If convert_to_html is set to 1, the message is converted into something
+ * which kind of resembles HTML.
  */
-void text_to_server(char *ptr)
+void text_to_server(char *ptr, int convert_to_html)
 {
-       char buf[256];
+       char buf[SIZ];
        int ch, a, pos;
 
-       pos = 0;
+       if (convert_to_html) {
+               serv_puts("<HTML><BODY>");
+       }
 
+       pos = 0;
        strcpy(buf, "");
+
        while (ptr[pos] != 0) {
                ch = ptr[pos++];
                if (ch == 10) {
-                       while (isspace(buf[strlen(buf) - 1]))
+                       while ( (isspace(buf[strlen(buf) - 1]))
+                         && (strlen(buf) > 1) )
                                buf[strlen(buf) - 1] = 0;
                        serv_puts(buf);
                        strcpy(buf, "");
+                       if (convert_to_html) {
+                               strcat(buf, "<BR>");
+                       }
+                       else {
+                               if (ptr[pos] != 0) strcat(buf, " ");
+                       }
                } else {
                        a = strlen(buf);
                        buf[a + 1] = 0;
@@ -182,6 +201,11 @@ void text_to_server(char *ptr)
                }
        }
        serv_puts(buf);
+
+       if (convert_to_html) {
+               serv_puts("</BODY></HTML>\n");
+       }
+
 }
 
 
@@ -195,7 +219,7 @@ void text_to_server(char *ptr)
  */
 void server_to_text()
 {
-       char buf[256];
+       char buf[SIZ];
 
        int count = 0;