tMore HTTP errors are now caught ("FIXMEs" removed) - vaccinewars - be a doctor and try to vaccinate the world
(HTM) git clone git://src.adamsgaard.dk/vaccinewars
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit d6a5076a9856794af828cdc4af60b37d505ef66e
(DIR) parent f66319b09db21ecf15b25182e73b8d7cf88df2d5
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Tue, 16 Oct 2001 19:32:47 +0000
More HTTP errors are now caught ("FIXMEs" removed)
Diffstat:
M ChangeLog | 2 --
M src/gtk_client.c | 3 ---
M src/message.c | 20 ++++++++++----------
M src/network.c | 40 ++++++++++++++++++++++---------
M src/network.h | 2 +-
M src/serverside.c | 4 ++--
6 files changed, 42 insertions(+), 29 deletions(-)
---
(DIR) diff --git a/ChangeLog b/ChangeLog
t@@ -5,8 +5,6 @@ cvs
- SOCKS4 and SOCKS5 (user/password) support
- French translation added by leonard
- Boolean configuration variables (TRUE/FALSE) now supported
- - Metaserver code is now non-blocking (and should soon support more
- HTTP features, such as redirects and authentication)
- Many code cleanups
- High score files now have a "proper" header, so that file(1) can
identify them, and so the -f option cannot be used to force setgid-games
(DIR) diff --git a/src/gtk_client.c b/src/gtk_client.c
t@@ -2156,9 +2156,6 @@ static void HandleMetaSock(gpointer data,gint socket,
NBStatus oldstatus;
NBSocksStatus oldsocks;
-/*g_print("HandleMetaSock: read %d, write %d\n",
- condition&GDK_INPUT_READ,
- condition&GDK_INPUT_WRITE);*/
widgets=(struct StartGameStruct *)data;
if (!widgets->MetaConn) return;
(DIR) diff --git a/src/message.c b/src/message.c
t@@ -352,23 +352,23 @@ gboolean HandleWaitingMetaServerData(HttpConnection *conn,GSList **listpt,
if (CountWaitingMessages(&conn->NetBuf)<8) return FALSE;
NewServer=g_new0(ServerData,1);
- NewServer->Name=ReadHttpResponse(conn);
- msg=ReadHttpResponse(conn);
+ NewServer->Name=ReadHttpResponse(conn,doneOK);
+ msg=ReadHttpResponse(conn,doneOK);
NewServer->Port=atoi(msg); g_free(msg);
- NewServer->Version=ReadHttpResponse(conn);
- msg=ReadHttpResponse(conn);
+ NewServer->Version=ReadHttpResponse(conn,doneOK);
+ msg=ReadHttpResponse(conn,doneOK);
if (msg[0]) NewServer->CurPlayers=atoi(msg);
else NewServer->CurPlayers=-1;
g_free(msg);
- msg=ReadHttpResponse(conn);
+ msg=ReadHttpResponse(conn,doneOK);
NewServer->MaxPlayers=atoi(msg); g_free(msg);
- NewServer->Update=ReadHttpResponse(conn);
- NewServer->Comment=ReadHttpResponse(conn);
- NewServer->UpSince=ReadHttpResponse(conn);
+ NewServer->Update=ReadHttpResponse(conn,doneOK);
+ NewServer->Comment=ReadHttpResponse(conn,doneOK);
+ NewServer->UpSince=ReadHttpResponse(conn,doneOK);
*listpt=g_slist_append(*listpt,NewServer);
} else if (conn->Status==HS_READSEPARATOR && conn->StatusCode==200) {
/* This should be the first line of the body, the "MetaServer:" line */
- msg=ReadHttpResponse(conn);
+ msg=ReadHttpResponse(conn,doneOK);
if (!msg) return FALSE;
if (strlen(msg)>=14 && strncmp(msg,"FATAL ERROR:",12)==0) {
SetError(&conn->NetBuf.error,&ETMeta,MEC_INTERNAL,g_strdup(&msg[13]));
t@@ -382,7 +382,7 @@ gboolean HandleWaitingMetaServerData(HttpConnection *conn,GSList **listpt,
}
g_free(msg);
} else {
- msg=ReadHttpResponse(conn);
+ msg=ReadHttpResponse(conn,doneOK);
if (!msg) return FALSE;
g_free(msg);
}
(DIR) diff --git a/src/network.c b/src/network.c
t@@ -340,6 +340,9 @@ static ErrorType ETSocks = { SocksAppendError,NULL };
typedef enum {
HEC_TRIESEX = 1,
+ HEC_BADAUTH,
+ HEC_BADREDIR,
+ HEC_BADSTATUS,
HEC_OK = 200,
HEC_REDIRECT = 300,
HEC_MOVEPERM = 301,
t@@ -355,8 +358,19 @@ typedef enum {
static void HTTPAppendError(GString *str,LastError *error) {
switch (error->code) {
case HEC_TRIESEX:
+/* Various HTTP error messages */
g_string_append(str,_("Number of tries exceeded"));
break;
+ case HEC_BADAUTH:
+ g_string_sprintfa(str,_("Bad auth header: %s"),(gchar *)error->data);
+ break;
+ case HEC_BADREDIR:
+ g_string_sprintfa(str,_("Bad redirect: %s"),(gchar *)error->data);
+ break;
+ case HEC_BADSTATUS:
+ g_string_sprintfa(str,_("Invalid HTTP status line: %s"),
+ (gchar *)error->data);
+ break;
case HEC_FORBIDDEN:
g_string_append(str,_("403: forbidden"));
break;
t@@ -454,7 +468,6 @@ static gboolean Socks5Connect(NetworkBuffer *NetBuf) {
memcpy(&addpt[5+hostlen],&netport,sizeof(netport));
NetBuf->sockstat = NBSS_CONNECT;
-/* g_print("FIXME: SOCKS5 CONNECT request sent\n");*/
CommitWriteBuffer(NetBuf,conn,addpt,addlen);
t@@ -1133,7 +1146,8 @@ static gboolean ParseHtmlLocation(gchar *uri,gchar **host,unsigned *port,
return TRUE;
}
-static void StartHttpAuth(HttpConnection *conn,gboolean proxy,gchar *header) {
+static void StartHttpAuth(HttpConnection *conn,gboolean proxy,gchar *header,
+ gboolean *doneOK) {
gchar *realm,**split;
if (!conn->authfunc) return;
t@@ -1146,13 +1160,14 @@ static void StartHttpAuth(HttpConnection *conn,gboolean proxy,gchar *header) {
conn->waitinput=TRUE;
(*conn->authfunc)(conn,proxy,realm,conn->authdata);
} else {
- g_print("FIXME: Bad HTTP auth header\n");
+ *doneOK=FALSE;
+ SetError(&conn->NetBuf.error,ÐTTP,HEC_BADAUTH,g_strdup(header));
}
g_strfreev(split);
}
-static void ParseHtmlHeader(gchar *line,HttpConnection *conn) {
+static void ParseHtmlHeader(gchar *line,HttpConnection *conn,gboolean *doneOK) {
gchar **split,*host,*query;
unsigned port;
t@@ -1161,27 +1176,27 @@ static void ParseHtmlHeader(gchar *line,HttpConnection *conn) {
if (g_strcasecmp(split[0],"Location:")==0 &&
(conn->StatusCode==HEC_MOVETEMP || conn->StatusCode==HEC_MOVEPERM)) {
if (ParseHtmlLocation(split[1],&host,&port,&query)) {
- g_print("FIXME: Redirect to %s:%u%s\n",host,port,query);
g_free(conn->RedirHost); g_free(conn->RedirQuery);
conn->RedirHost=host; conn->RedirQuery=query;
conn->RedirPort=port;
} else {
- g_print("FIXME: Bad redirect\n");
+ *doneOK=FALSE;
+ SetError(&conn->NetBuf.error,ÐTTP,HEC_BADREDIR,g_strdup(line));
}
} else if (g_strcasecmp(split[0],"WWW-Authenticate:")==0 &&
conn->StatusCode==HEC_AUTHREQ) {
- StartHttpAuth(conn,FALSE,split[1]);
+ StartHttpAuth(conn,FALSE,split[1],doneOK);
/* Proxy-Authenticate is, strictly speaking, an HTTP/1.1 thing, but some
HTTP/1.0 proxies seem to support it anyway */
} else if (g_strcasecmp(split[0],"Proxy-Authenticate:")==0 &&
conn->StatusCode==HEC_PROXYAUTH) {
- StartHttpAuth(conn,TRUE,split[1]);
+ StartHttpAuth(conn,TRUE,split[1],doneOK);
}
}
g_strfreev(split);
}
-gchar *ReadHttpResponse(HttpConnection *conn) {
+gchar *ReadHttpResponse(HttpConnection *conn,gboolean *doneOK) {
gchar *msg,**split;
msg=GetWaitingMessage(&conn->NetBuf);
t@@ -1191,12 +1206,15 @@ gchar *ReadHttpResponse(HttpConnection *conn) {
split=g_strsplit(msg," ",2);
if (split[0] && split[1]) {
conn->StatusCode=atoi(split[1]);
- } else g_warning("Invalid HTTP status line %s",msg);
+ } else {
+ *doneOK=FALSE;
+ SetError(&conn->NetBuf.error,ÐTTP,HEC_BADSTATUS,g_strdup(msg));
+ }
g_strfreev(split);
break;
case HS_READHEADERS:
if (msg[0]==0) conn->Status=HS_READSEPARATOR;
- else ParseHtmlHeader(msg,conn);
+ else ParseHtmlHeader(msg,conn,doneOK);
break;
case HS_READSEPARATOR:
conn->Status=HS_READBODY;
(DIR) diff --git a/src/network.h b/src/network.h
t@@ -194,7 +194,7 @@ gboolean OpenHttpConnection(HttpConnection **conn,gchar *HostName,
gchar *Method,gchar *Query,
gchar *Headers,gchar *Body);
void CloseHttpConnection(HttpConnection *conn);
-gchar *ReadHttpResponse(HttpConnection *conn);
+gchar *ReadHttpResponse(HttpConnection *conn,gboolean *doneOK);
void SetHttpAuthentication(HttpConnection *conn,gboolean proxy,
gchar *user,gchar *password);
void SetHttpAuthFunc(HttpConnection *conn,HCAuthFunc authfunc,gpointer data);
(DIR) diff --git a/src/serverside.c b/src/serverside.c
t@@ -953,7 +953,7 @@ void ServerLoop() {
if (MetaConn) {
if (RespondToSelect(&MetaConn->NetBuf,&readfs,&writefs,
&errorfs,&DoneOK)) {
- while ((buf=ReadHttpResponse(MetaConn))) {
+ while ((buf=ReadHttpResponse(MetaConn,&DoneOK))) {
gboolean ReadingBody = (MetaConn->Status==HS_READBODY);
if (buf[0] || !ReadingBody) {
dopelog(ReadingBody ? 2 : 4,"MetaServer: %s",buf);
t@@ -1072,7 +1072,7 @@ void GuiHandleMeta(gpointer data,gint socket,GdkInputCondition condition) {
if (!MetaConn) return;
if (NetBufHandleNetwork(&MetaConn->NetBuf,condition&GDK_INPUT_READ,
condition&GDK_INPUT_WRITE,&DoneOK)) {
- while ((buf=ReadHttpResponse(MetaConn))) {
+ while ((buf=ReadHttpResponse(MetaConn,&DoneOK))) {
gboolean ReadingBody = (MetaConn->Status==HS_READBODY);
if (buf[0] || !ReadingBody) {
dopelog(ReadingBody ? 2 : 4,"MetaServer: %s",buf);