Merge branch 'stable-82x' of ssh://git.citadel.org/appl/gitroot/citadel into stable-82x
authorArt Cancro <ajc@uncensored.citadel.org>
Tue, 7 Jan 2014 17:39:23 +0000 (12:39 -0500)
committerArt Cancro <ajc@uncensored.citadel.org>
Tue, 7 Jan 2014 17:39:23 +0000 (12:39 -0500)
citadel/modules/migrate/serv_migrate.c
citadel/sysconfig.h
citadel/utils/sendcommand.c
libcitadel/lib/stringbuf.c

index 117eb21bbeea4cba0cd4acdb2ea03cb75d6de08a..c3446e0d202c7cf28b40cfd98f5c9ad8644a3316 100644 (file)
@@ -524,6 +524,7 @@ void migr_xml_chardata(void *data, const XML_Char *s, int len) {
 
        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);
@@ -868,6 +869,7 @@ void migr_xml_end(void *data, const char *el) {
                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);
@@ -891,7 +893,7 @@ void migr_xml_end(void *data, const char *el) {
 void migr_do_import(void) {
        StrBuf *Buf;
        XML_Parser xp;
-       int linelen;
+       int Finished = 0;
        
        unbuffer_output();
        Buf = NewStrBufPlain(NULL, SIZ);
@@ -908,17 +910,23 @@ void migr_do_import(void) {
        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);
index f0c9bd2be6b9ad30db6f2fec6d34235710d55731..9b784816e685831f7bb8cf156dc6805e4ba0d4e7 100644 (file)
@@ -88,7 +88,6 @@
 #define SYSCONFIGROOM          "Local System Configuration"
 #define SMTP_SPOOLOUT_ROOM     "__CitadelSMTPspoolout__"
 #define FNBL_QUEUE_ROOM                "__CitadelFNBLqueue__"
-#define PAGER_QUEUE_ROOM       "__CitadelPagerQueue__"
 /*
  * Where we keep messages containing the vCards that source our directory.  It
  * makes no sense to change this, because you'd have to change it on every
index 6146dbb654f7a8ae845cc9012f96dce5f84a3238..5ee87fd41d7fc09801761e8772150211607502af 100644 (file)
@@ -150,6 +150,8 @@ int main(int argc, char **argv)
        char relhome[PATH_MAX]="";
        char ctdldir[PATH_MAX]=CTDLDIR;
 
+       StartLibCitadel(SIZ);
+
        /* Parse command line */
        while ((a = getopt(argc, argv, "h:w:")) != EOF) {
                switch (a) {
@@ -179,7 +181,7 @@ int main(int argc, char **argv)
        );
        fflush(stderr);
 
-//     alarm(watchdog);
+       alarm(watchdog);
        serv_sock = uds_connectsock(file_citadel_admin_socket);
 
        serv_gets(buf);
@@ -210,8 +212,10 @@ int main(int argc, char **argv)
                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");
@@ -251,7 +255,7 @@ int main(int argc, char **argv)
                                        }
                                        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;
index a245c3c37ea81483f8bf1ffd4410e67f28097362..ff44368f1cbf71f30312aafd0d4efdec32ce3701 100644 (file)
@@ -3936,15 +3936,23 @@ inline static void FDIOBufferFlush(FDIOBuffer *FDB)
 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;
 }
@@ -3971,68 +3979,159 @@ void FDIOBufferDelete(FDIOBuffer *FDB)
 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;
+                       }
                }
        }
 }