old_len = migr_chardata_len;
new_len = old_len + len;
+
new_buffer = realloc(migr_chardata, new_len + 1);
if (new_buffer != NULL) {
memcpy(&new_buffer[old_len], s, len);
cdb_store(CDB_MSGMAIN, &import_msgnum, sizeof(long), decoded_msg, msglen);
free(decoded_msg);
decoded_msg = NULL;
+ smi.meta_msgnum = import_msgnum;
PutMetaData(&smi);
syslog(LOG_INFO, "Imported message #%ld, size=%ld, refcount=%d, content-type: %s\n",
import_msgnum, msglen, smi.meta_refcount, smi.meta_content_type);
void migr_do_import(void) {
StrBuf *Buf;
XML_Parser xp;
- int linelen;
+ int Finished = 0;
unbuffer_output();
Buf = NewStrBufPlain(NULL, SIZ);
cprintf("%d sock it to me\n", SEND_LISTING);
unbuffer_output();
- while (CtdlClientGetLine(Buf) >= 0 && strcmp(ChrPtr(Buf), "000")) {
- linelen = StrLength(Buf);
- StrBufAppendBufPlain(Buf, HKEY("\n"), 0);
+ client_set_inbound_buf(SIZ * 10);
+ while (!Finished && client_read_random_blob(Buf, -1) >= 0) {
+ if ((StrLength(Buf) > 4) &&
+ !strcmp(ChrPtr(Buf) + StrLength(Buf) - 4, "000\n"))
+ {
+ Finished = 1;
+ StrBufCutAt(Buf, StrLength(Buf) - 4, NULL);
+ }
if (server_shutting_down)
break; // Should we break or return?
- if (linelen == 0)
+ if (StrLength(Buf) == 0)
continue;
- XML_Parse(xp, ChrPtr(Buf), linelen, 0);
+ XML_Parse(xp, ChrPtr(Buf), StrLength(Buf), 0);
+ FlushStrBuf(Buf);
}
XML_Parse(xp, "", 0, 1);
char relhome[PATH_MAX]="";
char ctdldir[PATH_MAX]=CTDLDIR;
+ StartLibCitadel(SIZ);
+
/* Parse command line */
while ((a = getopt(argc, argv, "h:w:")) != EOF) {
switch (a) {
);
fflush(stderr);
-// alarm(watchdog);
+ alarm(watchdog);
serv_sock = uds_connectsock(file_citadel_admin_socket);
serv_gets(buf);
IOB.fd = serv_sock;
FDIOBufferInit(&FDIO, &IOB, fileno(stdin), -1);
- while (FileSendChunked(&FDIO, &ErrStr));
+ while (FileSendChunked(&FDIO, &ErrStr) >= 0);
alarm(watchdog); /* reset the watchdog timer */
+ if (ErrStr != NULL)
+ fprintf(stderr, "Error while piping stuff: %s\n", ErrStr);
FDIOBufferDelete(&FDIO);
FreeStrBuf(&IOB.Buf);
serv_puts("000");
}
StrBufAppendBuf(OutBuf, Line, 0);
StrBufAppendBufPlain(OutBuf, HKEY("\n"), 0);
-// alarm(watchdog); /* reset the watchdog timer */
+ alarm(watchdog); /* reset the watchdog timer */
break;
case eBufferNotEmpty:
break;
void FDIOBufferInit(FDIOBuffer *FDB, IOBuffer *IO, int FD, long TotalSendSize)
{
FDIOBufferFlush(FDB);
- FDB->ChunkSize =
- FDB->TotalSendSize = TotalSendSize;
+
+ FDB->TotalSendSize = TotalSendSize;
+ if (TotalSendSize > 0)
+ FDB->ChunkSize = TotalSendSize;
+ else
+ {
+ TotalSendSize = SIZ * 10;
+ FDB->ChunkSize = TotalSendSize;
+ }
FDB->IOB = IO;
+
#ifdef LINUX_SPLICE
if (EnableSplice)
pipe(FDB->SplicePipe);
else
#endif
- FDB->ChunkBuffer = NewStrBufPlain(NULL, TotalSendSize + 1);
+ FDB->ChunkBuffer = NewStrBufPlain(NULL, TotalSendSize+ 1);
FDB->OtherFD = FD;
}
int FileSendChunked(FDIOBuffer *FDB, const char **Err)
{
ssize_t sent, pipesize;
-#ifdef LINUX_SPLICE
- if (EnableSplice)
+
+ if (FDB->TotalSendSize > 0)
{
- if (FDB->PipeSize == 0)
+#ifdef LINUX_SPLICE
+ if (EnableSplice)
{
- pipesize = splice(FDB->OtherFD,
- &FDB->TotalSentAlready,
- FDB->SplicePipe[1],
- NULL,
- FDB->ChunkSendRemain,
- SPLICE_F_MOVE);
+ if (FDB->PipeSize == 0)
+ {
+ pipesize = splice(FDB->OtherFD,
+ &FDB->TotalSentAlready,
+ FDB->SplicePipe[1],
+ NULL,
+ FDB->ChunkSendRemain,
+ SPLICE_F_MOVE);
- if (pipesize == -1)
+ if (pipesize == -1)
+ {
+ *Err = strerror(errno);
+ return pipesize;
+ }
+ FDB->PipeSize = pipesize;
+ }
+ sent = splice(FDB->SplicePipe[0],
+ NULL,
+ FDB->IOB->fd,
+ NULL,
+ FDB->PipeSize,
+ SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
+ if (sent == -1)
{
*Err = strerror(errno);
- return pipesize;
+ return sent;
}
- FDB->PipeSize = pipesize;
+ FDB->PipeSize -= sent;
+ FDB->ChunkSendRemain -= sent;
+ return sent;
}
- sent = splice(FDB->SplicePipe[0],
- NULL,
- FDB->IOB->fd,
- NULL,
- FDB->PipeSize,
- SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
- if (sent == -1)
+ else
+#endif
{
- *Err = strerror(errno);
- return sent;
+ char *pRead;
+ long nRead = 0;
+
+ pRead = FDB->ChunkBuffer->buf;
+ while ((FDB->ChunkBuffer->BufUsed < FDB->TotalSendSize) && (nRead >= 0))
+ {
+ nRead = read(FDB->OtherFD, pRead, FDB->TotalSendSize - FDB->ChunkBuffer->BufUsed);
+ if (nRead > 0) {
+ FDB->ChunkBuffer->BufUsed += nRead;
+ FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0';
+ }
+ else if (nRead == 0) {}
+ else return nRead;
+ }
+
+ nRead = write(FDB->IOB->fd,
+ FDB->ChunkBuffer->buf + FDB->TotalSentAlready,
+ FDB->ChunkBuffer->BufUsed - FDB->TotalSentAlready);
+
+ if (nRead >= 0) {
+ FDB->TotalSentAlready += nRead;
+ FDB->ChunkSendRemain -= nRead;
+ return FDB->ChunkSendRemain;
+ }
+ else {
+ return nRead;
+ }
}
- FDB->PipeSize -= sent;
- FDB->ChunkSendRemain -= sent;
- return sent;
}
else
-#endif
{
- char *pRead;
- long nRead = 0;
-
- pRead = FDB->ChunkBuffer->buf;
- while ((FDB->ChunkBuffer->BufUsed < FDB->TotalSendSize) && (nRead >= 0))
+#ifdef LINUX_SPLICE
+ if (EnableSplice)
{
- nRead = read(FDB->OtherFD, pRead, FDB->TotalSendSize - FDB->ChunkBuffer->BufUsed);
- if (nRead > 0) {
- FDB->ChunkBuffer->BufUsed += nRead;
- FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0';
+ if (FDB->PipeSize == 0)
+ {
+ pipesize = splice(FDB->OtherFD,
+ &FDB->TotalSentAlready,
+ FDB->SplicePipe[1],
+ NULL,
+ SIZ * 10,
+ SPLICE_F_MOVE);
+
+ if (pipesize == -1)
+ {
+ *Err = strerror(errno);
+ return pipesize;
+ }
+ FDB->PipeSize = pipesize;
+ if (pipesize == 0)
+ return -1;
}
- else if (nRead == 0) {}
- else return nRead;
-
+ sent = splice(FDB->SplicePipe[0],
+ NULL,
+ FDB->IOB->fd,
+ NULL,
+ FDB->PipeSize,
+ SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK);
+ if (sent == -1)
+ {
+ *Err = strerror(errno);
+ return sent;
+ }
+ FDB->PipeSize -= sent;
+ FDB->ChunkSendRemain -= sent;
+ return sent;
}
+ else
+#endif
+ {
+ char *pRead;
+ long nRead = 0;
- nRead = write(FDB->IOB->fd, FDB->ChunkBuffer->buf + FDB->TotalSentAlready, FDB->ChunkSendRemain);
+ pRead = FDB->ChunkBuffer->buf;
+ while ((FDB->ChunkSendRemain == 0) &&
+ (FDB->ChunkBuffer->BufUsed < FDB->ChunkBuffer->BufSize) &&
+ (nRead >= 0))
+ {
+ FDB->TotalSentAlready = 0;
+ nRead = read(FDB->OtherFD, pRead, FDB->ChunkBuffer->BufSize - FDB->ChunkBuffer->BufUsed);
+ if (nRead > 0) {
+ FDB->ChunkBuffer->BufUsed += nRead;
+ FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0';
+ FDB->ChunkSendRemain += nRead;
+ }
+ else if (nRead == 0)
+ {
+ return -1;
+ }
+ else
+ {
+ *Err = strerror(errno);
+ return nRead;
+ }
+ }
- if (nRead >= 0) {
- FDB->TotalSentAlready += nRead;
- FDB->ChunkSendRemain -= nRead;
- return FDB->ChunkSendRemain;
- }
- else {
- return nRead;
+ nRead = write(FDB->IOB->fd,
+ FDB->ChunkBuffer->buf + FDB->TotalSentAlready,
+ FDB->ChunkBuffer->BufUsed - FDB->TotalSentAlready);
+
+ if (nRead >= 0) {
+ FDB->TotalSentAlready += nRead;
+ FDB->ChunkSendRemain -= nRead;
+ if (FDB->ChunkSendRemain == 0)
+ {
+ FDB->ChunkBuffer->BufUsed = 0;
+ FDB->TotalSentAlready = 0;
+ }
+ return FDB->ChunkSendRemain;
+ }
+ else {
+ return nRead;
+ }
}
}
}