From: Wilfried Göesgens Date: Sun, 4 Nov 2007 23:19:17 +0000 (+0000) Subject: * dump message headers on artv dump X-Git-Tag: v7.86~2844 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=c1cf1c8630e59eab79e4eea45ed82a5f71edd0d4 * dump message headers on artv dump * some more tweaking on buffered reading. --- diff --git a/citadel/citadel_ipc.c b/citadel/citadel_ipc.c index 6b097551d..891facb34 100644 --- a/citadel/citadel_ipc.c +++ b/citadel/citadel_ipc.c @@ -2640,7 +2640,7 @@ static void serv_read(CtdlIPC *ipc, char *buf, unsigned int bytes) /* * send binary to server */ -static void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes) +void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes) { unsigned int bytes_written = 0; int retval; @@ -2858,25 +2858,26 @@ int ReadNetworkChunk(CtdlIPC* ipc) { fd_set read_fd; + int tries; int ret = 0; int err = 0; struct timeval tv; + size_t n; tv.tv_sec = 1; - tv.tv_usec = 0; + tv.tv_usec = 1000; + tries = 0; + n = 0; while (1) { + errno=0; FD_ZERO(&read_fd); FD_SET(ipc->sock, &read_fd); ret = select(ipc->sock+1, &read_fd, NULL, NULL, &tv); - if (ret == -1) { - if (!(errno == EINTR || errno == EAGAIN)) - fprintf(stderr, "\nselect failed: %d %s\n", err, strerror(err)); - return -1; - } - if (ret != 0) { - size_t n; +// fprintf(stderr, "\nselect failed: %d %d %s\n", ret, err, strerror(err)); + + if (ret > 0) { *(ipc->BufPtr) = '\0'; n = read(ipc->sock, ipc->BufPtr, ipc->BufSize - (ipc->BufPtr - ipc->Buf) - 1); @@ -2885,7 +2886,28 @@ ReadNetworkChunk(CtdlIPC* ipc) ipc->BufUsed += n; return n; } + else + return n; } + else if (ret < 0) { + if (!(errno == EINTR || errno == EAGAIN)) + error_printf( "\nselect failed: %d %s\n", err, strerror(err)); + return -1; + }/* + else { + tries ++; + if (tries >= 10) + n = read(ipc->sock, ipc->BufPtr, ipc->BufSize - (ipc->BufPtr - ipc->Buf) - 1); + if (n > 0) { + ipc->BufPtr[n]='\0'; + ipc->BufUsed += n; + return n; + } + else { + connection_died(ipc, 0); + return -1; + } + }*/ } } @@ -2894,9 +2916,11 @@ ReadNetworkChunk(CtdlIPC* ipc) */ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf) { - int i; + int i, ntries; char *aptr, *bptr, *aeptr, *beptr; +// error_printf("---\n"); + beptr = buf + SIZ; #if defined(HAVE_OPENSSL) if (ipc->ssl) { @@ -2928,10 +2952,12 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf) ipc->BufPtr = ipc->Buf; } + ntries = 0; +// while ((ipc->BufUsed == 0)||(ntries++ > 10)) if (ipc->BufUsed == 0) - while ( ReadNetworkChunk(ipc) < 0 ) - sleep (1); + ReadNetworkChunk(ipc); +//// if (ipc->BufUsed != 0) while (1) bptr = buf; while (1) @@ -2951,7 +2977,7 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf) while ((aptr < aeptr ) && (*(aptr + 1) == '\0') ) aptr ++; *(bptr++) = '\0'; -// fprintf(stderr, "parsing %d %d %d - %d %d %d\n", ipc->BufPtr - ipc->Buf, aptr - ipc->BufPtr, ipc->BufUsed , *aptr, *(aptr-1), *(aptr+1)); +// fprintf(stderr, "parsing %d %d %d - %d %d %d %s\n", ipc->BufPtr - ipc->Buf, aptr - ipc->BufPtr, ipc->BufUsed , *aptr, *(aptr-1), *(aptr+1), buf); if ((bptr > buf + 1) && (*(bptr-1) == '\r')) *(--bptr) = '\0'; @@ -2965,6 +2991,7 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf) ipc->BufUsed = 0; ipc->BufPtr = ipc->Buf; } +// error_printf("----bla6\n"); return; }/* should we move our read stuf to the bufferstart so we have more space at the end? */ @@ -2984,9 +3011,14 @@ static void CtdlIPC_getline(CtdlIPC* ipc, char *buf) ipc->BufSize = NewBufSize; } if (ReadNetworkChunk(ipc) <0) + { +// error_printf("----bla\n"); return; + } } +/// error_printf("----bl45761%s\nipc->BufUsed"); } +// error_printf("----bla1\n"); } void CtdlIPC_chat_recv(CtdlIPC* ipc, char* buf) diff --git a/citadel/debian/rules b/citadel/debian/rules index c0ca8031c..4c651a403 100755 --- a/citadel/debian/rules +++ b/citadel/debian/rules @@ -13,7 +13,7 @@ CFLAGS = -Wall -g EXTRA_ARGS= PROFILE_ARGS= -#to enable debugging: export DEB_BUILD_OPTIONS="debug profiling" +#to enable debugging: export DEB_BUILD_OPTIONS="debug profiling threadoff" ifneq (,$(findstring profiling,$(DEB_BUILD_OPTIONS))) PROFILE_ARGS= --with-gprof endif @@ -24,6 +24,12 @@ else CFLAGS += -O2 endif +ifneq (,$(findstring threadoff,$(DEB_BUILD_OPTIONS))) + THREAD_ARGS=--without-threaded-client +else + THREAD_ARGS= +endif + configure: configure-stamp configure-stamp: dh_testdir @@ -44,7 +50,7 @@ configure-stamp: --with-ldap \ --with-libical \ --with-libsieve \ - --enable-debug $(EXTRA_ARGS) $(PROFILE_ARGS) + --enable-debug $(EXTRA_ARGS) $(PROFILE_ARGS) $(THREAD_ARGS) touch configure-stamp diff --git a/citadel/modules/vandelay/serv_vandelay.c b/citadel/modules/vandelay/serv_vandelay.c index c50f4dc2a..c79e1eeee 100644 --- a/citadel/modules/vandelay/serv_vandelay.c +++ b/citadel/modules/vandelay/serv_vandelay.c @@ -366,10 +366,6 @@ void artv_export_message(long msgnum) { void artv_dump_message(long msgnum) { struct MetaData smi; struct CtdlMessage *msg; - struct ser_ret smr; - FILE *fp; - char buf[SIZ]; - char tempfile[PATH_MAX]; msg = CtdlFetchMessage(msgnum, 1); if (msg == NULL) return; /* fail silently */ @@ -380,27 +376,9 @@ void artv_dump_message(long msgnum) { cprintf(" MetaRefcount: %d\n", smi.meta_refcount); cprintf(" MetaContentType: %s\n", smi.meta_content_type); - serialize_message(&smr, msg); + dump_message(msg, 80); CtdlFreeMessage(msg); - /* write it in base64 * / - CtdlMakeTempFileName(tempfile, sizeof tempfile); - snprintf(buf, sizeof buf, "%s -e >%s", file_base64, tempfile); - fp = popen(buf, "w"); - fwrite(smr.ser, smr.len, 1, fp); - pclose(fp); - - free(smr.ser); - - fp = fopen(tempfile, "r"); - unlink(tempfile); - if (fp != NULL) { - while (fgets(buf, sizeof(buf), fp) != NULL) { - buf[strlen(buf)-1] = 0; - cprintf("%s\n", buf); - } - fclose(fp); - }*/ cprintf("%s\n", END_OF_MESSAGE); } @@ -513,7 +491,7 @@ void artv_do_dump(void) { /* export the config file (this is done using x-macros) */ cprintf("config\n"); -#include "artv_serialize.h" +#include "artv_dump.h" #include "dtds/config-defs.h" #include "undef_data.h" diff --git a/citadel/msgbase.c b/citadel/msgbase.c index f914c8526..733e34ad6 100644 --- a/citadel/msgbase.c +++ b/citadel/msgbase.c @@ -1811,21 +1811,26 @@ START_TEXT: * what message transfer format is in use. */ if (TheMessage->cm_format_type == FMT_FIXED) { + int buflen; if (mode == MT_MIME) { cprintf("Content-type: text/plain\n\n"); } - strcpy(buf, ""); + *buf = '\0'; + buflen = 0; while (ch = *mptr++, ch > 0) { if (ch == 13) ch = 10; - if ((ch == 10) || (strlen(buf) > 250)) { + if ((ch == 10) || (buflen > 250)) { + buf[buflen] = '\0'; cprintf("%s%s", buf, nl); - strcpy(buf, ""); + *buf = '\0'; + buflen = 0; } else { - buf[strlen(buf) + 1] = 0; - buf[strlen(buf)] = ch; + buf[buflen] = ch; + buflen++; } } + buf[buflen] = '\0'; if (!IsEmptyStr(buf)) cprintf("%s%s", buf, nl); } @@ -2315,6 +2320,43 @@ void serialize_message(struct ser_ret *ret, /* return values */ } +/* + * Serialize a struct CtdlMessage into the format used on disk and network. + * + * This function loads up a "struct ser_ret" (defined in server.h) which + * contains the length of the serialized message and a pointer to the + * serialized message in memory. THE LATTER MUST BE FREED BY THE CALLER. + */ +void dump_message(struct CtdlMessage *msg, /* unserialized msg */ + long Siz) /* how many chars ? */ +{ + size_t wlen; + int i; + static char *forder = FORDER; + char *buf; + + /* + * Check for valid message format + */ + if (is_valid_message(msg) == 0) { + lprintf(CTDL_ERR, "dump_message() aborting due to invalid message\n"); + return; + } + + buf = (char*) malloc (Siz + 1); + + wlen = 3; + + for (i=0; i<26; ++i) if (msg->cm_fields[(int)forder[i]] != NULL) { + snprintf (buf, Siz, " msg[%c] = %s ...\n", (char) forder[i], + msg->cm_fields[(int)forder[i]]); + client_write (buf, strlen(buf)); + } + + return; +} + + /* * Check to see if any messages already exist in the current room which diff --git a/citadel/msgbase.h b/citadel/msgbase.h index fa5d06f64..ca0e6f0ac 100644 --- a/citadel/msgbase.h +++ b/citadel/msgbase.h @@ -124,6 +124,7 @@ void CtdlWriteObject(char *, char *, char *, struct ctdluser *, struct CtdlMessage *CtdlFetchMessage(long msgnum, int with_body); void CtdlFreeMessage(struct CtdlMessage *msg); void serialize_message(struct ser_ret *, struct CtdlMessage *); +void dump_message(struct CtdlMessage *msg, long Siz); int is_valid_message(struct CtdlMessage *); void ReplicationChecks(struct CtdlMessage *); int CtdlSaveMsgPointersInRoom(char *roomname, long newmsgidlist[], int num_newmsgs, diff --git a/citadel/sendcommand.c b/citadel/sendcommand.c index c7439dc0d..9b331cc24 100644 --- a/citadel/sendcommand.c +++ b/citadel/sendcommand.c @@ -77,12 +77,40 @@ void nq_cleanup(int e) exit(e); } +/* + * send binary to server + */ +void serv_write(CtdlIPC *ipc, const char *buf, unsigned int nbytes) +{ + unsigned int bytes_written = 0; + int retval; +/* +#if defined(HAVE_OPENSSL) + if (ipc->ssl) { + serv_write_ssl(ipc, buf, nbytes); + return; + } +#endif +*/ + while (bytes_written < nbytes) { + retval = write(ipc->sock, &buf[bytes_written], + nbytes - bytes_written); + if (retval < 1) { + connection_died(ipc, 0); + return; + } + bytes_written += retval; + } +} + + void cleanup(int e) { static int nested = 0; alarm(30); signal(SIGALRM, nq_cleanup); + serv_write(ipc, "\n", 1); if (nested++ < 1) CtdlIPCQuit(ipc); nq_cleanup(e); diff --git a/citadel/sysdep.c b/citadel/sysdep.c index f7cfe8e2e..182c0df7d 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -632,7 +632,7 @@ void client_write(char *buf, int nbytes) "client_write(%d bytes) failed: %s (%d)\n", nbytes - bytes_written, strerror(errno), errno); - // cit_backtrace(); + cit_backtrace(); // lprintf(CTDL_DEBUG, "Tried to send: %s", &buf[bytes_written]); Ctx->kill_me = 1; return;