+
+/*
+ * Back end function used by make_message() and similar functions
+ */
+char *CtdlReadMessageBody(char *terminator, size_t maxlen) {
+ char buf[256];
+ size_t message_len = 0;
+ size_t buffer_len = 0;
+ char *ptr, *append;
+ char *m;
+
+ m = mallok(4096);
+ if (m == NULL) {
+ while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) ;;
+ return(NULL);
+ } else {
+ buffer_len = 4096;
+ m[0] = 0;
+ message_len = 0;
+ }
+ /* read in the lines of message text one by one */
+ append = NULL;
+ while ( (client_gets(buf)>0) && strcmp(buf, terminator) ) {
+
+ /* augment the buffer if we have to */
+ if ((message_len + strlen(buf) + 2) > buffer_len) {
+ lprintf(9, "realloking\n");
+ ptr = reallok(m, (buffer_len * 2) );
+ if (ptr == NULL) { /* flush if can't allocate */
+ while ( (client_gets(buf)>0) &&
+ strcmp(buf, terminator)) ;;
+ return(m);
+ } else {
+ buffer_len = (buffer_len * 2);
+ m = ptr;
+ append = NULL;
+ lprintf(9, "buffer_len is %d\n", buffer_len);
+ }
+ }
+
+ if (append == NULL) append = m;
+ while (strlen(append) > 0) ++append;
+ strcpy(append, buf);
+ strcat(append, "\n");
+ message_len = message_len + strlen(buf) + 1;
+
+ /* if we've hit the max msg length, flush the rest */
+ if (message_len >= maxlen) {
+ while ( (client_gets(buf)>0) && strcmp(buf, terminator)) ;;
+ return(m);
+ }
+ }
+ return(m);
+}
+
+
+
+