Permalink
Browse files

Merge branch 'release/1.1.0'

Conflicts:
	evhtp.c
  • Loading branch information...
2 parents f5b6e21 + 035ea3a commit 5e9f12fcc0090c226361e514ba6d02a0ce21cb76 Mark Ellzey committed Aug 16, 2012
Showing with 54 additions and 262 deletions.
  1. +5 −0 ChangeLog
  2. +44 −225 evhtp.c
  3. +5 −37 evhtp.h
View
@@ -1,3 +1,8 @@
+v1.1.0
+ o Add ability for rules to be ordered. (ad8c468 Mark Ellzey)
+ o Cleanup the old rule code. (fbfda73 Mark Ellzey)
+ o Fixed missing variable in callback_find (4eb5e87 Mark Ellzey)
+
v1.0.1
o Fixes to make coverity happy. (6776d85 Mark Ellzey)
o Add support for empty header values. (7ec160f Mark Ellzey)
View
@@ -494,41 +494,6 @@ _evhtp_hostname_hook(evhtp_request_t * r, const char * hostname) {
}
/**
- * @brief attempts to find a callback via hashing the path
- *
- * @param callbacks a evhtp_callbacks_t * structure
- * @param path a null terminated string to be hashed and searched
- *
- * @return evhtp_callback_t * if found, NULL if not found.
- */
-static evhtp_callback_t *
-_evhtp_callback_hash_find(evhtp_callbacks_t * callbacks, const char * path) {
- evhtp_callback_t * callback;
- unsigned int hash;
- unsigned int shash;
-
- if (path == NULL) {
- return NULL;
- }
-
- hash = _evhtp_quick_hash(path);
- shash = (hash & (callbacks->buckets - 1));
- callback = callbacks->callbacks[shash];
-
- while (callback != NULL) {
- if (callback->hash == hash &&
- callback->type == evhtp_callback_type_hash &&
- strcmp(callback->val.path, path) == 0) {
- return callback;
- }
-
- callback = callback->next;
- }
-
- return NULL;
-}
-
-/**
* @brief glob/wildcard type pattern matching.
*
* Note: This code was derived from redis's (v2.6) stringmatchlen() function.
@@ -599,126 +564,53 @@ _evhtp_glob_match(const char * pattern, const char * string) {
return 0;
} /* _evhtp_glob_match */
-/**
- * @brief iterate through a list of glob/wildcard defined callbacks.
- *
- * @param callbacks
- * @param path
- *
- * @return
- */
-static evhtp_callback_t *
-_evhtp_callback_glob_find(evhtp_callbacks_t * callbacks, const char * path) {
- evhtp_callback_t * callback;
-
- if (!callbacks || !path) {
- return NULL;
- }
-
- callback = callbacks->glob_callbacks;
-
- while (callback != NULL) {
- if (callback->type == evhtp_callback_type_glob) {
- if (_evhtp_glob_match(callback->val.glob, path) == 1) {
- return callback;
- }
- }
-
- callback = callback->next;
- }
-
- return NULL;
-}
-
-/**
- * @brief iterate through a tailq of callback hooks defined as a regex until a
- * match is found.
- *
- * @param callbacks a evhtp_callbacks_t structure
- * @param path a string containing a path to be matched against
- * @param soff a pointer to an integer which will be filled with the start
- * offset in the string if matched.
- * @param eoff a pointer to an integer which will be filled with the end
- * offset in the string if matched
- *
- * @return an evhtp_callback_t function on success, otherwise NULL
- */
-#ifndef EVHTP_DISABLE_REGEX
-static evhtp_callback_t *
-_evhtp_callback_regex_find(evhtp_callbacks_t * callbacks, const char * path,
- unsigned int * soff, unsigned int * eoff) {
- evhtp_callback_t * callback = callbacks->regex_callbacks;
-
- if (path == NULL) {
- return NULL;
- }
-
- while (callback != NULL) {
- regmatch_t pmatch[28];
-
- if (callback->type == evhtp_callback_type_regex) {
- if (regexec(callback->val.regex, path, callback->val.regex->re_nsub + 1, pmatch, 0) == 0) {
- *soff = (unsigned int)pmatch[callback->val.regex->re_nsub].rm_so;
- *eoff = (unsigned int)pmatch[callback->val.regex->re_nsub].rm_eo;
-
- return callback;
- }
- }
-
- callback = callback->next;
- }
-
- return NULL;
-}
-
-#endif
-
-/**
- * @brief A wrapper around hash, glob, and regex hook lookups
- * Search is done in this order:
- * hash
- * glob
- * regex
- *
- * @param callbacks
- * @param path
- * @param start_offset
- * @param end_offset
- *
- * @return evhtp_callback_t on success, otherwise NULL
- */
static evhtp_callback_t *
-_evhtp_callback_find(evhtp_callbacks_t * callbacks,
+_evhtp_callback_find(evhtp_callbacks_t * cbs,
const char * path,
unsigned int * start_offset,
unsigned int * end_offset) {
+#ifndef EVHTP_DISABLE_REGEX
+ regmatch_t pmatch[28];
+#endif
evhtp_callback_t * callback;
- if (callbacks == NULL) {
+ if (cbs == NULL) {
return NULL;
}
- if ((callback = _evhtp_callback_hash_find(callbacks, path)) != NULL) {
- *start_offset = 0;
- *end_offset = (unsigned int)strlen(path);
- return callback;
- }
+ TAILQ_FOREACH(callback, cbs, next) {
+ switch (callback->type) {
+ case evhtp_callback_type_hash:
+ if (strcmp(callback->val.path, path) == 0) {
+ *start_offset = 0;
+ *end_offset = (unsigned int)strlen(path);
+ return callback;
+ }
+ break;
+#ifndef EVHTP_DISABLE_REGEX
+ case evhtp_callback_type_regex:
+ if (regexec(callback->val.regex, path, callback->val.regex->re_nsub + 1, pmatch, 0) == 0) {
+ *start_offset = pmatch[callback->val.regex->re_nsub].rm_so;
+ *end_offset = pmatch[callback->val.regex->re_nsub].rm_eo;
- if ((callback = _evhtp_callback_glob_find(callbacks, path)) != NULL) {
- *start_offset = 0;
- *end_offset = (unsigned int)strlen(path);
- return callback;
- }
+ return callback;
+ }
-#ifndef EVHTP_DISABLE_REGEX
- if ((callback = _evhtp_callback_regex_find(callbacks, path,
- start_offset, end_offset)) != NULL) {
- return callback;
- }
+ break;
#endif
+ case evhtp_callback_type_glob:
+ if (_evhtp_glob_match(callback->val.glob, path) == 1) {
+ *start_offset = 0;
+ *end_offset = (unsigned int)strlen(path);
+ return callback;
+ }
+ default:
+ break;
+ } /* switch */
+ }
return NULL;
-}
+} /* _evhtp_callback_find */
/**
* @brief Creates a new evhtp_request_t
@@ -2632,63 +2524,9 @@ evhtp_unbind_socket(evhtp_t * htp, int deinit_status_codes) {
evconnlistener_free(htp->server);
}
-evhtp_callbacks_t *
-evhtp_callbacks_new(unsigned int buckets) {
- evhtp_callbacks_t * cbs;
-
- if (!(cbs = calloc(sizeof(evhtp_callbacks_t), 1))) {
- return NULL;
- }
-
- if (!(cbs->callbacks = calloc(sizeof(evhtp_callback_t *), buckets))) {
- free(cbs);
- return NULL;
- }
-
- cbs->buckets = buckets;
- cbs->count = 0;
-
- return cbs;
-}
-
void
evhtp_callbacks_free(evhtp_callbacks_t * callbacks) {
- evhtp_callback_t * callback;
- evhtp_callback_t * next;
- unsigned int idx;
-
- if (callbacks == NULL) {
- return;
- }
-
- if (callbacks->callbacks) {
- for (idx = 0; idx < callbacks->buckets; idx++) {
- if (callbacks->callbacks[idx] == NULL) {
- continue;
- }
-
- callback = callbacks->callbacks[idx];
-
- while (callback != NULL) {
- next = callback->next;
- evhtp_callback_free(callback);
- callback = next;
- }
- }
- free(callbacks->callbacks);
- }
-
-#ifndef EVHTP_DISABLE_REGEX
- callback = callbacks->regex_callbacks;
-
- while (callback != NULL) {
- next = callback->next;
- evhtp_callback_free(callback);
- callback = next;
- }
-#endif
-
- free(callbacks);
+ /* XXX TODO */
}
evhtp_callback_t *
@@ -2757,32 +2595,7 @@ evhtp_callback_free(evhtp_callback_t * callback) {
int
evhtp_callbacks_add_callback(evhtp_callbacks_t * cbs, evhtp_callback_t * cb) {
- unsigned int hkey;
-
- switch (cb->type) {
- case evhtp_callback_type_hash:
- hkey = cb->hash & (cbs->buckets - 1);
-
- if (cbs->callbacks[hkey] == NULL) {
- cbs->callbacks[hkey] = cb;
- } else {
- cb->next = cbs->callbacks[hkey];
- cbs->callbacks[hkey] = cb;
- }
- break;
-#ifndef EVHTP_DISABLE_REGEX
- case evhtp_callback_type_regex:
- cb->next = cbs->regex_callbacks;
- cbs->regex_callbacks = cb;
- break;
-#endif
- case evhtp_callback_type_glob:
- cb->next = cbs->glob_callbacks;
- cbs->glob_callbacks = cb;
- break;
- default:
- return -1;
- } /* switch */
+ TAILQ_INSERT_TAIL(cbs, cb, next);
return 0;
}
@@ -2918,10 +2731,12 @@ evhtp_set_cb(evhtp_t * htp, const char * path, evhtp_callback_cb cb, void * arg)
_evhtp_lock(htp);
if (htp->callbacks == NULL) {
- if (!(htp->callbacks = evhtp_callbacks_new(1024))) {
+ if (!(htp->callbacks = calloc(sizeof(evhtp_callbacks_t), sizeof(char)))) {
_evhtp_unlock(htp);
return NULL;
}
+
+ TAILQ_INIT(htp->callbacks);
}
if (!(hcb = evhtp_callback_new(path, evhtp_callback_type_hash, cb, arg))) {
@@ -2992,10 +2807,12 @@ evhtp_set_regex_cb(evhtp_t * htp, const char * pattern, evhtp_callback_cb cb, vo
_evhtp_lock(htp);
if (htp->callbacks == NULL) {
- if (!(htp->callbacks = evhtp_callbacks_new(1024))) {
+ if (!(htp->callbacks = calloc(sizeof(evhtp_callbacks_t), sizeof(char)))) {
_evhtp_unlock(htp);
return NULL;
}
+
+ TAILQ_INIT(htp->callbacks);
}
if (!(hcb = evhtp_callback_new(pattern, evhtp_callback_type_regex, cb, arg))) {
@@ -3022,10 +2839,12 @@ evhtp_set_glob_cb(evhtp_t * htp, const char * pattern, evhtp_callback_cb cb, voi
_evhtp_lock(htp);
if (htp->callbacks == NULL) {
- if (!(htp->callbacks = evhtp_callbacks_new(1024))) {
+ if (!(htp->callbacks = calloc(sizeof(evhtp_callbacks_t), sizeof(char)))) {
_evhtp_unlock(htp);
return NULL;
}
+
+ TAILQ_INIT(htp->callbacks);
}
if (!(hcb = evhtp_callback_new(pattern, evhtp_callback_type_glob, cb, arg))) {
Oops, something went wrong.

0 comments on commit 5e9f12f

Please sign in to comment.