/*
- * $Id$
- *
* Copyright (c) 1987-2010 by the citadel.org team
*
* This program is free software; you can redistribute it and/or modify
rc = getaddrinfo(host, service, &hints, &res);
if (rc != 0) {
lprintf(1, "%s: %s\n", host, gai_strerror(rc));
+ freeaddrinfo(res);
return(-1);
}
s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (s < 0) {
lprintf(1, "socket() failed: %s\n", strerror(errno));
+ freeaddrinfo(res);
return(-1);
}
- rc = connect(s, res->ai_addr, res->ai_addrlen);
+ rc = connect(s, ai->ai_addr, ai->ai_addrlen);
if (rc >= 0) {
+ freeaddrinfo(res);
return(s);
}
else {
close(s);
}
}
-
+ freeaddrinfo(res);
return(-1);
}
#ifdef SERV_TRACE
else
{
- long pos=0;
+ long pos = 0;
if (WCC->ReadPos != NULL)
- pos = WCC->ReadPos - ChrPtr(buf);
+ pos = WCC->ReadPos - ChrPtr(WCC->ReadBuf);
lprintf(9, "%3d<<<[%ld]%s\n", WC->serv_sock, pos, ChrPtr(buf));
}
#endif
return rc;
}
+
+void FlushReadBuf (void)
+{
+ long len;
+ const char *pch;
+ const char *pche;
+ wcsession *WCC = WC;
+
+ len = StrLength(WCC->ReadBuf);
+ if ((len > 0) &&
+ (WCC->ReadPos != NULL) &&
+ (WCC->ReadPos != StrBufNOTNULL))
+
+ {
+ pch = ChrPtr(WCC->ReadBuf);
+ pche = pch + len;
+ if (WCC->ReadPos != pche)
+ {
+ lprintf(1, "ERROR: somebody didn't eat his soup! Remaing Chars: %d [%s]\n",
+ pche - WCC->ReadPos, pche);
+ lprintf(1,
+ "--------------------------------------------------------------------------------\n"
+ "Whole buf: [%s]\n"
+ "--------------------------------------------------------------------------------\n",
+ pch);
+ AppendImportantMessage(HKEY("Suppenkasper alert! watch your webcit logfile and get connected to your favourite opensource Crew."));
+ }
+ }
+
+ FlushStrBuf(WCC->ReadBuf);
+ WCC->ReadPos = NULL;
+
+
+}
+
+
/*
* send binary to server
* buf the buffer to write to citadel server
int bytes_written = 0;
int retval;
- FlushStrBuf(WCC->ReadBuf);
- WCC->ReadPos = NULL;
+ FlushReadBuf();
while (bytes_written < nbytes) {
retval = write(WCC->serv_sock, &buf[bytes_written],
nbytes - bytes_written);
*/
void serv_puts(const char *string)
{
- wcsession *WCC = WC;
#ifdef SERV_TRACE
lprintf(9, "%3d>>>%s\n", WC->serv_sock, string);
#endif
- FlushStrBuf(WCC->ReadBuf);
- WCC->ReadPos = NULL;
+ FlushReadBuf();
serv_write(string, strlen(string));
serv_write("\n", 1);
*/
void serv_putbuf(const StrBuf *string)
{
- wcsession *WCC = WC;
#ifdef SERV_TRACE
lprintf(9, "%3d>>>%s\n", WC->serv_sock, ChrPtr(string));
#endif
- FlushStrBuf(WCC->ReadBuf);
- WCC->ReadPos = NULL;
+ FlushReadBuf();
serv_write(ChrPtr(string), StrLength(string));
serv_write("\n", 1);
*/
void serv_printf(const char *format,...)
{
- wcsession *WCC = WC;
va_list arg_ptr;
char buf[SIZ];
size_t len;
- FlushStrBuf(WCC->ReadBuf);
- WCC->ReadPos = NULL;
+ FlushReadBuf();
va_start(arg_ptr, format);
vsnprintf(buf, sizeof buf, format, arg_ptr);