Began making changes to do better handling of character sets.
[citadel.git] / webcit / serv_func.c
index 00024976c9d45955be657e5700ebca8c4956604e..05574c2660b41b70d7a1a857758adf3d2a89bece 100644 (file)
@@ -3,7 +3,7 @@
  */
 /**
  * \defgroup ServFuncs Handles various types of data transfer operations with the Citadel service.
- *
+ * \ingroup CitadelCommunitacion
  */
 
 /*@{*/ 
@@ -86,6 +86,9 @@ void get_serv_info(char *browser_host, char *user_agent)
                case 14:
                        serv_info.serv_supports_ldap = atoi(buf);
                        break;
+               case 15:
+                       serv_info.serv_newuser_disabled = atoi(buf);
+                       break;
                }
                ++a;
        }
@@ -186,14 +189,12 @@ void pullquote_fmout(void) {
 
 /**
  * \brief Transmit message text (in memory) to the server.
- * \param ptr the output buffer
- * \param convert_to_html if set to 1, the message is converted into something
- * which kind of resembles HTML.
+ *
+ * \param ptr Pointer to the message being transmitted
  */
-void text_to_server(char *ptr, int convert_to_html)
+void text_to_server(char *ptr)
 {
-       char buf[SIZ];
-       char conv[4];
+       char buf[256];
        int ch, a, pos;
 
        pos = 0;
@@ -207,15 +208,7 @@ void text_to_server(char *ptr, int convert_to_html)
                                buf[strlen(buf) - 1] = 0;
                        serv_puts(buf);
                        buf[0] = 0;
-                       if (convert_to_html) {
-                               strcat(buf, "<br />");
-                       }
-                       else {
-                               if (ptr[pos] != 0) strcat(buf, " ");
-                       }
-               } else if ((convert_to_html)&&(strchr("#&;`'|*?-~<>^()[]{}$\\", ch) != NULL)) {
-                       sprintf(conv, "%c", ch);
-                       stresc(&buf[strlen(buf)], conv, 0, 0);
+                       if (ptr[pos] != 0) strcat(buf, " ");
                } else {
                        a = strlen(buf);
                        buf[a + 1] = 0;
@@ -232,11 +225,85 @@ void text_to_server(char *ptr, int convert_to_html)
                }
        }
        serv_puts(buf);
+}
+
+
+/**
+ * \brief Transmit message text (in memory) to the server,
+ *        converting to Quoted-Printable encoding as we go.
+ *
+ * \param ptr Pointer to the message being transmitted
+ */
+void text_to_server_qp(char *ptr)
+{
+       char buf[256];
+       int ch, pos;
+       int output_len = 0;
+
+       pos = 0;
+       buf[0] = 0;
+       output_len = 0;
+
+       while (ptr[pos] != 0) {
+               ch = ptr[pos++];
+
+               if (ch == 13) {
+                       /* ignore carriage returns */
+               }
+               else if (ch == 10) {
+                       /* hard line break */
+                       if (output_len > 0) {
+                               if (isspace(buf[output_len-1])) {
+                                       sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]);
+                                       output_len += 2;
+                               }
+                       }
+                       buf[output_len++] = 0;
+                       serv_puts(buf);
+                       output_len = 0;
+               }
+               else if (ch == 9) {
+                       buf[output_len++] = ch;
+               }
+               else if ( (ch >= 32) && (ch <= 60) ) {
+                       buf[output_len++] = ch;
+               }
+               else if ( (ch >= 62) && (ch <= 126) ) {
+                       buf[output_len++] = ch;
+               }
+               else {
+                       sprintf(&buf[output_len], "=%02X", ch);
+                       output_len += 3;
+               }
+               
+               if (output_len > 72) {
+                       /* soft line break */
+                       if (isspace(buf[output_len-1])) {
+                               sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]);
+                               output_len += 2;
+                       }
+                       buf[output_len++] = '=';
+                       buf[output_len++] = 0;
+                       serv_puts(buf);
+                       output_len = 0;
+               }
+       }
 
+       /* end of data - transmit anything that's left */
+       if (output_len > 0) {
+               if (isspace(buf[output_len-1])) {
+                       sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]);
+                       output_len += 2;
+               }
+               buf[output_len++] = 0;
+               serv_puts(buf);
+               output_len = 0;
+       }
 }
 
 
 
+
 /**
  * \brief translate server message output to text
  * (used for editing room info files and such)