* @uri: pointer to an URI structure
* @str: the string to analyze
*
- * Parse a port part and fills in the appropriate fields
+ * Parse a port part and fills in the appropriate fields
* of the @uri structure
*
* port = *DIGIT
xmlParse3986Port(xmlURIPtr uri, const char **str)
{
const char *cur = *str;
- unsigned port = 0; /* unsigned for defined overflow behavior */
if (ISA_DIGIT(cur)) {
+ if (uri != NULL)
+ uri->port = 0;
while (ISA_DIGIT(cur)) {
- port = port * 10 + (*cur - '0');
-
+ if (uri != NULL)
+ uri->port = uri->port * 10 + (*cur - '0');
cur++;
}
- if (uri != NULL)
- uri->port = port & INT_MAX; /* port value modulo INT_MAX+1 */
*str = cur;
return(0);
}
cur += 2;
ret = xmlParse3986Authority(uri, &cur);
if (ret != 0) return(ret);
- if (uri->server == NULL)
- uri->port = -1;
ret = xmlParse3986PathAbEmpty(uri, &cur);
if (ret != 0) return(ret);
*str = cur;
}
}
} else {
- if ((uri->server != NULL) || (uri->port == -1)) {
+ if (uri->server != NULL) {
if (len + 3 >= max) {
temp = xmlSaveUriRealloc(ret, &max);
if (temp == NULL) goto mem_error;
}
ret[len++] = '@';
}
- if (uri->server != NULL) {
- p = uri->server;
- while (*p != 0) {
- if (len >= max) {
- temp = xmlSaveUriRealloc(ret, &max);
- if (temp == NULL) goto mem_error;
- ret = temp;
- }
- ret[len++] = *p++;
+ p = uri->server;
+ while (*p != 0) {
+ if (len >= max) {
+ temp = xmlSaveUriRealloc(ret, &max);
+ if (temp == NULL) goto mem_error;
+ ret = temp;
}
- if (uri->port > 0) {
- if (len + 10 >= max) {
- temp = xmlSaveUriRealloc(ret, &max);
- if (temp == NULL) goto mem_error;
- ret = temp;
- }
- len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
+ ret[len++] = *p++;
+ }
+ if (uri->port > 0) {
+ if (len + 10 >= max) {
+ temp = xmlSaveUriRealloc(ret, &max);
+ if (temp == NULL) goto mem_error;
+ ret = temp;
}
+ len += snprintf((char *) &ret[len], max - len, ":%d", uri->port);
}
} else if (uri->authority != NULL) {
if (len + 3 >= max) {
if (temp == NULL) goto mem_error;
ret = temp;
}
+ ret[len++] = '/';
+ ret[len++] = '/';
}
if (uri->path != NULL) {
p = uri->path;