[Debian-iot-packaging] [orcania] 01/02: Import Upstream version 1.1.1
Thorsten Alteholz
alteholz at moszumanska.debian.org
Sat Jan 27 18:56:00 UTC 2018
This is an automated email from the git hooks/post-receive script.
alteholz pushed a commit to branch master
in repository orcania.
commit 3e29e95ef8a4cc1f6dc3e0a8a2b6ae67323286bb
Author: Thorsten Alteholz <debian at alteholz.de>
Date: Sat Jan 27 19:51:41 2018 +0100
Import Upstream version 1.1.1
---
.gitignore | 1 +
README.md | 46 +++++++++++++++++++++++++++++++++++-----
src/Makefile | 28 +++++++++++++++++++------
src/orcania.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++-------
src/orcania.h | 19 +++++++++++++++--
test/str_test.c | 17 +++++++++++++--
6 files changed, 154 insertions(+), 22 deletions(-)
diff --git a/.gitignore b/.gitignore
index a34fb02..5f3153a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
*.o
*.so
*.so.*
+*.a
str_test
split_test
memory_test
diff --git a/README.md b/README.md
index 5706824..8b6b138 100644
--- a/README.md
+++ b/README.md
@@ -1,12 +1,24 @@
# Orcania
-Potluck with different functions for different purposes that can be shared among angharad programs
+Potluck with different functions for different purposes that can be shared among c programs
-Used my other projects.
+Used for my other projects.
## Installation
-### Prerequisites
+### Debian-ish packages
+
+[![Packaging status](https://repology.org/badge/vertical-allrepos/orcania.svg)](https://repology.org/metapackage/orcania)
+
+Orcania is now available in Debian Buster (testing) and some Debian based distributions. To install it on your device, use the following command as root:
+
+```shell
+# apt install liborcania-dev # Or apt install liborcania1.1 if you don't need the development files
+```
+
+### Manual install
+
+#### Prerequisites
You need [Jansson library](http://www.digip.org/jansson/) in order to install Orcania.
@@ -23,12 +35,36 @@ $ cd src
$ make JANSSONFLAG=-DU_DISABLE_JANSSON
```
-### Install Orcania library
+#### Install Orcania library
-Download Orania source code from Github, compile and install:
+Download Orcania source code from Github, compile and install:
```shell
$ git clone https://github.com/babelouest/orcania.git
$ cd orcania/src
$ make && sudo make install
```
+
+##### Install in a different directory
+
+To install Orcania library on a dfferent library, use a different $(PREFIX) value during install.
+
+Example: install orcania in /tmp/lib directory
+
+```shell
+$ cd src
+$ make && make PREFIX=/tmp install
+```
+
+You can install Orcania without root permission if your user has write access to `$(PREFIX)`.
+A `ldconfig` command is executed at the end of the install, it will probably fail if you don't have root permission, but this is harmless.
+If you choose to install Orcania in another directory, you must set your environment variable `LD_LIBRARY_PATH` properly.
+
+##### Install as a static archive
+
+To install Orcania library as a static archive, `liborcania.a`, use the make commands `make static*`:
+
+```shell
+$ cd src
+$ make static && sudo make static-install # or make PREFIX=/tmp static-install if you want to install in `/tmp/lib`
+```
diff --git a/src/Makefile b/src/Makefile
index 500b4e4..430a53d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -21,20 +21,24 @@
PREFIX=/usr/local
CC=gcc
CFLAGS=-c -fPIC -Wall -D_REENTRANT $(ADDITIONALFLAGS) $(JANSSONFLAG)
-LIBS=-lc -ljansson
OUTPUT=liborcania.so
-VERSION=1.1
+VERSION=1.1.1
-ifneq (($(JANSSONFLAG)),"")
+ifndef JANSSONFLAG
LJANSSON=-ljansson
endif
+LIBS=-lc $(LJANSSON)
+
all: release
liborcania.so: memory.o orcania.o base64.o
$(CC) -shared -Wl,-soname,$(OUTPUT) -o $(OUTPUT).$(VERSION) orcania.o memory.o base64.o $(LIBS)
ln -sf $(OUTPUT).$(VERSION) $(OUTPUT)
+liborcania.a: memory.o orcania.o base64.o
+ ar rcs liborcania.a memory.o orcania.o base64.o
+
orcania.o: orcania.h orcania.c
$(CC) $(CFLAGS) orcania.c
@@ -45,15 +49,19 @@ base64.o: orcania.h base64.c
$(CC) $(CFLAGS) base64.c
clean:
- rm -f *.o *.so $(OUTPUT) $(OUTPUT).*
+ rm -f *.o *.so *.a $(OUTPUT) $(OUTPUT).*
install: all
cp $(OUTPUT).$(VERSION) $(PREFIX)/lib
cp orcania.h $(PREFIX)/include
- /sbin/ldconfig -r $(PREFIX)
+ -ldconfig
+
+static-install: static
+ cp liborcania.a $(PREFIX)/lib
+ cp orcania.h $(PREFIX)/include
uninstall:
- rm -f $(PREFIX)/lib/$(OUTPUT)
+ rm -f $(PREFIX)/lib/$(OUTPUT) $(PREFIX)/lib/liborcania.a
rm -f $(PREFIX)/lib/$(OUTPUT).*
rm -f $(PREFIX)/include/orcania.h
@@ -64,3 +72,11 @@ debug: liborcania.so
release: ADDITIONALFLAGS=-O3
release: liborcania.so
+
+static-debug: ADDITIONALFLAGS=-DDEBUG -g -O0
+
+static-debug: liborcania.a
+
+static: ADDITIONALFLAGS=-O3
+
+static: liborcania.a
diff --git a/src/orcania.c b/src/orcania.c
index 5c6df58..c7f4047 100644
--- a/src/orcania.c
+++ b/src/orcania.c
@@ -31,7 +31,7 @@ char * str_replace(const char * source, const char * str_old, const char * str_n
ptr = strstr(source, str_old);
if (ptr == NULL) {
- return strdup(source);
+ return o_strdup(source);
} else {
pre_len = ptr-source;
pre = o_malloc((pre_len+1)*sizeof(char));
@@ -245,8 +245,8 @@ char * o_strrchr(const char * haystack, int c) {
}
}
-#ifdef __linux__
-char *strnstr(const char *haystack, const char *needle, size_t len) {
+#if defined(__linux__) || defined(__GLIBC__)
+static char *strnstr(const char *haystack, const char *needle, size_t len) {
int i;
size_t needle_len;
@@ -294,7 +294,7 @@ char * o_strcasestr(const char * haystack, const char * needle) {
*/
size_t o_strlen(const char * s) {
if (s == NULL) {
- return -1;
+ return 0;
} else {
return strlen(s);
}
@@ -381,13 +381,64 @@ char * trimwhitespace(char * str) {
}
/**
- * Check if an array of string has a specified value
+ * Check if an array of string has a specified value, case sensitive
*/
int string_array_has_value(const char ** array, const char * needle) {
int i;
if (array != NULL && needle != NULL) {
for (i=0; array[i] != NULL; i++) {
- if (strcmp(array[i], needle) == 0) {
+ if (o_strcmp(array[i], needle) == 0) {
+ return 1;
+ }
+ }
+ return 0;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * Check if an array of string has a specified value, case insensitive
+ */
+int string_array_has_value_case(const char ** array, const char * needle) {
+ int i;
+ if (array != NULL && needle != NULL) {
+ for (i=0; array[i] != NULL; i++) {
+ if (o_strcasecmp(array[i], needle) == 0) {
+ return 1;
+ }
+ }
+ return 0;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * Check if an array of string has a specified value, case sensitive, limit to len characters
+ */
+int string_array_has_value_n(const char ** array, const char * needle, size_t len) {
+ int i;
+ if (array != NULL && needle != NULL) {
+ for (i=0; array[i] != NULL; i++) {
+ if (o_strncmp(array[i], needle, len) == 0) {
+ return 1;
+ }
+ }
+ return 0;
+ } else {
+ return 0;
+ }
+}
+
+/**
+ * Check if an array of string has a specified value, case insensitive, limit to len characters
+ */
+int string_array_has_value_ncase(const char ** array, const char * needle, size_t len) {
+ int i;
+ if (array != NULL && needle != NULL) {
+ for (i=0; array[i] != NULL; i++) {
+ if (o_strncasecmp(array[i], needle, len) == 0) {
return 1;
}
}
@@ -416,7 +467,7 @@ int string_array_has_trimmed_value(const char ** array, const char * needle) {
break;
} else {
trimmed_value = trimwhitespace(duplicate_value);
- if (strcmp(trimmed_value, trimmed_needle) == 0) {
+ if (o_strcmp(trimmed_value, trimmed_needle) == 0) {
to_return = 1;
}
}
diff --git a/src/orcania.h b/src/orcania.h
index c1f3599..3506d18 100644
--- a/src/orcania.h
+++ b/src/orcania.h
@@ -14,7 +14,7 @@
#include <jansson.h>
#endif
-#define ORCANIA_VERSION 1.1
+#define ORCANIA_VERSION 1.1.1
/**
* char * str_replace(const char * source, char * old, char * new)
* replace all occurences of old by new in the string source
@@ -134,11 +134,26 @@ int split_string(const char * string, const char * separator, char *** return_ar
void free_string_array(char ** array);
/**
- * Check if an array of string has a specified value
+ * Check if an array of string has a specified value, case sensitive
*/
int string_array_has_value(const char ** array, const char * needle);
/**
+ * Check if an array of string has a specified value, case insensitive
+ */
+int string_array_has_value_case(const char ** array, const char * needle);
+
+/**
+ * Check if an array of string has a specified value, case sensitive, limit to len characters
+ */
+int string_array_has_value_n(const char ** array, const char * needle, size_t len);
+
+/**
+ * Check if an array of string has a specified value, case insensitive, limit to len characters
+ */
+int string_array_has_value_ncase(const char ** array, const char * needle, size_t len);
+
+/**
* Check if an array of string has a specified trimmed value
*/
int string_array_has_trimmed_value(const char ** array, const char * needle);
diff --git a/test/str_test.c b/test/str_test.c
index 57d1130..17ee9e4 100644
--- a/test/str_test.c
+++ b/test/str_test.c
@@ -114,7 +114,7 @@ END_TEST
START_TEST(test_o_strncpy)
{
- char * src = "abcd", target[5];
+ char * src = "abcd", target[5] = {0};
ck_assert_ptr_ne(o_strncpy(target, src, 3), NULL);
ck_assert_str_eq(target, "abc");
ck_assert_ptr_eq(o_strncpy(target, NULL, 4), NULL);
@@ -168,7 +168,7 @@ END_TEST
START_TEST(test_o_strlen)
{
ck_assert_int_eq(o_strlen("abcdef"), 6);
- ck_assert_int_eq(o_strlen(NULL), -1);
+ ck_assert_int_eq(o_strlen(NULL), 0);
ck_assert_int_eq(o_strlen(""), 0);
}
END_TEST
@@ -196,6 +196,18 @@ START_TEST(test_trimwhitespace)
}
END_TEST
+START_TEST(test_base64)
+{
+ char * src = "source string", encoded[128], decoded[128];
+ size_t encoded_size, decoded_size;
+ ck_assert_int_eq(o_base64_encode((unsigned char *)src, strlen(src), (unsigned char *)encoded, &encoded_size), 1);
+ ck_assert_str_eq(encoded, "c291cmNlIHN0cmluZw==");
+ ck_assert_int_eq(o_base64_decode((unsigned char *)encoded, encoded_size, (unsigned char *)decoded, &decoded_size), 1);
+ ck_assert_str_eq(decoded, src);
+ ck_assert_int_eq(decoded_size, strlen(src));
+}
+END_TEST
+
static Suite *orcania_suite(void)
{
Suite *s;
@@ -219,6 +231,7 @@ static Suite *orcania_suite(void)
tcase_add_test(tc_core, test_o_strlen);
tcase_add_test(tc_core, test_msprintf);
tcase_add_test(tc_core, test_trimwhitespace);
+ tcase_add_test(tc_core, test_base64);
tcase_set_timeout(tc_core, 30);
suite_add_tcase(s, tc_core);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-iot/orcania.git
More information about the Debian-iot-packaging
mailing list