diff --git a/src/pattern.c b/src/pattern.c index 3d8226fc2..4a3fe297e 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -1582,8 +1582,8 @@ void pattern_init_head(struct pattern_head *head) * */ -/* This function lookup for reference. If the reference is found, they return - * pointer to the struct pat_ref, else return NULL. +/* This function looks up a reference by name. If the reference is found, a + * pointer to the struct pat_ref is returned, otherwise NULL is returned. */ struct pat_ref *pat_ref_lookup(const char *reference) { @@ -1595,8 +1595,8 @@ struct pat_ref *pat_ref_lookup(const char *reference) return NULL; } -/* This function lookup for unique id. If the reference is found, they return - * pointer to the struct pat_ref, else return NULL. +/* This function looks up a reference's unique id. If the reference is found, a + * pointer to the struct pat_ref is returned, otherwise NULL is returned. */ struct pat_ref *pat_ref_lookupid(int unique_id) { @@ -1608,10 +1608,9 @@ struct pat_ref *pat_ref_lookupid(int unique_id) return NULL; } -/* This function remove all pattern matching the pointer from - * the the reference and from each expr member of the reference. This - * function returns 1 if the deletion is done and return 0 is the entry - * is not found. +/* This function removes all the patterns matching the pointer from + * the reference and from each expr member of this reference. This function + * returns 1 if the entry was found and deleted, otherwise zero. */ int pat_ref_delete_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt) { @@ -1709,7 +1708,10 @@ struct pat_ref_elt *pat_ref_find_elt(struct pat_ref *ref, const char *key) } - /* This function modify the sample of the first pattern that match the . */ +/* This function modifies the sample of pat_ref_elt in all expressions + * found under to become . It is assumed that the caller has + * already verified that belongs to . + */ static inline int pat_ref_set_elt(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value, char **err) { @@ -1735,8 +1737,8 @@ static inline int pat_ref_set_elt(struct pat_ref *ref, struct pat_ref_elt *elt, memprintf(err, "out of memory error"); return 0; } - /* Load sample in each reference. All the conversion are tested - * below, normally these calls dosn't fail. + /* Load sample in each reference. All the conversions are tested + * below, normally these calls don't fail. */ list_for_each_entry(expr, &ref->pat, list) { if (!expr->pat_head->parse_smp) @@ -1757,7 +1759,10 @@ static inline int pat_ref_set_elt(struct pat_ref *ref, struct pat_ref_elt *elt, return 1; } -/* This function modify the sample of the first pattern that match the . */ +/* This function modifies the sample of pat_ref_elt in all expressions + * found under to become , after checking that really + * belongs to . + */ int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const char *value, char **err) { struct pat_ref_elt *elt; @@ -1775,7 +1780,9 @@ int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const cha return 0; } -/* This function modify the sample of the first pattern that match the . */ +/* This function modifies to the sample of all patterns matching + * under . + */ int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **err) { struct pat_ref_elt *elt; @@ -1818,8 +1825,8 @@ int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char ** /* This function creates a new reference. is the reference name. * are PAT_REF_*. /!\ The reference is not checked, and must * be unique. The user must check the reference with "pat_ref_lookup()" - * before calling this function. If the function fail, it return NULL, - * else return new struct pat_ref. + * before calling this function. If the function fails, it returns NULL, + * otherwise it returns the new struct pat_ref. */ struct pat_ref *pat_ref_new(const char *reference, const char *display, unsigned int flags) { @@ -1855,12 +1862,12 @@ struct pat_ref *pat_ref_new(const char *reference, const char *display, unsigned return ref; } -/* This function create new reference. is the unique id. If +/* This function creates a new reference. is the unique id. If * the value of is -1, the unique id is calculated later. * are PAT_REF_*. /!\ The reference is not checked, and must * be unique. The user must check the reference with "pat_ref_lookup()" * or pat_ref_lookupid before calling this function. If the function - * fail, it return NULL, else return new struct pat_ref. + * fails, it returns NULL, otherwise it returns the new struct pat_ref. */ struct pat_ref *pat_ref_newid(int unique_id, const char *display, unsigned int flags) { @@ -1923,9 +1930,9 @@ struct pat_ref_elt *pat_ref_append(struct pat_ref *ref, const char *pattern, con return NULL; } -/* This function create sample found in , parse the pattern also - * found in and insert it in . The function copy - * in . If the function fails, it returns0 and is filled. +/* This function creates sample found in , parses the pattern also + * found in and inserts it in . The function copies + * into . If the function fails, it returns 0 and is filled. * In success case, the function returns 1. */ int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, @@ -2096,7 +2103,7 @@ void pat_ref_reload(struct pat_ref *ref, struct pat_ref *replace) HA_SPIN_UNLOCK(PATREF_LOCK, &ref->lock); } -/* This function prune all entries of . This function +/* This function prunes all entries of . This function * prunes the associated pattern_expr. It may return before the end of * the list is reached, returning 0, to yield. The caller must call it * again. Otherwise it returns 1 once done. @@ -2145,7 +2152,9 @@ int pat_ref_prune(struct pat_ref *ref) return 1; } -/* This function lookup for existing reference in pattern_head . */ +/* This function looks up any existing reference in pattern_head , and + * returns the associated pattern_expr pointer if found, otherwise NULL. + */ struct pattern_expr *pattern_lookup_expr(struct pattern_head *head, struct pat_ref *ref) { struct pattern_expr_list *expr; @@ -2592,7 +2601,7 @@ struct pattern *pattern_exec_match(struct pattern_head *head, struct sample *smp return NULL; } -/* This function prune the pattern expression. */ +/* This function prunes the pattern expressions starting at pattern_head . */ void pattern_prune(struct pattern_head *head) { struct pattern_expr_list *list, *safe; @@ -2610,10 +2619,9 @@ void pattern_prune(struct pattern_head *head) } } -/* This function lookup for a pattern matching the and return a - * pointer to a pointer of the sample stoarge. If the dont match, - * the function returns NULL. If the key cannot be parsed, the function - * fill . +/* This function searches occurrences of pattern reference element in + * expression and returns a pointer to a pointer of the sample storage. + * If is not found, NULL is returned. */ struct sample_data **pattern_find_smp(struct pattern_expr *expr, struct pat_ref_elt *ref) { @@ -2644,9 +2652,9 @@ struct sample_data **pattern_find_smp(struct pattern_expr *expr, struct pat_ref_ return NULL; } -/* This function search all the pattern matching the and delete it. - * If the parsing of the input key fails, the function returns 0 and the - * is filled, else return 1; +/* This function delets from expression all occurrences of patterns + * corresponding to pattern reference element . The function always + * returns 1. */ int pattern_delete(struct pattern_expr *expr, struct pat_ref_elt *ref) { @@ -2656,7 +2664,9 @@ int pattern_delete(struct pattern_expr *expr, struct pat_ref_elt *ref) return 1; } -/* This function compares two pat_ref** on unique_id */ +/* This function compares two pat_ref** on their unique_id, and returns -1/0/1 + * depending on their order (suitable for sorting). + */ static int cmp_pat_ref(const void *_a, const void *_b) { struct pat_ref * const *a = _a; @@ -2669,8 +2679,8 @@ static int cmp_pat_ref(const void *_a, const void *_b) return 0; } -/* This function finalize the configuration parsing. It sets all the - * automatic ids +/* This function finalizes the configuration parsing. It sets all the + * automatic ids. */ int pattern_finalize_config(void) {