View | Details | Raw Unified | Return to bug 38889
Collapse All | Expand All

(-)jk/native/common/jk_uri_worker_map.c.ORIG (-1 / +40 lines)
Lines 36-46 Link Here
36
#define JK_STRNCMP  strncmp
36
#define JK_STRNCMP  strncmp
37
#endif
37
#endif
38
38
39
40
/*
41
 * Given context uri, count the number of path tokens.
42
 *
43
 * Servlet specification 2.4, SRV.11.1 says
44
 
45
 *   The container will recursively try tomatch the longest
46
 *   path-prefix. This is done by stepping down the path tree a
47
 *   directory at a time, using the / character as a path
48
 *   separator. The longest match determines the servlet selected.
49
 *
50
 * The implication seems to be `most uri path elements is most exact'.
51
 * This is a little helper function to count uri tokens, so we can
52
 * keep the worker map sorted with most specific first.
53
 */
54
static int worker_count_context_uri_tokens(const char * context) {
55
  const char * c = context;
56
  int count = 0;
57
  while (c && *c) {
58
    if ('/' == *c++) {
59
      count++;
60
    }
61
  }
62
  return count;
63
}
64
65
39
static int worker_compare(const void *elem1, const void *elem2)
66
static int worker_compare(const void *elem1, const void *elem2)
40
{
67
{
41
    uri_worker_record_t *e1 = *(uri_worker_record_t **)elem1;
68
    uri_worker_record_t *e1 = *(uri_worker_record_t **)elem1;
42
    uri_worker_record_t *e2 = *(uri_worker_record_t **)elem2;
69
    uri_worker_record_t *e2 = *(uri_worker_record_t **)elem2;
43
    return ((int)e2->context_len - (int)e1->context_len);
70
    int e1_tokens = 0;
71
    int e2_tokens = 0;
72
73
    e1_tokens = worker_count_context_uri_tokens(e1->context);
74
    e2_tokens = worker_count_context_uri_tokens(e2->context);
75
76
    if (e1_tokens != e2_tokens) {
77
      return (e2_tokens - e1_tokens);
78
    }
79
80
    /* given the same number of URI tokens, use character
81
     * length as a tie breaker */
82
    return (e2->context_len - e1->context_len);
44
}
83
}
45
84
46
static void worker_qsort(jk_uri_worker_map_t *uw_map)
85
static void worker_qsort(jk_uri_worker_map_t *uw_map)

Return to bug 38889