fixed a nasty bug with interning some text strings prepare for beta5 of

* SAX2.c: fixed a nasty bug with interning some text strings
* configure.in: prepare for beta5 of 2.6.0
* libxml.h nanoftp.c nanohttp.c xmlIO.c include/libxml/xmlerror.h:
  better error handling for I/O and converted FTP and HTTP
* parser.c: fixed another bug
Daniel
diff --git a/ChangeLog b/ChangeLog
index e356ba4..024bdc2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Fri Oct 10 21:34:01 CEST 2003 Daniel Veillard <daniel@veillard.com>
+
+	* SAX2.c: fixed a nasty bug with interning some text strings
+	* configure.in: prepare for beta5 of 2.6.0
+	* libxml.h nanoftp.c nanohttp.c xmlIO.c include/libxml/xmlerror.h:
+	  better error handling for I/O and converted FTP and HTTP
+	* parser.c: fixed another bug
+
 Fri Oct 10 16:45:20 CEST 2003 Daniel Veillard <daniel@veillard.com>
 
 	* SAX2.c: fixed uninitialized new field.
diff --git a/SAX2.c b/SAX2.c
index 3bcc8f4..1bcd841 100644
--- a/SAX2.c
+++ b/SAX2.c
@@ -2221,6 +2221,10 @@
 	     * We try to minimaze realloc() uses and avoid copying
 	     * and recomputing length over and over.
 	     */
+	    if ((ctxt->nodemem == ctxt->nodelen + 1) &&
+	        (xmlDictOwns(ctxt->dict, lastChild->content))) {
+		lastChild->content = xmlStrdup(lastChild->content);
+	    }
 	    if (ctxt->nodelen + len >= ctxt->nodemem) {
 		xmlChar *newbuf;
 		int size;
diff --git a/configure.in b/configure.in
index a8f274b..49ba1e8 100644
--- a/configure.in
+++ b/configure.in
@@ -7,7 +7,7 @@
 LIBXML_MAJOR_VERSION=2
 LIBXML_MINOR_VERSION=6
 LIBXML_MICRO_VERSION=0
-LIBXML_MICRO_VERSION_SUFFIX=beta4
+LIBXML_MICRO_VERSION_SUFFIX=beta5
 LIBXML_VERSION=$LIBXML_MAJOR_VERSION.$LIBXML_MINOR_VERSION.$LIBXML_MICRO_VERSION$LIBXML_MICRO_VERSION_SUFFIX
 LIBXML_VERSION_INFO=`expr $LIBXML_MAJOR_VERSION + $LIBXML_MINOR_VERSION`:$LIBXML_MICRO_VERSION:$LIBXML_MINOR_VERSION
 
diff --git a/include/libxml/xmlerror.h b/include/libxml/xmlerror.h
index 8510a80..2def816 100644
--- a/include/libxml/xmlerror.h
+++ b/include/libxml/xmlerror.h
@@ -34,6 +34,8 @@
     XML_FROM_MEMORY,	/* The memory allocator */
     XML_FROM_OUTPUT,	/* The serialization code */
     XML_FROM_IO,	/* The Input/Output stack */
+    XML_FROM_FTP,	/* The FTP module */
+    XML_FROM_HTTP,	/* The FTP module */
     XML_FROM_XINCLUDE,	/* The XInclude processing */
     XML_FROM_XPATH,	/* The XPath module */
     XML_FROM_XPOINTER,	/* The XPointer module */
@@ -426,6 +428,13 @@
     XML_IO_NO_INPUT, /* 1547 */
     XML_IO_BUFFER_FULL, /* 1548 */
     XML_IO_LOAD_ERROR, /* 1549 */
+    XML_IO_ENOTSOCK, /* 1550 */
+    XML_IO_EISCONN, /* 1551 */
+    XML_IO_ECONNREFUSED, /* 1552 */
+    XML_IO_ENETUNREACH, /* 1553 */
+    XML_IO_EADDRINUSE, /* 1554 */
+    XML_IO_EALREADY, /* 1555 */
+    XML_IO_EAFNOSUPPORT, /* 1556 */
     XML_XINCLUDE_RECURSION=1600,
     XML_XINCLUDE_PARSE_VALUE, /* 1601 */
     XML_XINCLUDE_ENTITY_DEF_MISMATCH, /* 1602 */
@@ -545,7 +554,13 @@
     XML_C14N_CREATE_CTXT = 1950,
     XML_C14N_REQUIRES_UTF8, /* 1951 */
     XML_C14N_CREATE_STACK, /* 1952 */
-    XML_C14N_INVALID_NODE /* 1953 */
+    XML_C14N_INVALID_NODE, /* 1953 */
+    XML_FTP_PASV_ANSWER = 2000,
+    XML_FTP_EPSV_ANSWER, /* 2001 */
+    XML_FTP_ACCNT, /* 2002 */
+    XML_HTTP_URL_SYNTAX = 2020,
+    XML_HTTP_USE_IP, /* 2021 */
+    XML_HTTP_UNKNOWN_HOST /* 2022 */
 } xmlParserErrors;
 
 /**
diff --git a/libxml.h b/libxml.h
index c7a1e93..7c98d13 100644
--- a/libxml.h
+++ b/libxml.h
@@ -44,4 +44,5 @@
  * function while checking if the callback exists.
  */
 extern int __xmlRegisterCallbacks;
+void __xmlIOErr(int domain, int code, const char *extra);
 #endif /* ! __XML_LIBXML_H__ */
diff --git a/nanoftp.c b/nanoftp.c
index f4b08d8..5ea71f7 100644
--- a/nanoftp.c
+++ b/nanoftp.c
@@ -157,6 +157,18 @@
 #endif
 
 /**
+ * xmlFTPErrMemory:
+ * @extra:  extra informations
+ *
+ * Handle an out of memory condition
+ */
+static void
+xmlFTPErrMemory(const char *extra)
+{
+    __xmlSimpleError(XML_FROM_FTP, XML_ERR_NO_MEMORY, NULL, NULL, extra);
+}
+
+/**
  * xmlNanoFTPInit:
  *
  * Initialize the FTP protocol layer.
@@ -658,7 +670,10 @@
     char *unescaped;
 
     ret = (xmlNanoFTPCtxtPtr) xmlMalloc(sizeof(xmlNanoFTPCtxt));
-    if (ret == NULL) return(NULL);
+    if (ret == NULL) {
+        xmlFTPErrMemory("allocating FTP context");
+        return(NULL);
+    }
 
     memset(ret, 0, sizeof(xmlNanoFTPCtxt));
     ret->port = 21;
@@ -798,6 +813,7 @@
      */
     if ((len = recv(ctxt->controlFd, &ctxt->controlBuf[ctxt->controlBufIndex],
 		    size, 0)) < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "recv failed");
 	closesocket(ctxt->controlFd); ctxt->controlFd = -1;
         ctxt->controlFd = -1;
         return(-1);
@@ -922,9 +938,7 @@
 	case 0:
 	    return(0);
 	case -1:
-#ifdef DEBUG_FTP
-	    perror("select");
-#endif
+	    __xmlIOErr(XML_FROM_FTP, 0, "select");
 	    return(-1);
 			
     }
@@ -953,7 +967,10 @@
     xmlGenericError(xmlGenericErrorContext, "%s", buf);
 #endif
     res = send(ctxt->controlFd, buf, len, 0);
-    if (res < 0) return(res);
+    if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
+	return(res);
+    }
     return(0);
 }
 
@@ -978,7 +995,10 @@
     xmlGenericError(xmlGenericErrorContext, "%s", buf);
 #endif
     res = send(ctxt->controlFd, buf, len, 0);
-    if (res < 0) return(res);
+    if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
+	return(res);
+    }
     return(0);
 }
 
@@ -996,14 +1016,18 @@
 xmlNanoFTPQuit(void *ctx) {
     xmlNanoFTPCtxtPtr ctxt = (xmlNanoFTPCtxtPtr) ctx;
     char buf[200];
-    int len;
+    int len, res;
 
     snprintf(buf, sizeof(buf), "QUIT\r\n");
     len = strlen(buf);
 #ifdef DEBUG_FTP
     xmlGenericError(xmlGenericErrorContext, "%s", buf); /* Just to be consistent, even though we know it can't have a % in it */
 #endif
-    send(ctxt->controlFd, buf, len, 0);
+    res = send(ctxt->controlFd, buf, len, 0);
+    if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
+	return(res);
+    }
     return(0);
 }
 
@@ -1051,12 +1075,16 @@
 	hints.ai_socktype = SOCK_STREAM;
 
 	if (proxy) {
-	    if (getaddrinfo (proxy, NULL, &hints, &result) != 0)
+	    if (getaddrinfo (proxy, NULL, &hints, &result) != 0) {
+		__xmlIOErr(XML_FROM_FTP, 0, "getaddrinfo failed");
 		return (-1);
+	    }
 	}
 	else
-	    if (getaddrinfo (ctxt->hostname, NULL, &hints, &result) != 0)
+	    if (getaddrinfo (ctxt->hostname, NULL, &hints, &result) != 0) {
+		__xmlIOErr(XML_FROM_FTP, 0, "getaddrinfo failed");
 		return (-1);
+	    }
 
 	for (tmp = result; tmp; tmp = tmp->ai_next)
 	    if (tmp->ai_family == AF_INET || tmp->ai_family == AF_INET6)
@@ -1089,8 +1117,10 @@
 	    hp = gethostbyname (proxy);
 	else
 	    hp = gethostbyname (ctxt->hostname);
-	if (hp == NULL)
+	if (hp == NULL) {
+	    __xmlIOErr(XML_FROM_FTP, 0, "gethostbyname failed");
 	    return (-1);
+	}
 
     /*
      * Prepare the socket
@@ -1103,14 +1133,17 @@
 	addrlen = sizeof (struct sockaddr_in);
     }
 
-    if (ctxt->controlFd < 0)
+    if (ctxt->controlFd < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "socket failed");
         return(-1);
+    }
 
     /*
      * Do the connect.
      */
     if (connect(ctxt->controlFd, (struct sockaddr *) &ctxt->ftpAddr,
 	    addrlen) < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "Failed to create a connection");
         closesocket(ctxt->controlFd); ctxt->controlFd = -1;
         ctxt->controlFd = -1;
 	return(-1);
@@ -1177,6 +1210,7 @@
 #endif
 	    res = send(ctxt->controlFd, buf, len, 0);
 	    if (res < 0) {
+		__xmlIOErr(XML_FROM_FTP, 0, "send failed");
 		closesocket(ctxt->controlFd);
 		ctxt->controlFd = -1;
 	        return(res);
@@ -1198,6 +1232,7 @@
 #endif
 		    res = send(ctxt->controlFd, buf, len, 0);
 		    if (res < 0) {
+			__xmlIOErr(XML_FROM_FTP, 0, "send failed");
 			closesocket(ctxt->controlFd);
 			ctxt->controlFd = -1;
 			return(res);
@@ -1238,6 +1273,7 @@
 #endif
 		res = send(ctxt->controlFd, buf, len, 0);
 		if (res < 0) {
+		    __xmlIOErr(XML_FROM_FTP, 0, "send failed");
 		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
 		    ctxt->controlFd = -1;
 		    return(res);
@@ -1268,6 +1304,7 @@
 #endif
 		res = send(ctxt->controlFd, buf, len, 0);
 		if (res < 0) {
+		    __xmlIOErr(XML_FROM_FTP, 0, "send failed");
 		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
 		    ctxt->controlFd = -1;
 		    return(res);
@@ -1289,6 +1326,7 @@
 #endif
 		res = send(ctxt->controlFd, buf, len, 0);
 		if (res < 0) {
+		    __xmlIOErr(XML_FROM_FTP, 0, "send failed");
 		    closesocket(ctxt->controlFd); ctxt->controlFd = -1;
 		    ctxt->controlFd = -1;
 		    return(res);
@@ -1350,8 +1388,8 @@
 	case 2:
 	    break;
 	case 3:
-	    xmlGenericError(xmlGenericErrorContext,
-		    "FTP server asking for ACCNT on anonymous\n");
+	    __xmlIOErr(XML_FROM_FTP, XML_FTP_ACCNT,
+		       "FTP server asking for ACCNT on anonymous\n");
 	case 1:
 	case 4:
 	case 5:
@@ -1426,7 +1464,10 @@
     xmlGenericError(xmlGenericErrorContext, "%s", buf);
 #endif
     res = send(ctxt->controlFd, buf, len, 0);
-    if (res < 0) return(res);
+    if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
+	return(res);
+    }
     res = xmlNanoFTPGetResponse(ctxt);
     if (res == 4) {
 	return(-1);
@@ -1471,7 +1512,10 @@
     xmlGenericError(xmlGenericErrorContext, "%s", buf);
 #endif
     res = send(ctxt->controlFd, buf, len, 0);
-    if (res < 0) return(res);
+    if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
+	return(res);
+    }
     res = xmlNanoFTPGetResponse(ctxt);
     if (res == 4) {
 	return(-1);
@@ -1522,8 +1566,7 @@
     }
 
     if (ctxt->dataFd < 0) {
-	xmlGenericError (xmlGenericErrorContext,
-		"xmlNanoFTPGetConnection: failed to create socket\n");
+	__xmlIOErr(XML_FROM_FTP, 0, "socket failed");
 	return (-1);
     }
 
@@ -1540,6 +1583,7 @@
 #endif
 	res = send(ctxt->controlFd, buf, len, 0);
 	if (res < 0) {
+	    __xmlIOErr(XML_FROM_FTP, 0, "send failed");
 	    closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	    return(res);
 	}
@@ -1561,7 +1605,7 @@
 #ifdef SUPPORT_IP6
 	if ((ctxt->ftpAddr).ss_family == AF_INET6) {
 	    if (sscanf (cur, "%u", &temp[0]) != 1) {
-		xmlGenericError (xmlGenericErrorContext,
+		__xmlIOErr(XML_FROM_FTP, XML_FTP_EPSV_ANSWER,
 			"Invalid answer to EPSV\n");
 		if (ctxt->dataFd != -1) {
 		    closesocket (ctxt->dataFd); ctxt->dataFd = -1;
@@ -1576,7 +1620,7 @@
 	{
 	    if (sscanf (cur, "%u,%u,%u,%u,%u,%u", &temp[0], &temp[1], &temp[2],
 		&temp[3], &temp[4], &temp[5]) != 6) {
-		xmlGenericError (xmlGenericErrorContext,
+		__xmlIOErr(XML_FROM_FTP, XML_FTP_PASV_ANSWER,
 			"Invalid answer to PASV\n");
 		if (ctxt->dataFd != -1) {
 		    closesocket (ctxt->dataFd); ctxt->dataFd = -1;
@@ -1589,8 +1633,7 @@
 	}
 
 	if (connect(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
-	    xmlGenericError(xmlGenericErrorContext,
-		    "Failed to create a data connection\n");
+	    __xmlIOErr(XML_FROM_FTP, 0, "Failed to create a data connection");
 	    closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	    return (-1);
 	}
@@ -1604,24 +1647,14 @@
 	    ((struct sockaddr_in *)&dataAddr)->sin_port = 0;
 
 	if (bind(ctxt->dataFd, (struct sockaddr *) &dataAddr, dataAddrLen) < 0) {
-	    xmlGenericError(xmlGenericErrorContext,
-		    "Failed to bind a port\n");
+	    __xmlIOErr(XML_FROM_FTP, 0, "bind failed");
 	    closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	    return (-1);
 	}
         getsockname(ctxt->dataFd, (struct sockaddr *) &dataAddr, &dataAddrLen);
 
 	if (listen(ctxt->dataFd, 1) < 0) {
-#ifdef SUPPORT_IP6
-	    if ((ctxt->ftpAddr).ss_family == AF_INET6)
-		xmlGenericError (xmlGenericErrorContext,
-			"Could not listen on port %d\n",
-			ntohs (((struct sockaddr_in6 *)&dataAddr)->sin6_port));
-	    else
-#endif
-		xmlGenericError (xmlGenericErrorContext,
-			"Could not listen on port %d\n",
-			ntohs (((struct sockaddr_in *)&dataAddr)->sin_port));
+	    __xmlIOErr(XML_FROM_FTP, 0, "listen failed");
 	    closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	    return (-1);
 	}
@@ -1651,6 +1684,7 @@
 
 	res = send(ctxt->controlFd, buf, len, 0);
 	if (res < 0) {
+	    __xmlIOErr(XML_FROM_FTP, 0, "send failed");
 	    closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	    return(res);
 	}
@@ -1884,6 +1918,7 @@
 #endif
     res = send(ctxt->controlFd, buf, len, 0);
     if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
 	closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	return(res);
     }
@@ -1924,9 +1959,7 @@
 	}
 
 	if ((len = recv(ctxt->dataFd, &buf[indx], sizeof(buf) - (indx + 1), 0)) < 0) {
-#ifdef DEBUG_FTP
-	    perror("recv");
-#endif
+	    __xmlIOErr(XML_FROM_FTP, 0, "recv");
 	    closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	    ctxt->dataFd = -1;
 	    return(-1);
@@ -1978,6 +2011,7 @@
 #endif
     res = send(ctxt->controlFd, buf, len, 0);
     if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
 	closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	return(res);
     }
@@ -1997,6 +2031,7 @@
 #endif
     res = send(ctxt->controlFd, buf, len, 0);
     if (res < 0) {
+	__xmlIOErr(XML_FROM_FTP, 0, "send failed");
 	closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	return(res);
     }
@@ -2065,6 +2100,7 @@
 	    continue;
 	}
 	if ((len = recv(ctxt->dataFd, buf, sizeof(buf), 0)) < 0) {
+	    __xmlIOErr(XML_FROM_FTP, 0, "recv failed");
 	    callback(userData, buf, len);
 	    closesocket(ctxt->dataFd); ctxt->dataFd = -1;
 	    return(-1);
@@ -2097,12 +2133,13 @@
     if (len <= 0) return(0);
 
     len = recv(ctxt->dataFd, dest, len, 0);
+    if (len <= 0) {
+        __xmlIOErr(XML_FROM_FTP, 0, "recv failed");
+	xmlNanoFTPCloseConnection(ctxt);
+    }
 #ifdef DEBUG_FTP
     xmlGenericError(xmlGenericErrorContext, "Recvd %d bytes\n", len);
 #endif
-    if (len <= 0) {
-	xmlNanoFTPCloseConnection(ctxt);
-    }
     return(len);
 }
 
diff --git a/nanohttp.c b/nanohttp.c
index c2c4d30..c02136a 100644
--- a/nanohttp.c
+++ b/nanohttp.c
@@ -160,6 +160,18 @@
 int xmlNanoHTTPContentLength( void * ctx );
 
 /**
+ * xmlHTTPErrMemory:
+ * @extra:  extra informations
+ *
+ * Handle an out of memory condition
+ */
+static void
+xmlHTTPErrMemory(const char *extra)
+{
+    __xmlSimpleError(XML_FROM_HTTP, XML_ERR_NO_MEMORY, NULL, NULL, extra);
+}
+
+/**
  * A portability function
  */
 static int socket_errno(void) {
@@ -290,8 +302,8 @@
     while (1) {
 	if ((strchr (cur, '[') && !strchr (cur, ']')) ||
 		(!strchr (cur, '[') && strchr (cur, ']'))) {
-	    xmlGenericError (xmlGenericErrorContext, "\nxmlNanoHTTPScanURL: %s",
-		    "Syntax Error\n");
+	    __xmlIOErr(XML_FROM_HTTP, XML_HTTP_URL_SYNTAX, 
+	               "Syntax Error\n");
 	    return;
 	}
 
@@ -301,7 +313,7 @@
 		buf[indx++] = *cur++;
     
 	    if (!strchr (buf, ':')) {
-		xmlGenericError (xmlGenericErrorContext, "\nxmlNanoHTTPScanURL: %s",
+		__xmlIOErr(XML_FROM_HTTP, XML_HTTP_USE_IP,
 			"Use [IPv6]/IPv4 format\n");
 		return;
 	    }
@@ -410,8 +422,7 @@
     while (1) {
 	if ((strchr (cur, '[') && !strchr (cur, ']')) ||
 		(!strchr (cur, '[') && strchr (cur, ']'))) {
-	    xmlGenericError (xmlGenericErrorContext, "\nxmlNanoHTTPScanProxy: %s",
-		    "Syntax error\n");
+	    __xmlIOErr(XML_FROM_HTTP, XML_HTTP_URL_SYNTAX, "Syntax Error\n");
 	    return;
 	}
 
@@ -421,7 +432,7 @@
 		buf[indx++] = *cur++;
 
 	    if (!strchr (buf, ':')) {
-		xmlGenericError (xmlGenericErrorContext, "\nxmlNanoHTTPScanProxy: %s",
+		__xmlIOErr(XML_FROM_HTTP, XML_HTTP_USE_IP,
 			"Use [IPv6]/IPv4 format\n");
 		return;
 	    }
@@ -485,7 +496,10 @@
     xmlNanoHTTPCtxtPtr ret;
 
     ret = (xmlNanoHTTPCtxtPtr) xmlMalloc(sizeof(xmlNanoHTTPCtxt));
-    if (ret == NULL) return(NULL);
+    if (ret == NULL) {
+        xmlHTTPErrMemory("allocating context");
+        return(NULL);
+    }
 
     memset(ret, 0, sizeof(xmlNanoHTTPCtxt));
     ret->port = 80;
@@ -546,10 +560,7 @@
 	    	      ( socket_errno( ) != EAGAIN ) &&
 #endif
 		        ( socket_errno( ) != EWOULDBLOCK ) ) {
-	        xmlGenericError( xmlGenericErrorContext,
-				"xmlNanoHTTPSend error:  %s",
-				strerror( socket_errno( ) ) );
-
+		__xmlIOErr(XML_FROM_HTTP, 0, "send failed\n");
 		if ( total_sent == 0 )
 		    total_sent = -1;
 		break;
@@ -597,9 +608,8 @@
 	if (ctxt->in == NULL) {
 	    ctxt->in = (char *) xmlMallocAtomic(65000 * sizeof(char));
 	    if (ctxt->in == NULL) {
+		xmlHTTPErrMemory("allocating input");
 	        ctxt->last = -1;
-		xmlGenericError( xmlGenericErrorContext, 
-			"xmlNanoHTTPRecv:  Error allocating input memory." );
 		return(-1);
 	    }
 	    ctxt->inlen = 65000;
@@ -623,10 +633,7 @@
 	    ctxt->inlen *= 2;
             ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen);
 	    if (ctxt->in == NULL) {
-	        xmlGenericError( xmlGenericErrorContext,
-				"xmlNanoHTTPRecv:  %s %d bytes.",
-				"Failed to realloc input buffer to",
-				ctxt->inlen );
+		xmlHTTPErrMemory("allocating input buffer");
 		xmlFree( tmp_ptr );
 	        ctxt->last = -1;
 		return(-1);
@@ -657,9 +664,7 @@
 		    return ( 0 );
 
 		default:
-		    xmlGenericError( xmlGenericErrorContext,
-		    		"xmlNanoHTTPRecv:  recv( ) failure - %s",
-				strerror( socket_errno( ) ) );
+		    __xmlIOErr(XML_FROM_HTTP, 0, "recv failed\n");
 		    return(-1);
 	    }
 	}
@@ -843,10 +848,7 @@
 #ifdef DEBUG_HTTP
 	perror("socket");
 #endif
-	xmlGenericError( xmlGenericErrorContext,
-			"xmlNanoHTTPConnectAttempt: %s - %s",
-			"socket creation failure",
-			strerror( socket_errno( ) ) );
+	__xmlIOErr(XML_FROM_HTTP, 0, "socket failed\n");
 	return(-1);
     }
     
@@ -877,10 +879,7 @@
 #ifdef DEBUG_HTTP
 	perror("nonblocking");
 #endif
-	xmlGenericError( xmlGenericErrorContext,
-			"xmlNanoHTTPConnectAttempt:  %s - %s",
-			"error setting non-blocking IO",
-			strerror( socket_errno( ) ) );
+	__xmlIOErr(XML_FROM_HTTP, 0, "error setting non-blocking IO\n");
 	closesocket(s);
 	return(-1);
     }
@@ -893,10 +892,7 @@
 	    case EWOULDBLOCK:
 		break;
 	    default:
-		xmlGenericError( xmlGenericErrorContext,
-				"xmlNanoHTTPConnectAttempt:  %s - %s",
-				"error connecting to HTTP server",
-				strerror( socket_errno( ) ) );
+		__xmlIOErr(XML_FROM_HTTP, 0, "error connecting to HTTP server");
 		closesocket(s);
 		return(-1);
 	}
@@ -912,17 +908,12 @@
     {
 	case 0:
 	    /* Time out */
-	    xmlGenericError( xmlGenericErrorContext, 
-	    			"xmlNanoHTTPConnectAttempt: %s",
-				"Connect attempt timed out." );
+	    __xmlIOErr(XML_FROM_HTTP, 0, "Connect attempt timed out");
 	    closesocket(s);
 	    return(-1);
 	case -1:
 	    /* Ermm.. ?? */
-	    xmlGenericError( xmlGenericErrorContext,
-	    			"xmlNanoHTTPConnectAttempt: %s - %s",
-				"Error connecting to host",
-				strerror( socket_errno( ) ) );
+	    __xmlIOErr(XML_FROM_HTTP, 0, "Connect failed");
 	    closesocket(s);
 	    return(-1);
     }
@@ -933,27 +924,19 @@
 #ifdef SO_ERROR
 	if (getsockopt(s, SOL_SOCKET, SO_ERROR, (char*)&status, &len) < 0 ) {
 	    /* Solaris error code */
-	    xmlGenericError( xmlGenericErrorContext,
-	    			"xmlNanoHTTPConnectAttempt: %s - %s",
-				"Error retrieving pending socket errors",
-				strerror( socket_errno( ) ) );
+	    __xmlIOErr(XML_FROM_HTTP, 0, "getsockopt failed\n");
 	    return (-1);
 	}
 #endif
 	if ( status ) {
+	    __xmlIOErr(XML_FROM_HTTP, 0, "Error connecting to remote host");
 	    closesocket(s);
 	    errno = status;
-	    xmlGenericError( xmlGenericErrorContext,
-	    			"xmlNanoHTTPConnectAttempt: %s - %s",
-				"Error connecting to remote host",
-				strerror( status ) );
 	    return (-1);
 	}
     } else {
 	/* pbm */
-	xmlGenericError( xmlGenericErrorContext,
-		"xmlNanoHTTPConnectAttempt:  %s\n",
-		"Select returned, but descriptor not set for connection.\n" );
+	__xmlIOErr(XML_FROM_HTTP, 0, "select failed\n");
 	closesocket(s);
 	return (-1);
     }
@@ -1008,10 +991,7 @@
 
 	status = getaddrinfo (host, NULL, &hints, &result);
 	if (status) {
-	    xmlGenericError (xmlGenericErrorContext,
-		    "xmlNanoHTTPConnectHost:  %s '%s' - %s",
-		    "Failed to resolve host", host, gai_strerror (status));
-
+	    __xmlIOErr(XML_FROM_HTTP, 0, "getaddrinfo failed\n");
 	    return (-1);
 	}
 
@@ -1077,13 +1057,9 @@
 		    h_err_txt = "No error text defined.";
 		    break;
 	    }
-	    xmlGenericError (xmlGenericErrorContext,
-		"xmlNanoHTTPConnectHost:  %s '%s' - %s",
-		"Failed to resolve host", host, h_err_txt);
+	    __xmlIOErr(XML_FROM_HTTP, 0, h_err_txt);
 #else
-	    xmlGenericError (xmlGenericErrorContext,
-		"xmlNanoHTTPConnectHost:  %s '%s'",
-		"Failed to resolve host", host);
+	    __xmlIOErr(XML_FROM_HTTP, 0, "Failed to resolve host");
 #endif
 	    return (-1);
 	}
@@ -1252,27 +1228,18 @@
     }
 
     if ( ctxt == NULL ) {
-	xmlGenericError( xmlGenericErrorContext,
-			"xmlNanoHTTPMethodRedir:  %s %s.",
-			"Unable to allocate HTTP context to URI",
-			( ( redirURL == NULL ) ? URL : redirURL ) );
 	return ( NULL );
     }
 
     if ((ctxt->protocol == NULL) || (strcmp(ctxt->protocol, "http"))) {
-	xmlGenericError( xmlGenericErrorContext,
-			"xmlNanoHTTPMethodRedir:  %s - %s.",
-			"Not a valid HTTP URI",
-			( ( redirURL == NULL ) ? URL : redirURL ) );
+	__xmlIOErr(XML_FROM_HTTP, XML_HTTP_URL_SYNTAX, "Not a valid HTTP URI");
         xmlNanoHTTPFreeCtxt(ctxt);
 	if (redirURL != NULL) xmlFree(redirURL);
         return(NULL);
     }
     if (ctxt->hostname == NULL) {
-	xmlGenericError( xmlGenericErrorContext,
-			"xmlNanoHTTPMethodRedir:  %s - %s",
-			"Failed to identify host in URI",
-			( ( redirURL == NULL ) ? URL : redirURL ) );
+	__xmlIOErr(XML_FROM_HTTP, XML_HTTP_UNKNOWN_HOST,
+	           "Failed to identify host in URI");
         xmlNanoHTTPFreeCtxt(ctxt);
 	if (redirURL != NULL) xmlFree(redirURL);
         return(NULL);
@@ -1305,9 +1272,7 @@
     bp = xmlMallocAtomic(blen);
     if ( bp == NULL ) {
         xmlNanoHTTPFreeCtxt( ctxt );
-	xmlGenericError( xmlGenericErrorContext,
-			"xmlNanoHTTPMethodRedir:  %s",
-			"Error allocating HTTP header buffer." );
+	xmlHTTPErrMemory("allocating header buffer");
 	return ( NULL );
     }
 
diff --git a/parser.c b/parser.c
index 69a9c4c..de6b6e0 100644
--- a/parser.c
+++ b/parser.c
@@ -8271,8 +8271,7 @@
     xmlParseContent(ctxt);
     if (!IS_BYTE_CHAR(RAW)) {
         xmlFatalErrMsgStrIntStr(ctxt, XML_ERR_TAG_NOT_FINISHED,
-		     "Premature end of data in tag %s line %d\n"
-		     "Couldn't find end of Start Tag %s line %d\n",
+	 "Premature end of data in tag %s line %d\n",
 		                name, line, NULL);
 
 	/*
diff --git a/xmlIO.c b/xmlIO.c
index 41a7d9c..67d9c41 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -173,8 +173,20 @@
     "No such process",		/* ESRCH */
     "Operation timed out",	/* ETIMEDOUT */
     "Improper link",		/* EXDEV */
-    "Attempt to load network entity %s" /* XML_IO_NETWORK_ATTEMPT */
+    "Attempt to load network entity %s", /* XML_IO_NETWORK_ATTEMPT */
     "encoder error",		/* XML_IO_ENCODER */
+    "flush error",
+    "write error",
+    "no input",
+    "buffer full",
+    "loading error",
+    "not a socket",		/* ENOTSOCK */
+    "already connected",	/* EISCONN */
+    "connection refuxed",	/* ECONNREFUSED */
+    "unreachable network",	/* ENETUNREACH */
+    "adddress in use",		/* EADDRINUSE */
+    "already in use",		/* EALREADY */
+    "unknown address familly",	/* EAFNOSUPPORT */
 };
 
 /**
@@ -190,14 +202,15 @@
 }
 
 /**
- * xmlIOErr:
+ * __xmlIOErr:
  * @code:  the error number
+ * @
  * @extra:  extra informations
  *
  * Handle an I/O error
  */
-static void
-xmlIOErr(int code, const char *extra)
+void
+__xmlIOErr(int domain, int code, const char *extra)
 {
     unsigned int idx;
 
@@ -330,6 +343,33 @@
 #ifdef EXDEV
         else if (errno == EXDEV) code = XML_IO_EXDEV;
 #endif
+#ifdef ENOTSOCK
+        else if (errno == ENOTSOCK) code = XML_IO_ENOTSOCK;
+#endif
+#ifdef EISCONN
+        else if (errno == EISCONN) code = XML_IO_EISCONN;
+#endif
+#ifdef ECONNREFUSED
+        else if (errno == ECONNREFUSED) code = XML_IO_ECONNREFUSED;
+#endif
+#ifdef ETIMEDOUT
+        else if (errno == ETIMEDOUT) code = XML_IO_ETIMEDOUT;
+#endif
+#ifdef ENETUNREACH
+        else if (errno == ENETUNREACH) code = XML_IO_ENETUNREACH;
+#endif
+#ifdef EADDRINUSE
+        else if (errno == EADDRINUSE) code = XML_IO_EADDRINUSE;
+#endif
+#ifdef EINPROGRESS
+        else if (errno == EINPROGRESS) code = XML_IO_EINPROGRESS;
+#endif
+#ifdef EALREADY
+        else if (errno == EALREADY) code = XML_IO_EALREADY;
+#endif
+#ifdef EAFNOSUPPORT
+        else if (errno == EAFNOSUPPORT) code = XML_IO_EAFNOSUPPORT;
+#endif
         else code = XML_IO_UNKNOWN;
 #endif /* HAVE_ERRNO_H */
     }
@@ -337,7 +377,20 @@
     if (code >= XML_IO_UNKNOWN) idx = code - XML_IO_UNKNOWN;
     if (idx >= (sizeof(IOerr) / sizeof(IOerr[0]))) idx = 0;
     
-    __xmlSimpleError(XML_FROM_IO, code, NULL, IOerr[idx], extra);
+    __xmlSimpleError(domain, code, NULL, IOerr[idx], extra);
+}
+
+/**
+ * xmlIOErr:
+ * @code:  the error number
+ * @extra:  extra informations
+ *
+ * Handle an I/O error
+ */
+static void
+xmlIOErr(int code, const char *extra)
+{
+    __xmlIOErr(XML_FROM_IO, code, extra);
 }
 
 /**