/*
* $Id$
*/
-/**
- * \defgroup ServFuncs Handles various types of data transfer operations with the Citadel service.
- * \ingroup CitadelCommunitacion
- */
-/*@{*/
#include "webcit.h"
#include "webserver.h"
struct serv_info serv_info; /**< our connection data to the server */
-
-/**
- * \brief get info about the server we've connected to
- * \param browser_host the citadell we want to connect to
- * \param user_agent which browser uses our client?
+HashList *ServHash = NULL;//// TODO;
+/*
+ * get info about the server we've connected to
+ *
+ * browser_host the citadell we want to connect to
+ * user_agent which browser uses our client?
*/
void get_serv_info(char *browser_host, char *user_agent)
{
serv_puts("MSGP text/html|text/plain");
serv_getln(buf, sizeof buf);
-#ifdef WEBCIT_WITH_CALENDAR_SERVICE
- /**
+ /*
* Tell the server that when we save a calendar event, we
* want invitations to be generated by the Citadel server
* instead of by the client.
*/
serv_puts("ICAL sgi|1");
serv_getln(buf, sizeof buf);
-#endif
/** Now ask the server to tell us a little bit about itself... */
serv_puts("INFO");
case 15:
serv_info.serv_newuser_disabled = atoi(buf);
break;
+ case 16:
+ safestrncpy(serv_info.serv_default_cal_zone, buf, sizeof serv_info.serv_default_cal_zone);
+ break;
+ case 20:
+ serv_info.serv_supports_sieve = atoi(buf);
+ break;
+ case 21:
+ serv_info.serv_fulltext_enabled = atoi(buf);
+ break;
+ case 22:
+ safestrncpy(serv_info.serv_svn_revision, buf, sizeof serv_info.serv_svn_revision);
+ break;
+ case 23:
+ serv_info.serv_supports_openid = atoi(buf);
+ break;
}
++a;
}
strcpy(buf, &buf[2]);
}
/** Activate embedded URL's */
- url(buf);
+ url(buf, sizeof(buf));
escputs(buf);
wprintf("\n");
void text_to_server(char *ptr)
{
char buf[256];
- int ch, a, pos;
+ int ch, a, pos, len;
pos = 0;
buf[0] = 0;
while (ptr[pos] != 0) {
ch = ptr[pos++];
if (ch == 10) {
- while ( (isspace(buf[strlen(buf) - 1]))
- && (strlen(buf) > 1) )
- buf[strlen(buf) - 1] = 0;
+ len = strlen(buf);
+ while ( (isspace(buf[len - 1]))
+ && (buf[0] != '\0')
+ && (buf[1] != '\0') )
+ buf[--len] = 0;
serv_puts(buf);
buf[0] = 0;
if (ptr[pos] != 0) strcat(buf, " ");
*/
void text_to_server_qp(char *ptr)
{
- char buf[256];
- int ch, pos;
+ unsigned char ch, buf[256];
+ int pos;
int output_len = 0;
pos = 0;
output_len = 0;
while (ptr[pos] != 0) {
- ch = ptr[pos++];
+ ch = (unsigned char)(ptr[pos++]);
if (ch == 13) {
/* ignore carriage returns */
/* hard line break */
if (output_len > 0) {
if (isspace(buf[output_len-1])) {
- sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]);
+ sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
output_len += 2;
}
}
buf[output_len++] = 0;
- serv_puts(buf);
+ serv_puts((char *)buf);
output_len = 0;
}
else if (ch == 9) {
buf[output_len++] = ch;
}
else {
- sprintf(&buf[output_len], "=%02X", ch);
+ sprintf((char *)&buf[output_len], "=%02X", ch);
output_len += 3;
}
if (output_len > 72) {
/* soft line break */
if (isspace(buf[output_len-1])) {
- sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]);
+ sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
output_len += 2;
}
buf[output_len++] = '=';
buf[output_len++] = 0;
- serv_puts(buf);
+ serv_puts((char *)buf);
output_len = 0;
}
}
/* end of data - transmit anything that's left */
if (output_len > 0) {
if (isspace(buf[output_len-1])) {
- sprintf(&buf[output_len-1], "=%02X", buf[output_len-1]);
+ sprintf((char *)&buf[output_len-1], "=%02X", buf[output_len-1]);
output_len += 2;
}
buf[output_len++] = 0;
- serv_puts(buf);
+ serv_puts((char *)buf);
output_len = 0;
}
}
/**
* Read binary data from server into memory using a series of
* server READ commands.
- * \param buffer the output buffer
- * \param total_len the maximal length of buffer
+ * \return the read content as StrBuf
*/
-void read_server_binary(char *buffer, size_t total_len) {
+int read_server_binary(StrBuf *Ret, size_t total_len)
+{
char buf[SIZ];
size_t bytes = 0;
size_t thisblock = 0;
+ StrBuf *Buf;
+
+ Buf = NewStrBuf();
+ if (Ret == NULL)
+ return -1;
- memset(buffer, 0, total_len);
while (bytes < total_len) {
thisblock = 4095;
if ((total_len - bytes) < thisblock) {
thisblock = total_len - bytes;
- if (thisblock == 0) return;
+ if (thisblock == 0) {
+ FlushStrBuf(Ret);
+ FreeStrBuf(&Buf);
+ return -1;
+ }
}
serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
- serv_getln(buf, sizeof buf);
- if (buf[0] == '6') {
- thisblock = (size_t)atoi(&buf[4]);
- if (!WC->connected) return;
- serv_read(&buffer[bytes], thisblock);
- bytes += thisblock;
- }
- else {
- lprintf(3, "Error: %s\n", &buf[4]);
- return;
+ if (StrBuf_ServGetln(Buf) > 0)
+ {
+ if (ChrPtr(Buf)[0] == '6')
+ {
+ StrBufCutLeft(Buf, 4); //thisblock = (size_t)atoi(&buf[4]);
+ thisblock = StrTol(Buf);
+ if (!WC->connected) {
+ FlushStrBuf(Ret);
+ FreeStrBuf(&Buf);
+ return -1;
+ }
+ StrBuf_ServGetBLOB(Ret, thisblock);
+ bytes += thisblock;
+ }
+ else {
+ FreeStrBuf(&Buf);
+ lprintf(3, "Error: %s\n", &buf[4]);
+ return -1;
+ }
}
}
+ FreeStrBuf(&Buf);
+ return StrLength(Ret);
}
* usual 000 terminator is found. Caller is responsible for freeing
* the returned pointer.
*/
-char *read_server_text(void) {
- char *text = NULL;
- size_t bytes_allocated = 0;
- size_t bytes_read = 0;
- int linelen;
- char buf[SIZ];
-
- text = malloc(SIZ);
- if (text == NULL) {
- return(NULL);
- }
- text[0] = 0;
- bytes_allocated = SIZ;
-
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- linelen = strlen(buf);
- buf[linelen] = '\n';
- buf[linelen+1] = 0;
- ++linelen;
-
- if ((bytes_read + linelen) >= (bytes_allocated - 2)) {
- bytes_allocated = 2 * bytes_allocated;
- text = realloc(text, bytes_allocated);
+int read_server_text(StrBuf *Buf, long *nLines)
+{
+ struct wcsession *WCC = WC;
+ long nRead;
+ long nTotal = 0;
+ long nlines;
+
+ nlines = 0;
+ while ((WCC->serv_sock!=-1) &&
+ (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
+ {
+ if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
+ StrBufCutRight(Buf, nRead);
+ break;
}
-
- strcpy(&text[bytes_read], buf);
- bytes_read += linelen;
+ nTotal += nRead;
+ nlines ++;
}
- return(text);
+ *nLines = nlines;
+ return nTotal;
}