}
#ifdef SERV_TRACE
else
- syslog(9, "%3d<<<BLOB: %ld bytes\n", WC->serv_sock, StrLength(buf));
+ syslog(9, "%3d<<<BLOB: %d bytes\n", WC->serv_sock, StrLength(buf));
#endif
return rc;
}
#ifdef SERV_TRACE
else
- syslog(9, "%3d<<<BLOB: %ld bytes\n", WC->serv_sock, StrLength(buf));
+ syslog(9, "%3d<<<BLOB: %d bytes\n", WC->serv_sock, StrLength(buf));
#endif
return rc;
pche = pch + len;
if (WCC->ReadPos != pche)
{
- syslog(1, "ERROR: somebody didn't eat his soup! Remaing Chars: %d [%s]\n",
+ syslog(1, "ERROR: somebody didn't eat his soup! Remaing Chars: %ld [%s]\n",
pche - WCC->ReadPos, pche);
syslog(1,
"--------------------------------------------------------------------------------\n"
* buf the buffer to write to citadel server
* nbytes how many bytes to send to citadel server
*/
-void serv_write(const char *buf, int nbytes)
+int serv_write(const char *buf, int nbytes)
{
wcsession *WCC = WC;
int bytes_written = 0;
WCC->serv_sock = (-1);
WCC->connected = 0;
WCC->logged_in = 0;
- return;
+ return 0;
}
bytes_written = bytes_written + retval;
}
+ return 1;
}
* send line to server
* string the line to send to the citadel server
*/
-void serv_puts(const char *string)
+int serv_puts(const char *string)
{
#ifdef SERV_TRACE
syslog(9, "%3d>>>%s\n", WC->serv_sock, string);
#endif
FlushReadBuf();
- serv_write(string, strlen(string));
- serv_write("\n", 1);
+ if (!serv_write(string, strlen(string)))
+ return 0;
+ return serv_write("\n", 1);
}
/*
* send line to server
* string the line to send to the citadel server
*/
-void serv_putbuf(const StrBuf *string)
+int serv_putbuf(const StrBuf *string)
{
#ifdef SERV_TRACE
syslog(9, "%3d>>>%s\n", WC->serv_sock, ChrPtr(string));
#endif
FlushReadBuf();
- serv_write(ChrPtr(string), StrLength(string));
- serv_write("\n", 1);
+ if (!serv_write(ChrPtr(string), StrLength(string)))
+ return 0;
+ return serv_write("\n", 1);
}
* format the formatstring
* ... the entities to insert into format
*/
-void serv_printf(const char *format,...)
+int serv_printf(const char *format,...)
{
va_list arg_ptr;
char buf[SIZ];
size_t len;
+ int rc;
FlushReadBuf();
len = strlen(buf);
buf[len++] = '\n';
buf[len] = '\0';
- serv_write(buf, len);
+ rc = serv_write(buf, len);
#ifdef SERV_TRACE
syslog(9, ">>>%s", buf);
#endif
+ return rc;
}
return -1;
}
- serv_printf("READ %d|%d", bytes_read, total_len-bytes_read);
+ serv_printf("READ "SIZE_T_FMT"|"SIZE_T_FMT, bytes_read, total_len-bytes_read);
if ( (rc = StrBuf_ServGetln(Buf) > 0) && (GetServerStatus(Buf, NULL) == 6) )
{
if (rc < 0)
#ifdef HAVE_OPENSSL
if (is_https) {
- long bufremain;
+ long bufremain = 0;
long baselen;
baselen = StrLength(Target);
if (Hdr->Pos == NULL)
Hdr->Pos = ChrPtr(Hdr->ReadBuf);
- bufremain = StrLength(Hdr->ReadBuf) - (Hdr->Pos - ChrPtr(Hdr->ReadBuf));
- if (bytes < bufremain)
- bufremain = bytes;
- StrBufAppendBufPlain(Target, Hdr->Pos, bufremain, 0);
- StrBufCutLeft(Hdr->ReadBuf, bufremain);
+ if (StrLength(Hdr->ReadBuf) > 0)
+ {
+ bufremain = StrLength(Hdr->ReadBuf) - (Hdr->Pos - ChrPtr(Hdr->ReadBuf));
+
+ if (bytes < bufremain)
+ bufremain = bytes;
+ StrBufAppendBufPlain(Target, Hdr->Pos, bufremain, 0);
+ StrBufCutLeft(Hdr->ReadBuf, bufremain);
+ }
if (bytes > bufremain)
{
FreeStrBuf(&sess->ReadBuf);
sess->ReadPos = NULL;
FreeStrBuf(&sess->MigrateReadLineBuf);
- if (sess->serv_sock > 0)
+ if (sess->serv_sock > 0) {
+ syslog(LOG_DEBUG, "Closing socket %d", sess->serv_sock);
close(sess->serv_sock);
+ }
}