Skip to content
Snippets Groups Projects
Commit 8a28fa9c authored by Mirar (Pontus Hagland)'s avatar Mirar (Pontus Hagland)
Browse files

more \n\n bugfixes

Rev: lib/modules/Protocols.pmod/HTTP.pmod/Query.pike:1.8
parent bb4943b8
No related branches found
No related tags found
No related merge requests found
...@@ -148,7 +148,7 @@ static void ponder_answer() ...@@ -148,7 +148,7 @@ static void ponder_answer()
if (i<0) i=0; if (i<0) i=0;
j=search(buf,"\r\n\r\n",i); if (j==-1) j=10000000; j=search(buf,"\r\n\r\n",i); if (j==-1) j=10000000;
i=search(buf,"\n\n",i); if (i==-1) i=10000000; i=search(buf,"\n\n",i); if (i==-1) i=10000000;
if ((j=min(i,j))!=10000000) break; if ((i=min(i,j))!=10000000) break;
s=con->read(8192,1); s=con->read(8192,1);
if (s=="") { i=strlen(buf); break; } if (s=="") { i=strlen(buf); break; }
...@@ -157,16 +157,21 @@ static void ponder_answer() ...@@ -157,16 +157,21 @@ static void ponder_answer()
buf+=s; buf+=s;
} }
headerbuf=buf[..i-1]; headerbuf=buf[..i-1]-"\n";
if (buf[i..i+1]=="\n\n") datapos=i+2; if (buf[i..i+1]=="\n\n") datapos=i+2;
else datapos=i+4; else datapos=i+4;
#ifdef HTTP_QUERY_DEBUG
werror("** %d bytes of header; %d bytes left in buffer (pos=%d)\n",
sizeof(headerbuf),sizeof(buf)-datapos,datapos);
#endif
// split headers // split headers
headers=([]); headers=([]);
sscanf(headerbuf,"%s%*[ ]%d%*[ ]%s%*[\r\n]",protocol,status,status_desc); sscanf(headerbuf,"%s%*[ ]%d%*[ ]%s%*[\r]",protocol,status,status_desc);
foreach ((headerbuf/"\r\n")[1..],string s) foreach ((headerbuf/"\r")[1..],string s)
{ {
string n,d; string n,d;
sscanf(s,"%[!-9;-~]%*[ \t]:%*[ \t]%s",n,d); sscanf(s,"%[!-9;-~]%*[ \t]:%*[ \t]%s",n,d);
...@@ -213,11 +218,11 @@ static void async_close() ...@@ -213,11 +218,11 @@ static void async_close()
static void async_read(mixed dummy,string s) static void async_read(mixed dummy,string s)
{ {
#ifdef HTTP_QUERY_DEBUG #ifdef HTTP_QUERY_DEBUG
werror("-> %O\n",s); werror("-> %d bytes of data\n",strlen(s));
#endif #endif
buf+=s; buf+=s;
if (-1!=search(buf,"\r\n\r\n")) if (-1!=search(buf,"\r\n\r\n") || -1!=search(buf,"\n\n"))
{ {
con->set_blocking(); con->set_blocking();
ponder_answer(); ponder_answer();
...@@ -253,6 +258,9 @@ static void async_failed() ...@@ -253,6 +258,9 @@ static void async_failed()
static void async_timeout() static void async_timeout()
{ {
#ifdef HTTP_QUERY_DEBUG
werror("** TIMEOUT\n");
#endif
errno=110; // timeout errno=110; // timeout
if (con) if (con)
{ {
...@@ -298,13 +306,16 @@ void async_got_host(string server,int port) ...@@ -298,13 +306,16 @@ void async_got_host(string server,int port)
void async_fetch_read(mixed dummy,string data) void async_fetch_read(mixed dummy,string data)
{ {
#ifdef HTTP_QUERY_DEBUG #ifdef HTTP_QUERY_DEBUG
werror("-> %O\n",data); werror("-> %d bytes of data\n",strlen(data));
#endif #endif
buf+=data; buf+=data;
} }
void async_fetch_close() void async_fetch_close()
{ {
#ifdef HTTP_QUERY_DEBUG
werror("-> close\n");
#endif
con->set_blocking(); con->set_blocking();
destruct(con); destruct(con);
con=0; con=0;
...@@ -554,10 +565,13 @@ class PseudoFile ...@@ -554,10 +565,13 @@ class PseudoFile
{ {
string s; string s;
if (p+n>len) n=len-p; if (len && p+n>len) n=len-p;
if (strlen(buf)<n && con) if (strlen(buf)<n && con)
buf+=con->read(n-strlen(buf)); {
string s=con->read(n-strlen(buf));
buf+=s;
}
s=buf[..n-1]; s=buf[..n-1];
buf=buf[n..]; buf=buf[n..];
...@@ -567,7 +581,6 @@ class PseudoFile ...@@ -567,7 +581,6 @@ class PseudoFile
void close() void close()
{ {
catch { con->close(); destruct(con); };
con=0; // forget con=0; // forget
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment