Giter Site home page Giter Site logo

url's Introduction

URL parse

mini URL parse code.

url struct define:

/*
 * parse url like this
 *
 * schema://username:password@host:port/path?key=value#fragment
 * \____/   \______/ \______/ \__/ \__/ \__/ \_______/ \______/
 *   |         |        |       |    |    |      |         |
 * schema      |     password   |   port  |    query    fragment
 *          username          host      path
 *
 * note:
 *   - username, password, port, path, query, fragment is optional.
 *   - scheme, host must be setting.
 *   - username and password must be paired.
 *
 */

typedef struct _url_field
{
   host_type_t host_type;
   char *href;
   char *schema;
   char *username;
   char *password;
   char *host;
   char *port;
   char *path;
   char *query;
   char *fragment;
} url_field_t;

parse function define:

url_field_t *url_parse(const char *str);
void url_free(url_field_t *url);
void url_field_print(url_field_t *url);

Usage:

int main()
{
   char *str[] = {
      "scheme://0.0.0.0",
      "http://username:password@[::1]:8080/index.html",
      "scheme://username:[email protected]",
      "scheme://host:port",
      "scheme://host:port/path?id=1&method=get#fragment",
      "scheme://host/path/to/subpath#fragment",
      "scheme://username:password@host/path?name=test#fragment",
      "scheme://username:password@host:port/path?name=test#fragment",
      NULL
   };
   for (int i = 0; str[i]; i++)
   {
      url_field_t *url = url_parse(str[i]);
      url_field_print(url);
      url_free(url);
   }
   return 0;
}

url's People

Contributors

guidefloripa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.