Commit 46aded9a authored by Michael Tremer's avatar Michael Tremer

Initial commit

Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parents
*.log
*.o
*.tar.xz
.deps/
.libs/
Makefile
Makefile.in
/aclocal.m4
/autom4te.cache
/build-aux
/config.*
/configure
/libtool
/stamp-h1
This diff is collapsed.
EXTRA_DIST =
CLEANFILES =
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
AM_MAKEFLAGS = --no-print-directory
AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-DSYSCONFDIR=\""$(sysconfdir)"\" \
-I${top_srcdir}/src
AM_CFLAGS = ${my_CFLAGS} \
-fvisibility=hidden \
-ffunction-sections \
-fdata-sections
AM_LDFLAGS = \
-Wl,--gc-sections \
-Wl,--as-needed
LIBLOC_CURRENT=0
LIBLOC_REVISION=0
LIBLOC_AGE=0
SED_PROCESS = \
$(AM_V_GEN)$(MKDIR_P) $(dir $@) && $(SED) \
-e 's,@VERSION\@,$(VERSION),g' \
-e 's,@prefix\@,$(prefix),g' \
-e 's,@exec_prefix\@,$(exec_prefix),g' \
-e 's,@libdir\@,$(libdir),g' \
-e 's,@includedir\@,$(includedir),g' \
< $< > $@ || rm $@
pkgconfigdir = $(libdir)/pkgconfig
%.pc: %.pc.in Makefile
$(SED_PROCESS)
pkginclude_HEADERS = \
src/loc/libloc.h
lib_LTLIBRARIES = \
src/libloc.la
src_libloc_la_SOURCES =\
src/libloc-private.h \
src/libloc.c
EXTRA_DIST += src/libloc.sym
src_libloc_la_LDFLAGS = \
$(AM_LDFLAGS) \
-version-info $(LIBLOC_CURRENT):$(LIBLOC_REVISION):$(LIBLOC_AGE) \
-Wl,--version-script=$(top_srcdir)/src/libloc.sym
src_libloc_la_DEPENDENCIES = \
${top_srcdir}/src/libloc.sym
pkgconfig_DATA = \
src/libloc.pc
EXTRA_DIST += \
src/libloc.pc.in
CLEANFILES += \
src/libloc.pc
TESTS = \
src/test-libloc
check_PROGRAMS = \
src/test-libloc
src_test_libloc_SOURCES = \
src/test-libloc.c
src_test_libloc_LDADD = \
src/libloc.la
#!/bin/sh
set -e
if [ -f .git/hooks/pre-commit.sample -a ! -f .git/hooks/pre-commit ] ; then
cp -p .git/hooks/pre-commit.sample .git/hooks/pre-commit && \
chmod +x .git/hooks/pre-commit && \
echo "Activated pre-commit hook."
fi
autoreconf --install --symlink
libdir() {
echo $(cd $1/$(gcc -print-multi-os-directory); pwd)
}
args="--prefix=/usr \
--sysconfdir=/etc \
--libdir=$(libdir /usr/lib)"
echo
echo "----------------------------------------------------------------"
echo "Initialized build system. For a common configuration please run:"
echo "----------------------------------------------------------------"
echo
echo "./configure CFLAGS='-g -O0' $args"
echo
AC_PREREQ(2.60)
AC_INIT([libloc],
[0],
[michael.tremer@ipfire.org],
[libloc],
[https://www.ipfire.org/])
AC_CONFIG_SRCDIR([src/libloc.c])
AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([
foreign
1.11
-Wall
-Wno-portability
silent-rules
tar-pax
no-dist-gzip
dist-xz
subdir-objects
])
AC_PROG_CC_STDC
AC_USE_SYSTEM_EXTENSIONS
AC_SYS_LARGEFILE
AC_CONFIG_MACRO_DIR([m4])
AM_SILENT_RULES([yes])
LT_INIT([
disable-static
pic-only
])
AC_PREFIX_DEFAULT([/usr])
AC_PROG_SED
AC_PROG_MKDIR_P
AC_ARG_ENABLE([debug],
AS_HELP_STRING([--enable-debug], [enable debug messages @<:@default=disabled@:>@]),
[], [enable_debug=no])
AS_IF([test "x$enable_debug" = "xyes"], [
AC_DEFINE(ENABLE_DEBUG, [1], [Debug messages.])
])
AC_CHECK_FUNCS([ \
__secure_getenv \
secure_getenv\
])
my_CFLAGS="\
-Wall \
-Wchar-subscripts \
-Wformat-security \
-Wmissing-declarations \
-Wmissing-prototypes \
-Wnested-externs \
-Wpointer-arith \
-Wshadow \
-Wsign-compare \
-Wstrict-prototypes \
-Wtype-limits \
"
AC_SUBST([my_CFLAGS])
AC_CONFIG_HEADERS(config.h)
AC_CONFIG_FILES([
Makefile
])
AC_OUTPUT
AC_MSG_RESULT([
$PACKAGE $VERSION
=====
prefix: ${prefix}
sysconfdir: ${sysconfdir}
libdir: ${libdir}
includedir: ${includedir}
compiler: ${CC}
cflags: ${CFLAGS}
ldflags: ${LDFLAGS}
logging: ${enable_logging}
debug: ${enable_debug}
])
libtool.m4
ltoptions.m4
ltsugar.m4
ltversion.m4
lt~obsolete.m4
.dirstamp
.deps/
.libs/
*.la
*.lo
*.trs
libloc.pc
test-libloc
/*
libloc - A library to determine the location of someone on the Internet
Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
#ifndef LIBLOC_PRIVATE_H
#define LIBLOC_PRIVATE_H
#include <stdbool.h>
#include <syslog.h>
#include <loc/libloc.h>
static inline void __attribute__((always_inline, format(printf, 2, 3)))
loc_log_null(struct loc_ctx *ctx, const char *format, ...) {}
#define loc_log_cond(ctx, prio, arg...) \
do { \
if (loc_get_log_priority(ctx) >= prio) \
loc_log(ctx, prio, __FILE__, __LINE__, __FUNCTION__, ## arg); \
} while (0)
#ifdef ENABLE_DEBUG
# define DEBUG(ctx, arg...) loc_log_cond(ctx, LOG_DEBUG, ## arg)
#else
# define DEBUG(ctx, arg...) loc_log_null(ctx, ## arg)
#endif
#define INFO(ctx, arg...) loc_log_cond(ctx, LOG_INFO, ## arg)
#define ERROR(ctx, arg...) loc_log_cond(ctx, LOG_ERR, ## arg)
#ifndef HAVE_SECURE_GETENV
# ifdef HAVE___SECURE_GETENV
# define secure_getenv __secure_getenv
# else
# error neither secure_getenv nor __secure_getenv is available
# endif
#endif
#define LOC_EXPORT __attribute__ ((visibility("default")))
void loc_log(struct loc_ctx *ctx,
int priority, const char *file, int line, const char *fn,
const char *format, ...) __attribute__((format(printf, 6, 7)));
#endif
/*
libloc - A library to determine the location of someone on the Internet
Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <loc/libloc.h>
#include "libloc-private.h"
struct loc_ctx {
int refcount;
void (*log_fn)(struct loc_ctx* ctx,
int priority, const char *file, int line, const char *fn,
const char *format, va_list args);
int log_priority;
};
void loc_log(struct loc_ctx* ctx,
int priority, const char* file, int line, const char* fn,
const char* format, ...) {
va_list args;
va_start(args, format);
ctx->log_fn(ctx, priority, file, line, fn, format, args);
va_end(args);
}
static void log_stderr(struct loc_ctx* ctx,
int priority, const char* file, int line, const char* fn,
const char* format, va_list args) {
fprintf(stderr, "libloc: %s: ", fn);
vfprintf(stderr, format, args);
}
static int log_priority(const char* priority) {
char *endptr;
int prio = strtol(priority, &endptr, 10);
if (endptr[0] == '\0' || isspace(endptr[0]))
return prio;
if (strncmp(priority, "err", 3) == 0)
return LOG_ERR;
if (strncmp(priority, "info", 4) == 0)
return LOG_INFO;
if (strncmp(priority, "debug", 5) == 0)
return LOG_DEBUG;
return 0;
}
LOC_EXPORT int loc_new(struct loc_ctx** ctx) {
struct loc_ctx* c = calloc(1, sizeof(*c));
if (!c)
return -ENOMEM;
c->refcount = 1;
c->log_fn = log_stderr;
c->log_priority = LOG_ERR;
const char* env = secure_getenv("LOC_LOG");
if (env)
loc_set_log_priority(c, log_priority(env));
INFO(c, "ctx %p created\n", c);
DEBUG(c, "log_priority=%d\n", c->log_priority);
*ctx = c;
return 0;
}
LOC_EXPORT struct loc_ctx* loc_ref(struct loc_ctx* ctx) {
if (!ctx)
return NULL;
ctx->refcount++;
return ctx;
}
LOC_EXPORT struct loc_ctx* loc_unref(struct loc_ctx* ctx) {
if (!ctx)
return NULL;
if (--ctx->refcount > 0)
return NULL;
INFO(ctx, "context %p released\n", ctx);
free(ctx);
return NULL;
}
LOC_EXPORT void loc_set_log_fn(struct loc_ctx* ctx,
void (*log_fn)(struct loc_ctx* ctx, int priority, const char* file,
int line, const char* fn, const char* format, va_list args)) {
ctx->log_fn = log_fn;
INFO(ctx, "custom logging function %p registered\n", log_fn);
}
LOC_EXPORT int loc_get_log_priority(struct loc_ctx* ctx) {
return ctx->log_priority;
}
LOC_EXPORT void loc_set_log_priority(struct loc_ctx* ctx, int priority) {
ctx->log_priority = priority;
}
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: libloc
Description: A library to determine the location of someone on the Internet
Version: @VERSION@
Libs: -L${libdir} -lloc
Libs.private:
Cflags: -I${includedir}
LIBLOC_1 {
global:
loc_ref;
loc_get_log_priority;
loc_set_log_fn;
loc_unref;
loc_set_log_priority;
loc_new;
local:
*;
};
/*
libloc - A library to determine the location of someone on the Internet
Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
*/
#ifndef LIBLOC_H
#define LIBLOC_H
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
struct loc_ctx;
struct loc_ctx *loc_ref(struct loc_ctx* ctx);
struct loc_ctx *loc_unref(struct loc_ctx* ctx);
int loc_new(struct loc_ctx** ctx);
void loc_set_log_fn(struct loc_ctx* ctx,
void (*log_fn)(struct loc_ctx* ctx,
int priority, const char* file, int line, const char* fn,
const char* format, va_list args));
int loc_get_log_priority(struct loc_ctx* ctx);
void loc_set_log_priority(struct loc_ctx* ctx, int priority);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif
/*
libloc - A library to determine the location of someone on the Internet
Copyright (C) 2017 IPFire Development Team <info@ipfire.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <errno.h>
#include <unistd.h>
#include <loc/libloc.h>
int main(int argc, char** argv) {
struct loc_ctx *ctx;
int err = loc_new(&ctx);
if (err < 0)
exit(EXIT_FAILURE);
printf("version %s\n", VERSION);
loc_unref(ctx);
return EXIT_SUCCESS;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment