Skip to content

Commit

Permalink
Merge pull request #46 from LeSpocky/maintenance
Browse files Browse the repository at this point in the history
collected maintenance changes
  • Loading branch information
LeSpocky committed Jul 20, 2018
2 parents c13110c + d5bf438 commit 6ba2fe2
Show file tree
Hide file tree
Showing 23 changed files with 102 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ libcgi.a
libcgi.so
autom4te.cache
configure
src/config.h
*swp
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ option(BUILD_SHARED_LIBS
)

# subdirectories
add_subdirectory("include/libcgi")
add_subdirectory("src")

# test
Expand Down
15 changes: 15 additions & 0 deletions include/libcgi/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#
# Copyright 2018 Alexander Dahl <[email protected]>
#

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
)

install(FILES
cgi.h
error.h
session.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/libcgi"
)
21 changes: 19 additions & 2 deletions src/cgi.h → include/libcgi/cgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@

#include <stdio.h>

#if defined(__GNUC__)
#define CGI_DEPRECATED __attribute__ ((deprecated))
#elif defined(_MSC_VER)
#define CGI_DEPRECATED __declspec(deprecated)
#elif defined(__clang__)
#define CGI_DEPRECATED __deprecated
#else
#pragma message("WARNING: You need to implement CGI_DEPRECATED for this compiler")
#define CGI_DEPRECATED
#endif

#ifdef __cplusplus
extern "C" {
#endif


// general purpose linked list. Actually isn't very portable
// because uses only 'name' and 'value' variables to store data.
// Problably, in a future release, this will be replaced by
Expand Down Expand Up @@ -81,7 +91,7 @@ extern char *stripslashes(char *str);
extern char *str_base64_encode(char *str);
extern char *str_base64_decode(char *str);
extern char *recvline(FILE *fp);
extern char *md5(const char *str);
CGI_DEPRECATED char *md5(const char *str);
extern char *cgi_ltrim(char *str);
extern char *cgi_rtrim(char *str);
extern char *cgi_trim(char *str);
Expand Down Expand Up @@ -126,6 +136,13 @@ extern void cgi_session_save_path(const char *path);
*/
void cgi_session_free( void );

/**
* The version of this library.
*
* @return Version string.
*/
const char *cgi_version( void );

#ifdef __cplusplus
}
#endif
Expand Down
16 changes: 16 additions & 0 deletions include/libcgi/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*******************************************************************//**
* @file config.h
*
* @brief Stuff set by the build system.
*
* @author Alexander Dahl <[email protected]>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
* License-Filename: COPYING
*
* @copyright 2018 Alexander Dahl and libcgi contributors
**********************************************************************/

#pragma once

#define CGI_VERSION "v@PROJECT_VERSION@"
File renamed without changes.
File renamed without changes.
19 changes: 3 additions & 16 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@
# Copyright 2013,2016,2018 Alexander Dahl <[email protected]>
#

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
)

set(CGI_SRC
base64.c
cgi.c
cookie.c
error.c
general.c
list.c
# md5.c
md5.c
session.c
string.c
)
Expand All @@ -32,8 +27,8 @@ set_target_properties(${PROJECT_NAME} PROPERTIES

target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

Expand All @@ -49,11 +44,3 @@ install(EXPORT ${PROJECT_NAME}-targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)

# install headers
install(FILES
cgi.h
error.h
session.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/lib${PROJECT_NAME}"
)
2 changes: 1 addition & 1 deletion src/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ LICENCE: Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc.
#include <stdlib.h>
#include <string.h>

#include "error.h"
#include "libcgi/error.h"

static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
Expand Down
9 changes: 7 additions & 2 deletions src/cgi.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#include <ctype.h>
#include <sys/stat.h> /* for cgi_include() */

#include "cgi.h"
#include "error.h"
#include "libcgi/cgi.h"
#include "libcgi/config.h"
#include "libcgi/error.h"

// There's no reason to not have this initialised.
static const char hextable[256] = {
Expand Down Expand Up @@ -551,6 +552,10 @@ void cgi_send_header(const char *header)
printf("%s\r\n", header);
}

const char *cgi_version( void )
{
return CGI_VERSION;
}

/**
* @}
Expand Down
1 change: 0 additions & 1 deletion src/config.h.cmake.in

This file was deleted.

4 changes: 2 additions & 2 deletions src/cookie.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <stdlib.h>
#include <string.h>

#include "error.h"
#include "cgi.h"
#include "libcgi/cgi.h"
#include "libcgi/error.h"

formvars *cookies_start = NULL;
formvars *cookies_last = NULL;
Expand Down
4 changes: 2 additions & 2 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include <stdarg.h>
#include <stdlib.h>

#include "error.h"
#include "cgi.h"
#include "libcgi/cgi.h"
#include "libcgi/error.h"

const char *libcgi_error_type[] = {
"LibCGI Warning",
Expand Down
4 changes: 2 additions & 2 deletions src/general.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#include <string.h>
#include <stdlib.h>

#include "error.h"
#include "cgi.h"
#include "libcgi/cgi.h"
#include "libcgi/error.h"

struct iso8859_15 {
char code;
Expand Down
4 changes: 2 additions & 2 deletions src/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <stdlib.h>
#include <string.h>

#include "error.h"
#include "cgi.h"
#include "libcgi/cgi.h"
#include "libcgi/error.h"

// Add a new item to the list
void slist_add(formvars *item, formvars **start, formvars **last)
Expand Down
8 changes: 2 additions & 6 deletions src/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@
#include <stdlib.h>
#include <string.h>

#include "config.h"
#include "error.h"
#include "cgi.h"
#include "libcgi/cgi.h"
#include "libcgi/error.h"

/** @ingroup libcgi_general
* @{
*/

#if HAVE_MD5

#ifndef MD5_H
#define MD5_H

Expand Down Expand Up @@ -95,7 +92,6 @@ char *md5(const char *str)
// returning a encrypted string
return tmp;
}
#endif

/*=======================================================================*/

Expand Down
6 changes: 3 additions & 3 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
#include <unistd.h>
#include <errno.h>

#include "cgi.h"
#include "session.h"
#include "error.h"
#include "libcgi/cgi.h"
#include "libcgi/error.h"
#include "libcgi/session.h"

// session id length
#define SESS_ID_LEN 45
Expand Down
4 changes: 2 additions & 2 deletions src/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include <stdarg.h>
#include <ctype.h>

#include "cgi.h"
#include "error.h"
#include "libcgi/cgi.h"
#include "libcgi/error.h"

/*********************************************************
* STRING GROUP
Expand Down
8 changes: 8 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ add_executable(cgi-test
cgi_test.c
test.c
)
target_compile_definitions(cgi-test
PRIVATE
_POSIX_C_SOURCE=200112L
_XOPEN_SOURCE
)
target_link_libraries(cgi-test
${PROJECT_NAME}
)
Expand All @@ -28,6 +33,9 @@ add_test(NAME cgi_ltrim
add_test(NAME cgi_rtrim
COMMAND cgi-test rtrim
)
add_test(NAME cgi_version
COMMAND cgi-test version
)

# slist
add_executable(cgi-test-slist
Expand Down
16 changes: 14 additions & 2 deletions test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

#include "cgi_test.h"

#include "cgi.h"
#include "libcgi/cgi.h"
#include "libcgi/config.h"

extern formvars *
process_data(const char *query, formvars **start, formvars **last,
Expand All @@ -23,6 +24,7 @@ static int test_cgi_param_multiple( void );
static int test_cgi_process_form( void );
static int _test_ltrim( void );
static int _test_rtrim( void );
static int version( void );

int main( int argc, char *argv[] )
{
Expand All @@ -33,6 +35,7 @@ int main( int argc, char *argv[] )
{ "process_form", test_cgi_process_form },
{ "ltrim", _test_ltrim },
{ "rtrim", _test_rtrim },
{ "version", version },
};

/* require at least one argument to select test */
Expand Down Expand Up @@ -61,7 +64,6 @@ int test_cgi_escape_special_chars( void )

for (c = 0; c < 256; ++c)
str[c] = (char) c + 1;
str[c] = 0;

check( strlen(str) == 255, "strlen" );
check( esc = cgi_escape_special_chars(str), "escape" );
Expand Down Expand Up @@ -312,3 +314,13 @@ int _test_rtrim( void )
error:
return EXIT_FAILURE;
}

int version( void )
{
check( 0 == strcmp( CGI_VERSION, cgi_version() ),
"strcmp( '%s', '%s' )", CGI_VERSION, cgi_version() );

return EXIT_SUCCESS;
error:
return EXIT_FAILURE;
}
2 changes: 1 addition & 1 deletion test/test_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "cgi_test.h"

#include "cgi.h"
#include "libcgi/cgi.h"

#define CGI_TEST_SHRT_COOKIE_NAME "cgi_sess"
#define CGI_TEST_COOKIE_NAME_49 "_______ten____twenty____thirty____fourty_____fift"
Expand Down
2 changes: 1 addition & 1 deletion test/test_slist.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "cgi_test.h"

#include "cgi.h"
#include "libcgi/cgi.h"

/* declarations for functions not declared in src */
formvars *process_data(const char *query, formvars **start, formvars **last,
Expand Down
2 changes: 1 addition & 1 deletion test/test_trim.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "cgi_test.h"

#include "cgi.h"
#include "libcgi/cgi.h"

/* trim.c */
char* ltrim(char* s);
Expand Down

0 comments on commit 6ba2fe2

Please sign in to comment.