sdb man page on DragonFly

Man page or keyword search:  
man Server   44335 pages
apropos Keyword Search (all sections)
Output format
DragonFly logo
[printable version]

SDB(3)									SDB(3)

NAME
       sdb_init, sdb_open, sdb_query, sdb_close - the Simple Database Library.

SYNOPSIS
       #include <sdb.h>

       void sdb_init();
       char *sdb_open(char *url);
       void sdb_close(char *id);
       int  sdb_query(char  *url,  char	 *query, int (*callback)(int, char **,
       void *), void *closure);

DESCRIPTION
       The SDB library allows applications to support multiple	database  man‐
       agement	systems with negligeable overhead, in terms of code as well as
       system resources.

       sdb_init() initializes the library and registers the database  drivers.
       It  is not necessary to call sdb_init explicitly, since it will be done
       automatically when needed.

       sdb_open() opens a database connection that can be  used	 for  multiple
       queries.	 This is optional; calling sdb_query directly will simply open
       and close the connection for each query. sdb_open returns a  connection
       id which is used in place of the url in calls to sdb_query.

       sdb_query() calls the callback once for each row returned. No rows does
       not indicate an error condition. sdb_query returns the number  of  rows
       or  -1 for error.  The callback takes three arguments, an integer indi‐
       cating the number of columns in the result, an array of pointers to the
       fields  and  a  pointer	to some arbitrary data that the callback might
       need. Values are always returned as strings.

       sdb_close() closes the database connection opened by sdb_open.

EXAMPLES
       This minimal program runs queries from the command line.

       #include <stdio.h>
       #include <stdlib.h>
       #include <sdb.h>

       static int callback(int n, char **p, void *closure)
       {
	   int i;
	   for (i = 0; i < n; i++) {
	       printf("%s\t", p[i]);
	   }
	   printf("0);
	   return 0;
       }

       int main(int argc, char **argv)
       {
	   if (argc != 3) {
	       fprintf(stderr, "Usage: sdb_demo url query\n");
	       return EXIT_FAILURE;
	   }
	   sdb_query(argv[1], argv[2], callback, NULL);
	   return EXIT_SUCCESS;
       }

       This program can be used to authenticate Squid proxy users.

       #include <stdio.h>
       #include <stdlib.h>
       #include <unistd.h>
       #include <string.h>
       #include <sdb.h>

       static int cb_db(int n, char **p, void *closure)
       {
	   return 0;
       }

       int main(int argc, char **argv)
       {
	   char *url, query[1024];
	   int n;
	   char buf[256];
	   char *user, *passwd, *p;
	   setbuf(stdout, NULL);
	   if (argc != 2) {
	       fprintf(stderr, "Usage: sdb_auth url\n");
	       exit(1);
	   }
	   url = argv[1];
	   while (fgets(buf, 256, stdin) != NULL) {
	       if ((p = strchr(buf, '\n')) != NULL)
		   *p = '\0';	       /* strip \n */
	       if ((user = strtok(buf, " ")) == NULL) {
		   printf("ERR\n");
		   continue;
	       }
	       if ((passwd = strtok(NULL, "")) == NULL) {
		   printf("ERR\n");
		   continue;
	       }
	       sprintf(query,
		       "select * from htpasswd "
		       "where user = '%s' "
		       "and passwd = '%s'",
		       user, passwd);
	       n = sdb_query(url, query, cb_db, NULL);
	       if (n < 1) {
		   printf("ERR\n");
	       } else {
		   printf("OK\n");
	       }
	   }
	   exit(0);
       }

SEE ALSO
       sdbd.8

       Example clients in sdb_client.c and sdbd_client.c.

AUTHOR
       Copyright (c) 2000-2005	Ulric Eriksson <ulric@siag.nu>

       This library is free software; you can redistribute it and/or modify it
       under  the terms of the GNU Library General Public License as published
       by the Free Software Foundation; either version 2 of  the  Licence,  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  MER‐
       CHANTABILITY  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
       General Public License for more details.

       You should have received a copy	of  the	 GNU  Library  General	Public
       License	along  with  this  library; if not, write to the Free Software
       Foundation, Inc., 59 Temple Place - Suite 330, Boston,  MA  02111-1307,
       USA.

				     LOCAL				SDB(3)
[top]

List of man pages available for DragonFly

Copyright (c) for man pages and the logo by the respective OS vendor.

For those who want to learn more, the polarhome community provides shell access and support.

[legal] [privacy] [GNU] [policy] [cookies] [netiquette] [sponsors] [FAQ]
Tweet
Polarhome, production since 1999.
Member of Polarhome portal.
Based on Fawad Halim's script.
....................................................................
Vote for polarhome
Free Shell Accounts :: the biggest list on the net