Add const fix

This commit is contained in:
c9s 2014-06-03 23:42:40 +08:00
parent 2ff85c876d
commit a3c527e1b2
4 changed files with 15 additions and 11 deletions

View file

@ -122,7 +122,7 @@ edge * r3_node_find_edge(const node * n, const char * pat, int pat_len);
void r3_node_append_edge(node *n, edge *child);
edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *prefix_len, char **errstr);
edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *prefix_len, const char **errstr);
node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * data);
@ -136,7 +136,7 @@ route * r3_tree_insert_routel(node *tree, int method, const char *path, int path
/**
* The private API to insert a path
*/
node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, char ** errstr);
node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, const char ** errstr);
void r3_tree_dump(const node * n, int level);

View file

@ -496,7 +496,7 @@ node * r3_tree_insert_pathl(node *tree, const char *path, int path_len, void * d
* 4. "aaa{slug:xxx}/hate" vs "aab{slug:yyy}/bar" => common prefix = "aa"
* 5. "/foo/{slug}/hate" vs "/fo{slug}/bar" => common prefix = "/fo"
*/
edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *prefix_len, char **errstr) {
edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *prefix_len, const char **errstr) {
int i = 0;
int prefix = 0;
*prefix_len = 0;
@ -557,7 +557,7 @@ edge * r3_node_find_common_prefix(node *n, const char *path, int path_len, int *
/**
* Return the last inserted node.
*/
node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, char **errstr)
node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route * route, void * data, const char **errstr)
{
node * n = tree;
@ -568,7 +568,7 @@ node * r3_tree_insert_pathl_ex(node *tree, const char *path, int path_len, route
/* length of common prefix */
int prefix_len = 0;
char *err = NULL;
const char *err = NULL;
e = r3_node_find_common_prefix(tree, path, path_len, &prefix_len, &err);
if (err) {
// copy the error message pointer

View file

@ -76,7 +76,7 @@ Return 1 => Slug found
Return -1 => Slug parsing error
*/
int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, const char *offset, char **errstr) {
int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, const char *offset, const char **errstr) {
s->path = (char*) needle;
s->path_len = needle_len;
@ -138,7 +138,9 @@ int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, const char *
if (state != 0) {
if (errstr) {
asprintf(errstr, "Incomplete slug pattern. PATH (%d): '%s', OFFSET: %ld, STATE: %d", needle_len, needle, p - needle, state);
char *err = NULL;
asprintf(&err, "Incomplete slug pattern. PATH (%d): '%s', OFFSET: %ld, STATE: %d", needle_len, needle, p - needle, state);
*errstr = err;
}
return -1;
}
@ -150,7 +152,7 @@ int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, const char *
/**
* provide a quick way to count slugs, simply search for '{'
*/
int slug_count(const char * needle, int len, char **errstr) {
int slug_count(const char * needle, int len, const char **errstr) {
int cnt = 0;
int state = 0;
char * p = (char*) needle;
@ -174,7 +176,9 @@ int slug_count(const char * needle, int len, char **errstr) {
info("FOUND PATTERN: '%s' (%d), STATE: %d\n", needle, len, state);
if (state != 0) {
if (errstr) {
asprintf(errstr, "Incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
char *err = NULL;
asprintf(&err, "Incomplete slug pattern. PATTERN (%d): '%s', OFFSET: %ld, STATE: %d", len, needle, p - needle, state);
*errstr = err;
}
return -1;
}

View file

@ -43,13 +43,13 @@ r3_slug_t * r3_slug_new(const char * path, int path_len);
int r3_slug_check(r3_slug_t *s);
int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, const char *offset, char **errstr);
int r3_slug_parse(r3_slug_t *s, const char *needle, int needle_len, const char *offset, const char **errstr);
char * r3_slug_to_str(const r3_slug_t *s);
void r3_slug_free(r3_slug_t * s);
int slug_count(const char * needle, int len, char **errstr);
int slug_count(const char * needle, int len, const char **errstr);
static inline int r3_path_contains_slug_char(const char * str) {
return strchr(str, '{') != NULL ? 1 : 0;