Skip to content

ShadowsocksR-Live/uri-encode-c

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

encode_uri

An optimized C library for percent encoding/decoding text

Description

This is a URI encoder/decoder written in C based on RFC3986. This module always encodes characters that are not unreserved. When decoding, invalid escape sequences are preserved.

The code is optimized for speed and has a reasonable test suite. It will also encode and decode null bytes in the middle of strings (assuming you calculated the string length correctly!).

Synopsis

#include <stdlib.h>
#include <string.h>
#include <uri_encode.h>

/* encode text */
const char* uri = "Some data!That Needs Encoding/";
size_t len = strlen(uri);
size_t b_len = uri_encode_buffer_size(uri, len);
char *buffer = (char*) calloc(b_len, sizeof(char));
assert(buffer != NULL);
buffer[0] = '\0';
uri_encode(uri, len, buffer, b_len);

/* decode text */
const char* encoded_uri = "Some%20data%21That%20Needs%20Encoding%2F";
size_t len2 = strlen(encoded_uri);
char *decoded_uri = (char*)calloc(len2 + 1, sizeof(char));
assert(decoded_uri != NULL);
decoded_uri[0] = '\0';
uri_decode(encoded_uri, decoded_uri, len2 + 1);

assert(strcmp(decoded_uri, uri) == 0);

free(decoded_uri);
free(buffer);

Installation

Builds, tests and installs a static library: liburi_encode.a

clone https://github.com/ssrlive/uri-encode-c.git uri
cd uri
make
make test
sudo make install

To install to a custom location, edit DESTDIR and PREFIX in Makefile.

Uninstallation

sudo make uninstall

See Also

Authors

© 2016

Version

0.04

License

See LICENSE

About

C library for URI percent encoding/decoding

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 92.9%
  • CMake 4.1%
  • Makefile 3.0%