Skip to content

Commit

Permalink
0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
daddinuz authored Aug 1, 2018
1 parent cc8a982 commit bb18b29
Show file tree
Hide file tree
Showing 93 changed files with 6,143 additions and 6,670 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,6 @@ cmake-build-*/
# IDEs and editors
*.idea
*.swp

# log files
*.log
52 changes: 21 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
cmake_minimum_required(VERSION 3.1)
project(http)
cmake_minimum_required(VERSION 3.8)
project(http C)

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pedantic")
if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
# using GCC
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align -Wbad-function-cast")
endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")

#####
# Archive
###
include_directories(${PROJECT_SOURCE_DIR}/include/http)
file(GLOB HEADER_FILES ${PROJECT_SOURCE_DIR}/include/http/*.h)
file(GLOB SOURCE_FILES ${PROJECT_SOURCE_DIR}/src/*.c)
add_library(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
target_link_libraries(${PROJECT_NAME} PRIVATE curl)
# dependencies
include_directories(deps)
find_package(CURL)
include(deps/atom/build.cmake)
include(deps/text/build.cmake)
include(deps/error/build.cmake)
include(deps/panic/build.cmake)
include(deps/option/build.cmake)
include(deps/alligator/build.cmake)
include(deps/traits-unit/build.cmake)

#####
# External
###
include(ext/sds/sds.cmake)
include(ext/parson/parson.cmake)
include(ext/picohttpparser/picohttpparser.cmake)
# archive
include_directories(sources)
include(sources/build.cmake)

#####
# Examples
###
set(EXAMPLE_PATH ${PROJECT_SOURCE_DIR}/examples)
# examples
include(examples/build.cmake)

add_executable(example ${EXAMPLE_PATH}/example.c)
target_include_directories(example PRIVATE ${PROJECT_SOURCE_DIR}/ext)
target_link_libraries(example PRIVATE ${PROJECT_NAME} sds parson picohttpparser)

add_executable(bench ${EXAMPLE_PATH}/bench.c)
target_link_libraries(bench PRIVATE ${PROJECT_NAME})
# tests
include_directories(tests)
include(tests/unit/build.cmake)
35 changes: 19 additions & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
The MIT License (MIT)

Copyright (c) 2017-Present Davide Di Carlo
Copyright (c) 2018 Davide Di Carlo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
# http
http
====

HTTP requests made easier.
Depends on libcurl.
Http requests made easier, depends on libcurl.

```C
#include <http.h>
#include <stdio.h>
#include <stdlib.h>

int main() {
Http_initialize();

Atom url = Atom_fromLiteral("https://api.github.com/repos/daddinuz/http/issues");
struct HttpRequestBuilder *requestBuilder = HttpRequestBuilder_new(HTTP_METHOD_GET, url);
HttpRequestBuilder_setTimeout(requestBuilder, 25);
HttpRequestBuilder_emplaceHeaders(requestBuilder,
"Authorization: token %s\n"
"Accept: application/vnd.github.VERSION.raw+json\n"
"Content-Type: application/json\n"
"User-Agent: daddinuz/http\n",
getenv("GITHUB_AUTH_TOKEN"));

const struct HttpRequest *request = HttpRequestBuilder_build(&requestBuilder);
printRequest(request);

const struct HttpResponse *response = Http_FireResult_unwrap(HttpRequest_fire(&request));
printResponse(response);

HttpResponse_delete(response);
Http_terminate();
return 0;
}
```
60 changes: 0 additions & 60 deletions bench.log

This file was deleted.

14 changes: 0 additions & 14 deletions bench.py

This file was deleted.

16 changes: 0 additions & 16 deletions bench.sh

This file was deleted.

58 changes: 58 additions & 0 deletions deps/alligator/alligator.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Author: daddinuz
* email: [email protected]
*
* Copyright (c) 2018 Davide Di Carlo
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include "alligator.h"
#include "alligator_config.h"

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || (defined(__cplusplus) && __cplusplus >= 201103L)

Option Alligator_aligned_alloc(size_t alignment, size_t size) {
void *memory = __Alligator_aligned_alloc(alignment, size);
return memory ? Option_some(memory) : None;
}

#endif

Option Alligator_malloc(const size_t size) {
void *memory = __Alligator_malloc(size);
return memory ? Option_some(memory) : None;
}

Option Alligator_calloc(const size_t numberOfMembers, const size_t memberSize) {
void *memory = __Alligator_calloc(numberOfMembers, memberSize);
return memory ? Option_some(memory) : None;
}

Option Alligator_realloc(void *ptr, size_t newSize) {
void *memory = __Alligator_realloc(ptr, newSize);
return memory ? Option_some(memory) : None;
}

void Alligator_free(void *ptr) {
__Alligator_free(ptr);
}
69 changes: 69 additions & 0 deletions deps/alligator/alligator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Author: daddinuz
* email: [email protected]
*
* Copyright (c) 2018 Davide Di Carlo
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <stddef.h>
#include <option/option.h>

#if !(defined(__GNUC__) || defined(__clang__))
#define __attribute__(...)
#endif

#define ALLIGATOR_VERSION_MAJOR 0
#define ALLIGATOR_VERSION_MINOR 24
#define ALLIGATOR_VERSION_PATCH 0
#define ALLIGATOR_VERSION_SUFFIX ""
#define ALLIGATOR_VERSION_IS_RELEASE 0
#define ALLIGATOR_VERSION_HEX 0x002400

#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || (defined(__cplusplus) && __cplusplus >= 201103L)

extern Option Alligator_aligned_alloc(size_t alignment, size_t size)
__attribute__((__warn_unused_result__));

#endif

extern Option Alligator_malloc(size_t size)
__attribute__((__warn_unused_result__));

extern Option Alligator_calloc(size_t numberOfMembers, size_t memberSize)
__attribute__((__warn_unused_result__));

extern Option Alligator_realloc(void *ptr, size_t newSize)
__attribute__((__warn_unused_result__));

extern void Alligator_free(void *ptr);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit bb18b29

Please sign in to comment.