+/*********************************************************************
+ *
+ * Function : init_domain_components
+ *
+ * Description : Splits the domain name so we can compare it
+ * against wildcards. It used to be part of
+ * parse_http_url, but was separated because the
+ * same code is required in chat in case of
+ * intercepted requests.
+ *
+ * Parameters :
+ * 1 : http = pointer to the http structure to hold elements.
+ *
+ * Returns : JB_ERR_OK on success
+ * JB_ERR_MEMORY on out of memory
+ * JB_ERR_PARSE on malformed command/URL
+ * or >100 domains deep.
+ *
+ *********************************************************************/
+jb_err init_domain_components(struct http_request *http)
+{
+ char *vec[BUFFER_SIZE];
+ size_t size;
+ char *p;
+
+ http->dbuffer = strdup(http->host);
+ if (NULL == http->dbuffer)
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ /* map to lower case */
+ for (p = http->dbuffer; *p ; p++)
+ {
+ *p = (char)tolower((int)(unsigned char)*p);
+ }
+
+ /* split the domain name into components */
+ http->dcount = ssplit(http->dbuffer, ".", vec, SZ(vec), 1, 1);
+
+ if (http->dcount <= 0)
+ {
+ /*
+ * Error: More than SZ(vec) components in domain
+ * or: no components in domain
+ */
+ log_error(LOG_LEVEL_ERROR, "More than SZ(vec) components in domain or none at all.");
+ return JB_ERR_PARSE;
+ }
+
+ /* save a copy of the pointers in dvec */
+ size = (size_t)http->dcount * sizeof(*http->dvec);
+
+ http->dvec = (char **)malloc(size);
+ if (NULL == http->dvec)
+ {
+ return JB_ERR_MEMORY;
+ }
+
+ memcpy(http->dvec, vec, size);
+
+ return JB_ERR_OK;
+}