* some more tweaking on buffered reading.
/*
* 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;
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);
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;
+ }
+ }*/
}
}
*/
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) {
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)
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';
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? */
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)
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
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
--with-ldap \
--with-libical \
--with-libsieve \
- --enable-debug $(EXTRA_ARGS) $(PROFILE_ARGS)
+ --enable-debug $(EXTRA_ARGS) $(PROFILE_ARGS) $(THREAD_ARGS)
touch configure-stamp
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 */
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);
}
/* 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"
* 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);
}
}
+/*
+ * 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
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,
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);
"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;