Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve route slug parser #92

Open
2 tasks
c9s opened this issue Nov 18, 2015 · 2 comments
Open
2 tasks

Improve route slug parser #92

c9s opened this issue Nov 18, 2015 · 2 comments

Comments

@c9s
Copy link
Owner

c9s commented Nov 18, 2015

  • Save slug name in the structure
  • Add slugs member to route struct so we can iterate the slugs in the matched route.
@c9s
Copy link
Owner Author

c9s commented Mar 8, 2016

@karantin2020 just to confirm, are the items above completed?

@karantin2020
Copy link
Contributor

  • Save slug name in the structure
  • Add slugs member to route struct so we can iterate the slugs in the matched route

Routes contain only slug names:

struct _R3Route {
    char * path;
    int    path_len;

    char **slugs;
    int    slugs_len;
    int    slugs_cap;
...
typedef struct {
    str_array * vars;
    const char * path; // current path to dispatch
    int    path_len; // the length of the current path
    int    request_method;  // current request method

    void * data; // R3Route ptr

    char * host; // the request host
    int    host_len;

    char * remote_addr;
    int    remote_addr_len;
} match_entry;

typedef struct _str_array {
  char **slugs;
  int    slugs_len;
  char **tokens;
  int    len;
  int    cap;
} str_array;

Access to slug names and it's values is through match_entry->vars.
Slug names are pointers to routers field slugs. They do not copy by value and do not create again.

The second point was not realized full.
...so we can iterate the slugs in the matched route - it is incorrect way to access slugs. Routes created only once and there is no need to change it in life time. Because slug values depend on every match path it is better to save that values in match_entry struct.
So iterate slugs with match_entry->vars.

For details see examples/routing.c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants