00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef _IPA_IPA_H_
00016 #define _IPA_IPA_H_
00017
00135 #ifdef HAVE_CONFIG_H
00136 # include "config.h"
00137 #endif
00138
00139 #include <stdio.h>
00140
00141 #if STDC_HEADERS
00142 # include <stdlib.h>
00143 # include <stddef.h>
00144 #else
00145 # if HAVE_STDLIB_H
00146 # include <stdlib.h>
00147 # endif
00148 # if HAVE_MALLOC_H
00149 # include <malloc.h>
00150 # endif
00151 #endif
00152
00153 #if HAVE_INTTYPES_H
00154 # include <inttypes.h>
00155 #else
00156 # if HAVE_STDINT_H
00157 # include <stdint.h>
00158 # endif
00159 #endif
00160 #if HAVE_UNISTD_H
00161 # include <unistd.h>
00162 #endif
00163
00164 #if HAVE_LIMITS_H
00165 # include <limits.h>
00166 #endif
00167
00168 #if HAVE_STRING_H
00169 # if !STDC_HEADERS && HAVE_MEMORY_H
00170 # include <memory.h>
00171 # endif
00172 # include <string.h>
00173 #endif
00174 #if HAVE_STRINGS_H
00175 # include <strings.h>
00176 #endif
00177
00178 #if HAVE_STDARG_H
00179 # include <stdarg.h>
00180 #endif
00181
00182
00183 #if HAVE_ERRNO_H
00184 # include <errno.h>
00185 #endif
00186
00187 #if HAVE_ARPA_INET_H
00188 # include <arpa/inet.h>
00189 #endif
00190
00191
00192 #if !defined (PRIu32)
00193
00194 # define PRId32 "d"
00195 # define PRIi32 "i"
00196 # define PRIo32 "o"
00197 # define PRIu32 "u"
00198 # define PRIx32 "x"
00199 # define PRIX32 "X"
00200
00201 # define PRId16 PRId32
00202 # define PRIi16 PRIi32
00203 # define PRIo16 PRIo32
00204 # define PRIu16 PRIu32
00205 # define PRIx16 PRIx32
00206 # define PRIX16 PRIX32
00207
00208 # define PRId8 PRId32
00209 # define PRIi8 PRIi32
00210 # define PRIo8 PRIo32
00211 # define PRIu8 PRIu32
00212 # define PRIx8 PRIx32
00213 # define PRIX8 PRIX32
00214 #endif
00215 #if !defined (PRIu64)
00216 # if (SIZEOF_LONG >= 8)
00217 # define PRId64 "l" PRId32
00218 # define PRIi64 "l" PRIi32
00219 # define PRIo64 "l" PRIo32
00220 # define PRIu64 "l" PRIu32
00221 # define PRIx64 "l" PRIx32
00222 # define PRIX64 "l" PRIX32
00223 # else
00224 # define PRId64 "ll" PRId32
00225 # define PRIi64 "ll" PRIi32
00226 # define PRIo64 "ll" PRIo32
00227 # define PRIu64 "ll" PRIu32
00228 # define PRIx64 "ll" PRIx32
00229 # define PRIX64 "ll" PRIX32
00230 # endif
00231 #endif
00232
00233 #include <glib.h>
00234 #if GLIB_CHECK_VERSION(2, 6, 0)
00235 # include <glib/gstdio.h>
00236 #else
00237 # define g_debug(...) g_log(G_LOG_DOMAIN, \
00238 G_LOG_LEVEL_DEBUG, \
00239 __VA_ARGS__)
00240 #endif
00241 #include <airdbc/airdbc.h>
00242
00291 #define ENV_IPA_DB_URI "IPA_DB_URI"
00292
00293 #define IPA_CHECK_ERR( e, m, n ) \
00294 if (e != NULL) { \
00295 g_critical("%s: %s", m, (e && e->message) ? e->message : "" ); \
00296 g_clear_error(&e); \
00297 return n; \
00298 }
00299
00301 typedef enum _IPAStatus {
00302 IPA_OK = 0,
00303 IPA_ERR_NOTFOUND,
00304 IPA_ERR_FILEIO,
00305 IPA_ERR_SQL,
00306 IPA_ERR_INVALID,
00307 IPA_ERR_UNKNOWN
00308 } IPAStatus;
00309
00311 typedef enum _IPACatalogType
00312 {
00313 IPA_CAT_NONE = 0,
00314 IPA_CAT_SET,
00315 IPA_CAT_BAG,
00316 IPA_CAT_PMAP,
00317 IPA_CAT_MMAP
00318 } IPACatalogType;
00319
00320
00321 typedef enum _IPAContextState
00322 {
00323 IPA_STATE_INITIAL = 0,
00324 IPA_STATE_EXPORT,
00325 IPA_STATE_IMPORT,
00326 IPA_STATE_QUERY,
00327 IPA_STATE_QUERY_DONE
00328 } IPAContextState;
00329
00333 typedef struct _IPAContext {
00334 IPAContextState state;
00335 char *db_uri;
00336 uint64_t ds_id;
00337 AdbConnection *conn;
00338 AdbStatement *stmt;
00339 AdbResultSet *rs;
00340 GString *sql;
00341 IPACatalogType cat_type;
00342 uint8_t cat_width;
00343 uint8_t range_width;
00344 uint8_t label_width;
00345 uint8_t value_width;
00346 gboolean verbose;
00347 } IPAContext;
00348
00349 #define IPA_ADDR_LEN 16
00350 #define IPA_RANGE_LEN ((2 * IPA_ADDR_LEN) + 4)
00351 #define IPA_LABEL_LEN 1024
00352 #define IPA_VALUE_LEN 32
00353 #define IPA_CAT_LEN 64
00354
00360 typedef struct _IPAAssoc {
00361 char range[IPA_RANGE_LEN];
00362 uint32_t begin;
00363 uint32_t end;
00364 char label[IPA_LABEL_LEN];
00365 char value[IPA_VALUE_LEN];
00366 char catalog[IPA_CAT_LEN];
00367 char t1[IPA_VALUE_LEN];
00368 char t2[IPA_VALUE_LEN];
00369 } IPAAssoc;
00370
00371 typedef struct _IPAColumn {
00372 char *label;
00373 int width;
00374 gboolean align_left;
00375 char *val;
00376 } IPAColumn;
00377
00388 int ipa_create_context(
00389 IPAContext **ipa,
00390 char *db_uri);
00391
00398 void ipa_destroy_context(
00399 IPAContext **ipa);
00400
00401
00407 void ipa_begin(
00408 IPAContext *ipa);
00409
00415 void ipa_commit(
00416 IPAContext *ipa);
00417
00423 void ipa_rollback(
00424 IPAContext *ipa);
00425
00437 int ipa_add_dataset(
00438 IPAContext *ipa,
00439 const char *catname,
00440 const char *catdesc,
00441 IPACatalogType type,
00442 const char *begin,
00443 const char *end);
00444
00458 int ipa_add_assoc(
00459 IPAContext *ipa,
00460 uint32_t addr1,
00461 uint32_t addr2,
00462 char *label,
00463 uint64_t value);
00464
00475 int ipa_add_cidr(
00476 IPAContext *ipa,
00477 uint32_t addr,
00478 uint32_t prefix,
00479 char *label,
00480 uint64_t value);
00481
00482
00492 int ipa_get_dataset(
00493 IPAContext *ipa,
00494 const char *catalog_name,
00495 const char *dataset_time);
00496
00504 int ipa_get_assoc(
00505 IPAContext *ipa,
00506 IPAAssoc *assoc);
00507
00512 typedef enum _IPAOrderBy {
00513 IPA_ORDER_DEFAULT = 0,
00514 IPA_ORDER_CTIME,
00515 IPA_ORDER_MTIME
00516 } IPAOrderBy;
00517
00518 uint32_t ipa_mask_from_prefix(
00519 uint32_t pfx);
00520
00525 #endif
00526
00527