aboutsummaryrefslogtreecommitdiff
path: root/include/smap
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-06-07 01:07:00 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2010-06-07 01:07:00 +0300
commit769386224bd9df0ae8772b20d4d3f8fd743ff4f5 (patch)
treef95b67811f7b947c5a5f3f87ca6283998965bf5f /include/smap
parent24dd694b5ad3dad1e8690eae895d11d3e826dbb1 (diff)
downloadsmap-769386224bd9df0ae8772b20d4d3f8fd743ff4f5.tar.gz
smap-769386224bd9df0ae8772b20d4d3f8fd743ff4f5.tar.bz2
Implement loadable modules. Add `echo' module.
* include/Makefile.am: New file. * include/smap/Makefile.am: New file. * include/smap/module.h: New file. * lib/Makefile.am: New file. * src/module.c: New file. * src/query.c: New file. * include/smap: New directory. * src/kwtab.h: Move to include/smap. * src/diag.h: Likewise. * src/ostr.h: Likewise. * src/wordsplit.h: Likewise. * lib: New directory. * src/kwtab.c: Move to lib * src/ostr.c: Likewise. * src/wordsplit.c: Likewise. * lib/diag.c: New file. * Makefile.am (SUBDIRS): Add include and lib * configure.ac: Update. * src/Makefile.am: Move installable headers to include/smap, libraries to lib. (smap_SOURCES): Add module.c, url.c, query.c. (AM_CPPFLAGS): Define SMAP_MODDIR. * src/log.c (smap_error_str, smap_debug_str) (smap_trace_str): Move to lib/diag.c (smap_verror, smap_error): Likewise. * src/smap.c (smap_kwtab): Add new keywords. (main): Initialize module subsystem. * src/smap.h: Update. * modules/Makefile.am: New file. * modules/echo/Makefile.am: New file. * modules/echo/echo.c: New file.
Diffstat (limited to 'include/smap')
-rw-r--r--include/smap/Makefile.am18
-rw-r--r--include/smap/diag.h29
-rw-r--r--include/smap/kwtab.h30
-rw-r--r--include/smap/module.h45
-rw-r--r--include/smap/ostr.h34
-rw-r--r--include/smap/wordsplit.h96
6 files changed, 252 insertions, 0 deletions
diff --git a/include/smap/Makefile.am b/include/smap/Makefile.am
new file mode 100644
index 0000000..9b7a2bb
--- /dev/null
+++ b/include/smap/Makefile.am
@@ -0,0 +1,18 @@
+# This file is part of SMAP.
+# Copyright (C) 2010 Sergey Poznyakoff
+#
+# 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 3, 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.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+pkginclude_HEADERS = ostr.h wordsplit.h kwtab.h module.h diag.h
+
diff --git a/include/smap/diag.h b/include/smap/diag.h
new file mode 100644
index 0000000..d5378d5
--- /dev/null
+++ b/include/smap/diag.h
@@ -0,0 +1,29 @@
+/* This file is part of smap.
+ Copyright (C) 2006, 2007, 2010 Sergey Poznyakoff
+
+ 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 3, 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef __SMAP_DIAG_H
+#define __SMAP_DIAG_H
+
+#include "smap/ostr.h"
+
+extern smap_ostream_t smap_error_str;
+extern smap_ostream_t smap_debug_str;
+extern smap_ostream_t smap_trace_str;
+
+void smap_verror(const char *fmt, va_list ap);
+void smap_error(const char *fmt, ...);
+
+#endif
diff --git a/include/smap/kwtab.h b/include/smap/kwtab.h
new file mode 100644
index 0000000..8fde142
--- /dev/null
+++ b/include/smap/kwtab.h
@@ -0,0 +1,30 @@
+/* This file is part of smf.
+ Copyright (C) 2006, 2007, 2010 Sergey Poznyakoff
+
+ 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 3, 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef __SMAP_KWTAB_H
+#define __SMAP_KWTAB_H
+
+struct smap_kwtab {
+ char *name;
+ int tok;
+};
+
+int smap_kwtab_nametotok_len(struct smap_kwtab *kwtab, const char *str,
+ size_t len, int *pres);
+int smap_kwtab_nametotok(struct smap_kwtab *kwtab, const char *str, int *pres);
+int smap_kwtab_toktoname(struct smap_kwtab *kwtab, int tok, const char **pres);
+
+#endif
diff --git a/include/smap/module.h b/include/smap/module.h
new file mode 100644
index 0000000..550761b
--- /dev/null
+++ b/include/smap/module.h
@@ -0,0 +1,45 @@
+/* This file is part of smap.
+ Copyright (C) 2010 Sergey Poznyakoff
+
+ 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 3, 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef __SMAP_MODULE_H
+#define __SMAP_MODULE_H
+
+#define __smap_s_cat3__(a,b,c) a ## b ## c
+#define SMAP_EXPORT(module,name) __smap_s_cat3__(module,_LTX_,name)
+
+#define SMAP_MODULE_VERSION 1
+#define SMAP_CAPA_NONE 0
+#define SMAP_CAPA_DEFAULT SMAP_CAPA_NONE
+
+typedef struct smap_database *smap_database_t;
+
+struct sockaddr;
+
+struct smap_module {
+ unsigned smap_version;
+ unsigned smap_capabilities; /* Unused so far */
+ int (*smap_init)(int argc, char **argv);
+ smap_database_t (*smap_init_db)(int argc, char **argv);
+ int (*smap_free_db)(smap_database_t dbp);
+ int (*smap_query)(smap_database_t dbp,
+ smap_ostream_t ostr,
+ const char *map, const char *key,
+ struct sockaddr const *fsa, int fsalen,
+ struct sockaddr const *tsa, int tsalen);
+};
+
+#endif
+
diff --git a/include/smap/ostr.h b/include/smap/ostr.h
new file mode 100644
index 0000000..fbac3c3
--- /dev/null
+++ b/include/smap/ostr.h
@@ -0,0 +1,34 @@
+/* This file is part of smf.
+ Copyright (C) 2006, 2007, 2010 Sergey Poznyakoff
+
+ 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 3, 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.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef __SMAP_OSTR_H
+#define __SMAP_OSTR_H
+
+/* ostr.c */
+#include <unistd.h>
+#include <stdarg.h>
+
+typedef struct smap_output_stream *smap_ostream_t;
+int smap_ostream_write(smap_ostream_t str, char *buf, size_t len);
+int smap_ostream_vprintf(smap_ostream_t str, const char *fmt, va_list ap);
+int smap_ostream_printf(smap_ostream_t str, const char *fmt, ...);
+int smap_ostream_flush(smap_ostream_t str);
+smap_ostream_t smap_ostream_create(void (*flush)(void *data, char *buf),
+ void *data);
+void smap_ostream_free(smap_ostream_t str);
+void smap_ostream_destroy(smap_ostream_t *str);
+
+#endif
diff --git a/include/smap/wordsplit.h b/include/smap/wordsplit.h
new file mode 100644
index 0000000..4aa5e67
--- /dev/null
+++ b/include/smap/wordsplit.h
@@ -0,0 +1,96 @@
+/* wordsplit - a word splitter
+ Copyright (C) 2009, 2010 Sergey Poznyakoff
+
+ 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 3 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.
+
+ You should have received a copy of the GNU General Public License along
+ with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef __SMAP_WORDSPLIT_H
+#define __SMAP_WORDSPLIT_H
+
+struct wordsplit
+{
+ size_t ws_wordc;
+ char **ws_wordv;
+ size_t ws_offs;
+ size_t ws_wordn;
+ int ws_flags;
+ const char *ws_delim;
+ const char *ws_comment;
+ void (*ws_alloc_die)(struct wordsplit *wsp);
+ void (*ws_error)(const char *, ...);
+
+ const char *ws_input;
+ size_t ws_len;
+ size_t ws_endp;
+};
+
+/* Append the words found to the array resulting from a previous
+ call. */
+#define WRDSF_APPEND 0x00001
+/* Insert we_offs initial NULLs in the array ws_wordv.
+ (These are not counted in the returned ws_wordc.) */
+#define WRDSF_DOOFFS 0x00002
+/* Don't do command substitution. Reserved for future use. */
+#define WRDSF_NOCMD 0x00004
+/* The parameter p resulted from a previous call to
+ wordsplit(), and wordsplit_free() was not called. Reuse the
+ allocated storage. */
+#define WRDSF_REUSE 0x00008
+/* Print errors */
+#define WRDSF_SHOWERR 0x00010
+/* Consider it an error if an undefined shell variable
+ is expanded. */
+#define WRDSF_UNDEF 0x00020
+
+/* Don't do variable expansion. Reserved for future use. */
+#define WRDSF_NOVAR 0x00040
+/* Abort on ENOMEM error */
+#define WRDSF_ENOMEMABRT 0x00080
+/* Treat whitespace as delimiters */
+#define WRDSF_WS 0x00100
+/* Handle quotes and escape directives */
+#define WRDSF_QUOTE 0x00200
+/* Replace each input sequence of repeated delimiters with a single
+ delimiter */
+#define WRDSF_SQUEEZE_DELIMS 0x00400
+/* Return delimiters */
+#define WRDSF_RETURN_DELIMS 0x00800
+/* Treat sed expressions as words */
+#define WRDSF_SED_EXPR 0x01000
+/* ws_delim field is initialized */
+#define WRDSF_DELIM 0x02000
+/* ws_comment field is initialized */
+#define WRDSF_COMMENT 0x04000
+/* ws_alloc_die field is initialized */
+#define WRDSF_ALLOC_DIE 0x08000
+/* ws_error field is initialized */
+#define WRDSF_ERROR 0x10000
+
+#define WRDSF_DEFFLAGS \
+ (WRDSF_NOVAR | WRDSF_NOCMD | \
+ WRDSF_WS | WRDSF_QUOTE | WRDSF_SQUEEZE_DELIMS)
+
+#define WRDSE_EOF 0
+#define WRDSE_QUOTE 1
+#define WRDSE_NOSPACE 2
+
+int wordsplit(const char *s, struct wordsplit *p, int flags);
+void wordsplit_free(struct wordsplit *p);
+
+int wordsplit_unquote_char(int c);
+int wordsplit_quote_char(int c);
+size_t wordsplit_quoted_length(const char *str, int quote_hex, int *quote);
+void wordsplit_unquote_copy(char *dst, const char *src, size_t n);
+void wordsplit_quote_copy(char *dst, const char *src, int quote_hex);
+
+#endif

Return to:

Send suggestions and report system problems to the System administrator.