+ if (pattern->tag_regex != NULL)
+ {
+ /* It's a tag pattern and shouldn't be matched against URLs */
+ return 0;
+ }
+
+ return (port_matches(http->port, pattern->port_list)
+ && host_matches(http, pattern) && path_matches(http->path, pattern));
+
+}
+
+
+/*********************************************************************
+ *
+ * Function : match_portlist
+ *
+ * Description : Check if a given number is covered by a comma
+ * separated list of numbers and ranges (a,b-c,d,..)
+ *
+ * Parameters :
+ * 1 : portlist = String with list
+ * 2 : port = port to check
+ *
+ * Returns : 0 => no match
+ * 1 => match
+ *
+ *********************************************************************/
+int match_portlist(const char *portlist, int port)
+{
+ char *min, *max, *next, *portlist_copy;
+
+ min = portlist_copy = strdup(portlist);
+
+ /*
+ * Zero-terminate first item and remember offset for next
+ */
+ if (NULL != (next = strchr(portlist_copy, (int) ',')))
+ {
+ *next++ = '\0';
+ }
+
+ /*
+ * Loop through all items, checking for match
+ */
+ while (NULL != min)
+ {
+ if (NULL == (max = strchr(min, (int) '-')))
+ {
+ /*
+ * No dash, check for equality
+ */
+ if (port == atoi(min))
+ {
+ freez(portlist_copy);
+ return(1);
+ }
+ }
+ else
+ {
+ /*
+ * This is a range, so check if between min and max,
+ * or, if max was omitted, between min and 65K
+ */
+ *max++ = '\0';
+ if(port >= atoi(min) && port <= (atoi(max) ? atoi(max) : 65535))
+ {
+ freez(portlist_copy);
+ return(1);
+ }
+
+ }
+
+ /*
+ * Jump to next item
+ */
+ min = next;
+
+ /*
+ * Zero-terminate next item and remember offset for n+1
+ */
+ if ((NULL != next) && (NULL != (next = strchr(next, (int) ','))))
+ {
+ *next++ = '\0';
+ }
+ }
+
+ freez(portlist_copy);
+ return 0;
+
+}
+
+
+/*********************************************************************
+ *
+ * Function : parse_forwarder_address
+ *
+ * Description : Parse out the host and port from a forwarder address.
+ *
+ * Parameters :
+ * 1 : address = The forwarder address to parse.
+ * 2 : hostname = Used to return the hostname. NULL on error.
+ * 3 : port = Used to return the port. Untouched if no port
+ * is specified.
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out of memory
+ * JB_ERR_PARSE on malformed address.
+ *
+ *********************************************************************/
+jb_err parse_forwarder_address(char *address, char **hostname, int *port)
+{
+ char *p = address;
+
+ if ((*address == '[') && (NULL == strchr(address, ']')))
+ {
+ /* XXX: Should do some more validity checks here. */
+ return JB_ERR_PARSE;
+ }
+
+ *hostname = strdup(address);
+ if (NULL == *hostname)
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ if ((**hostname == '[') && (NULL != (p = strchr(*hostname, ']'))))
+ {
+ *p++ = '\0';
+ memmove(*hostname, (*hostname + 1), (size_t)(p - *hostname));
+ if (*p == ':')
+ {
+ *port = (int)strtol(++p, NULL, 0);
+ }
+ }
+ else if (NULL != (p = strchr(*hostname, ':')))
+ {
+ *p++ = '\0';
+ *port = (int)strtol(p, NULL, 0);
+ }
+
+ return JB_ERR_OK;
+