* non-buffered IO is going away completely, thus we remove the buffered suffix from the function and all places that used it so far
* set O_NONBLOCK on our server FD, hopefully this does what we want?
relevant_partnum[0] = '\0';
serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */
Buf = NewStrBuf();
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 1) {
FreeStrBuf (&Buf);
return;
}
- while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) {
+ while (!Done && (StrBuf_ServGetln(Buf)>=0)) {
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000")) {
Done = 1;
Buf = NewStrBuf();
StrBufUnescape(WCC->UrlFragment2, 1);
serv_printf("OPEN %s", ChrPtr(WCC->UrlFragment2));
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 2) {
StrBufCutLeft(Buf, 4);
bytes = StrBufExtract_long(Buf, 0, '|');
}
read_server_binary(WCC->WBuf, bytes, Buf);
serv_puts("CLOS");
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
http_transmit_thing(ChrPtr(ContentType), 0);
} else {
StrBufCutLeft(Buf, 4);
Buf = NewStrBuf();
serv_printf("OIMG %s|%s", bstr("name"), bstr("parm"));
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 2) {
StrBufCutLeft(Buf, 4);
bytes = StrBufExtract_long(Buf, 0, '|');
if (read_server_binary(WCC->WBuf, bytes, Buf) > 0) {
serv_puts("CLOS");
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
MimeType = GuessMimeType (ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
/** Write it to the browser */
StrBuf_ServGetln(MsgNum);
if (GetServerStatus(MsgNum, NULL) == 1)
- while (BufLen = StrBuf_ServGetlnBuffered(MsgNum), strcmp(ChrPtr(MsgNum), "000")) {
+ while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000")) {
msgs = realloc(msgs, ++num_msgs * sizeof(long));
msgs[num_msgs-1] = StrTol(MsgNum);
}
serv_printf("MSG0 %ld|3", msgs[i]);
StrBuf_ServGetln(MsgNum);
if (GetServerStatus(MsgNum, NULL) == 1)
- while (BufLen = StrBuf_ServGetlnBuffered(MsgNum), strcmp(ChrPtr(MsgNum), "000"))
+ while (BufLen = StrBuf_ServGetln(MsgNum), strcmp(ChrPtr(MsgNum), "000"))
{
if (!strncasecmp(ChrPtr(MsgNum), "exti=", 5)) {
strcpy(uid, &ChrPtr(MsgNum)[5]);
}
case 1:
while (!Done) {
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000")) {
Done = 1;
/** begin everythingamundo table */
HdrToken = NewStrBuf();
- while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) {
+ while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000"))
{
serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 1) {
FreeStrBuf(&Buf);
return NULL;
Msg = (message_summary*)malloc(sizeof(message_summary));
memset(Msg, 0, sizeof(message_summary));
- while (len = StrBuf_ServGetlnBuffered(Buf),
+ while (len = StrBuf_ServGetln(Buf),
((len != 3) ||
strcmp(ChrPtr(Buf), "000")== 0)){
buf = ChrPtr(Buf);
Buf = NewStrBuf();
serv_puts(servcmd);
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 1) {
FreeStrBuf(&Buf);
return (nummsgs);
}
Buf2 = NewStrBuf();
- while (len = StrBuf_ServGetlnBuffered(Buf),
+ while (len = StrBuf_ServGetln(Buf),
((len != 3) ||
strcmp(ChrPtr(Buf), "000")!= 0))
{
Buf = NewStrBuf();
serv_printf("OPNA %s|%s", ChrPtr(WCC->UrlFragment2), ChrPtr(WCC->UrlFragment3));
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 2) {
StrBufCutLeft(Buf, 4);
bytes = StrBufExtract_long(Buf, 0, '|');
read_server_binary(WCC->WBuf, bytes, Buf);
serv_puts("CLOS");
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
CT = ChrPtr(ContentType);
if (!force_download) {
Buf = NewStrBuf();
serv_printf("DLAT %ld|%s", msgnum, partnum);
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 6) {
StrBufCutLeft(Buf, 4);
bytes = StrBufExtract_long(Buf, 0, '|');
/* TODO: is there a chance the contenttype is different to the one we know? */
serv_printf("DLAT %ld|%s", Mime->msgnum, ChrPtr(Mime->PartNum));
Buf = NewStrBuf();
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 6) {
bytes = extract_long(&(ChrPtr(Buf)[4]), 0);
relevant_partnum[0] = '\0';
serv_printf("MSG4 %ld", msgnum); /* we need the mime headers */
Buf = NewStrBuf();
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 1) {
FreeStrBuf (&Buf);
return NULL;
}
- while ((StrBuf_ServGetlnBuffered(Buf)>=0) && !Done) {
+ while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000")) {
Done = 1;
*/
void load_preferences(void)
{
+ int Done = 0;
StrBuf *ReadBuf;
- char buf[SIZ];
long msgnum = 0L;
if (goto_config_room() != 0) return; /* oh well. */
serv_puts("subj|__ WebCit Preferences __");
serv_puts("000");
}
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- msgnum = atol(buf);
+ while (!Done &&
+ StrBuf_ServGetln(ReadBuf)) {
+ if ( (StrLength(ReadBuf)==3) &&
+ !strcmp(ChrPtr(ReadBuf), "000")) {
+ Done = 1;
+ break;
+ }
+ msgnum = StrTol(ReadBuf);
}
if (msgnum > 0L) {
*/
void save_preferences(void)
{
- char buf[SIZ];
+ int Done;
+ StrBuf *ReadBuf;
long msgnum = 0L;
+ ReadBuf = NewStrBuf();
if (goto_config_room() != 0) return; /* oh well. */
serv_puts("MSGS ALL|0|1");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '8') {
+ StrBuf_ServGetln(ReadBuf);
+ if (GetServerStatus(ReadBuf, NULL) == 8) {
serv_puts("subj|__ WebCit Preferences __");
serv_puts("000");
}
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- msgnum = atol(buf);
+ while (!Done &&
+ StrBuf_ServGetln(ReadBuf)) {
+ if ( (StrLength(ReadBuf)==3) &&
+ !strcmp(ChrPtr(ReadBuf), "000")) {
+ Done = 1;
+ break;
+ }
+ msgnum = StrTol(ReadBuf);
}
if (msgnum > 0L) {
serv_printf("DELE %ld", msgnum);
- serv_getln(buf, sizeof buf);
+ StrBuf_ServGetln(ReadBuf);
+ GetServerStatus(ReadBuf, NULL);
}
serv_printf("ENT0 1||0|1|__ WebCit Preferences __|");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '4') {
+ StrBuf_ServGetln(ReadBuf);
+ if (GetServerStatus(ReadBuf, NULL) == 4) {
WritePrefsToServer(WC->hash_prefs);
serv_puts("");
/** Go back to the room we're supposed to be in */
serv_printf("GOTO %s", ChrPtr(WC->wc_roomname));
- serv_getln(buf, sizeof buf);
+ StrBuf_ServGetln(ReadBuf);
+ FreeStrBuf(&ReadBuf);
}
/**
/*
* load the list of floors
*/
-void load_floorlist(void)
+void load_floorlist(StrBuf *Buf)
{
int a;
- char buf[SIZ];
+ int Done = 0;
for (a = 0; a < MAX_FLOORS; ++a)
floorlist[a][0] = 0;
serv_puts("LFLR");
- serv_getln(buf, sizeof buf);
- if (buf[0] != '1') {
+ StrBuf_ServGetln(Buf);
+ if (GetServerStatus(Buf, NULL) != 1) {
strcpy(floorlist[0], "Main Floor");
return;
}
- while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
- extract_token(floorlist[extract_int(buf, 0)], buf, 1, '|', sizeof floorlist[0]);
+ while (!Done && (StrBuf_ServGetln(Buf)>=0)) {
+ if ( (StrLength(Buf)==3) &&
+ !strcmp(ChrPtr(Buf), "000")) {
+ Done = 1;
+ break;
+ }
+ extract_token(floorlist[StrBufExtract_int(Buf, 0, '|')], ChrPtr(Buf), 1, '|', sizeof floorlist[0]);
}
}
*/
void display_editroom(void)
{
+ StrBuf *Buf;
char buf[SIZ];
char cmd[1024];
char node[256];
tab = bstr("tab");
if (IsEmptyStr(tab)) tab = "admin";
- load_floorlist();
+ Buf = NewStrBuf();
+ load_floorlist(Buf);
+ FreeStrBuf(&Buf);
output_headers(1, 1, 1, 0, 0, 0);
wprintf("<div class=\"fix_scrollbar_bug\">");
*/
void display_entroom(void)
{
+ StrBuf *Buf;
int i;
char buf[SIZ];
+ Buf = NewStrBuf();
serv_puts("CRE8 0");
serv_getln(buf, sizeof buf);
if (buf[0] != '2') {
strcpy(WC->ImportantMessage, &buf[4]);
display_main_menu();
+ FreeStrBuf(&Buf);
return;
}
wprintf("<tr class=\"odd\"><td>");
wprintf(_("Resides on floor: "));
wprintf("</td><td>");
- load_floorlist();
+ load_floorlist(Buf);
wprintf("<select name=\"er_floor\" size=\"1\">\n");
for (i = 0; i < 128; ++i)
if (!IsEmptyStr(floorlist[i])) {
do_template("endbox", NULL);
wDumpContent(1);
+ FreeStrBuf(&Buf);
}
*/
void list_all_rooms_by_floor(const char *viewpref) {
+ StrBuf *Buf;
char buf[SIZ];
int swap = 0;
struct folder *fold = NULL;
do_iconbar_view(WC->cache_fold, WC->cache_max_folders, WC->cache_num_floors);
return;
}
+ Buf = NewStrBuf();
/** Grab the floor table so we know how to build the list... */
- load_floorlist();
-
+ load_floorlist(Buf);
+ FreeStrBuf(&Buf);
/** Start with the mailboxes */
max_folders = 1;
alloc_folders = 1;
}
}
serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
- if (StrBuf_ServGetlnBuffered(Buf) > 0)
+ if (StrBuf_ServGetln(Buf) > 0)
{
if (GetServerStatus(Buf, NULL) == 6)
{
*/
int tcp_connectsock(char *host, char *service)
{
+ int fdflags;
struct hostent *phe;
struct servent *pse;
struct protoent *ppe;
alarm(0);
signal(SIGALRM, SIG_IGN);
+ fdflags = fcntl(s, F_GETFL);
+ fdflags = fdflags | O_NONBLOCK;
+ fcntl(s, F_SETFD, fdflags);
return (s);
}
-int StrBuf_ServGetln(StrBuf *buf)
-{
- wcsession *WCC = WC;
- const char *ErrStr;
- int rc;
-
- WCC->ReadPos = NULL;
- rc = StrBufTCP_read_line(buf, &WCC->serv_sock, 0, &ErrStr);
- if (rc < 0)
- {
- lprintf(1, "Server connection broken: %s\n",
- ErrStr);
- wc_backtrace();
- WCC->serv_sock = (-1);
- WCC->connected = 0;
- WCC->logged_in = 0;
- }
- return rc;
-}
-
/*
* input string from pipe
*/
{
wcsession *WCC = WC;
int len;
-
- WCC->ReadPos = NULL;
+ *strbuf = '\0';
StrBuf_ServGetln(WCC->MigrateReadLineBuf);
len = StrLength(WCC->MigrateReadLineBuf);
if (len > bufsize)
len = bufsize - 1;
memcpy(strbuf, ChrPtr(WCC->MigrateReadLineBuf), len);
- strbuf[len] = 0;
+ FlushStrBuf(WCC->MigrateReadLineBuf);
+ strbuf[len] = '\0';
#ifdef SERV_TRACE
lprintf(9, "%3d>%s\n", WC->serv_sock, strbuf);
#endif
}
-int StrBuf_ServGetlnBuffered(StrBuf *buf)
+int StrBuf_ServGetln(StrBuf *buf)
{
wcsession *WCC = WC;
const char *ErrStr;
}
Buf = NewStrBuf();
serv_printf(buf, "DLAT %ld|%s", msgnum, partnum);
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) != 6) {
convenience_page("770000", "Error", &(ChrPtr(Buf)[4]));
return;
}
case 1:
while (!Done) {
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if ( (StrLength(Buf)==3) &&
!strcmp(ChrPtr(Buf), "000")) {
Done = 1;
int tcp_connectsock(char *, char *);
int serv_getln(char *strbuf, int bufsize);
int StrBuf_ServGetln(StrBuf *buf);
-int StrBuf_ServGetlnBuffered(StrBuf *buf);
int GetServerStatus(StrBuf *Line, long* FullState);
void serv_puts(const char *string);
void who(void);
void serv_write(const char *buf, int nbytes);
void serv_putbuf(const StrBuf *string);
void serv_printf(const char *format,...)__attribute__((__format__(__printf__,1,2)));
-void load_floorlist(void);
+void load_floorlist(StrBuf *Buf);
void shutdown_sessions(void);
void do_housekeeping(void);
void smart_goto(const StrBuf *);
const char *Pos;
serv_puts("RWHO");
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 1) {
- while (BufLen = StrBuf_ServGetlnBuffered(Buf), strcmp(ChrPtr(Buf), "000")) {
+ while (BufLen = StrBuf_ServGetln(Buf), strcmp(ChrPtr(Buf), "000")) {
if (BufLen <= 0)
continue;
Pos = NULL;
Buf = NewStrBuf();
serv_puts("TIME");
- StrBuf_ServGetlnBuffered(Buf);
+ StrBuf_ServGetln(Buf);
if (GetServerStatus(Buf, NULL) == 2) {
const char *pos = ChrPtr(Buf) + 4;
now = StrBufExtractNext_long(Buf, &pos, '|');