fec625 | 1998-03-25 | Fredrik Hübinette (Hubbe) | | #include "global.h"
|
780686 | 1997-02-13 | Per Hedbor | | #include "config.h"
#if defined(HAVE_RPCSVC_YPCLNT_H) && defined(HAVE_RPCSVC_YP_PROT_H)
|
497b2a | 1997-03-03 | Henrik Grubbström (Grubba) | | #ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
|
6e6fba | 1997-03-04 | Henrik Grubbström (Grubba) | | #ifdef HAVE_RPC_TYPES_H
#include <rpc/types.h>
#endif /* HAVE_RPC_TYPES_H */
#ifdef HAVE_RPC_RPC_H
#include <rpc/rpc.h>
#endif /* HAVE_RPC_RPC_H */
#ifdef HAVE_RPC_CLNT_H
#include <rpc/clnt.h>
#endif /* HAVE_RPC_CLNT_H */
|
780686 | 1997-02-13 | Per Hedbor | | #include <rpcsvc/yp_prot.h>
|
abfe51 | 1998-08-08 | Henrik Grubbström (Grubba) | | #include <rpcsvc/ypclnt.h>
|
780686 | 1997-02-13 | Per Hedbor | |
#include "stralloc.h"
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | #include "pike_error.h"
|
bb55f8 | 1997-03-16 | Fredrik Hübinette (Hubbe) | | #include "pike_macros.h"
|
780686 | 1997-02-13 | Per Hedbor | | #include "object.h"
#include "constants.h"
#include "interpret.h"
#include "svalue.h"
#include "mapping.h"
#include "builtin_functions.h"
|
9c6f7d | 1997-04-15 | Fredrik Hübinette (Hubbe) | | #include "module_support.h"
|
780686 | 1997-02-13 | Per Hedbor | |
|
6dc277 | 2000-07-28 | Fredrik Hübinette (Hubbe) | |
#include "module_magic.h"
|
d579c8 | 2001-12-08 | Martin Nilsson | | RCSID("$Id: yp.c,v 1.23 2001/12/08 01:52:34 nilsson Exp $");
|
24ddc7 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
350336 | 2000-08-17 | Henrik Grubbström (Grubba) | | #ifdef HAVE_YPERR_STRING
|
b2d3e4 | 2000-12-01 | Fredrik Hübinette (Hubbe) | | #define YPERROR(fun,err) do{ if(err) Pike_error("yp->%s(): %s\n", (fun), \
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | | yperr_string(err)); }while(0)
|
350336 | 2000-08-17 | Henrik Grubbström (Grubba) | | #else /* !HAVE_YPERR_STRING */
|
a4a172 | 2000-12-05 | Per Hedbor | | #define YPERROR(fun,err) do{ if(err) Pike_error("yp->%s(): YP error %d.\n", (fun), \
|
350336 | 2000-08-17 | Henrik Grubbström (Grubba) | | (err)); }while(0)
#endif /* HAVE_YPERR_STRING */
|
780686 | 1997-02-13 | Per Hedbor | |
struct my_yp_domain
{
char *domain;
int last_size;
};
#define this ((struct my_yp_domain *)fp->current_storage)
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | static void f_default_yp_domain(INT32 args)
{
int err;
char *ret;
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | err = yp_get_default_domain(&ret);
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
YPERROR( "default_yp_domain", err );
pop_n_elems( args );
|
780686 | 1997-02-13 | Per Hedbor | | push_text( ret );
}
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | static void f_server(INT32 args)
{
int err;
char *ret;
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | err = yp_master(this->domain, sp[-1].u.string->str, &ret);
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | YPERROR( "server", err );
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
pop_n_elems( args );
|
780686 | 1997-02-13 | Per Hedbor | | push_text( ret );
}
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | | |
d579c8 | 2001-12-08 | Martin Nilsson | | *! @decl void bind(string domain)
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | | *!
*! If @[domain] is not specified , the default domain will be used.
*! (As returned by @[Yp.default_yp_domain()]).
*!
*! If there is no YP server available for the domain, this
*! function call will block until there is one. If no server appears
*! in about ten minutes or so, an error will be returned. This timeout
*! is not configurable.
*!
*! @seealso
*! @[Yp.default_yp_domain()]
*/
|
780686 | 1997-02-13 | Per Hedbor | | static void f_create(INT32 args)
{
int err;
if(!args)
{
f_default_yp_domain(0);
args = 1;
}
|
3c04e8 | 1997-03-13 | Fredrik Hübinette (Hubbe) | | check_all_args("yp->create", args, BIT_STRING,0);
|
780686 | 1997-02-13 | Per Hedbor | |
if(this->domain)
{
yp_unbind( this->domain );
free(this->domain);
}
this->domain = strdup( sp[-args].u.string->str );
err = yp_bind( this->domain );
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | YPERROR("create", err);
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
pop_n_elems(args);
|
780686 | 1997-02-13 | Per Hedbor | | }
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | static void f_all(INT32 args)
{
int err, num=0;
char *retval, *retkey;
int retlen, retkeylen;
char *map;
struct mapping *res_map;
|
3c04e8 | 1997-03-13 | Fredrik Hübinette (Hubbe) | | check_all_args("yp->all", args, BIT_STRING, 0);
|
780686 | 1997-02-13 | Per Hedbor | |
map = sp[-1].u.string->str;
res_map = allocate_mapping( (this->last_size?this->last_size+2:40) );
if(!(err = yp_first(this->domain, map, &retkey,&retkeylen, &retval,&retlen)))
do {
push_string(make_shared_binary_string(retkey, retkeylen));
push_string(make_shared_binary_string(retval, retlen));
mapping_insert( res_map, sp-2, sp-1 );
pop_stack(); pop_stack();
err = yp_next(this->domain, map, retkey, retkeylen,
&retkey, &retkeylen, &retval, &retlen);
num++;
} while(!err);
if(err != YPERR_NOMORE)
{
free_mapping( res_map );
YPERROR( "all", err );
}
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | this->last_size = num;
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | | pop_n_elems(args);
|
780686 | 1997-02-13 | Per Hedbor | | push_mapping( res_map );
}
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | |
|
ed01d5 | 1999-08-02 | Fredrik Hübinette (Hubbe) | | static void f_map(INT32 args)
|
780686 | 1997-02-13 | Per Hedbor | | {
int err;
char *retval, *retkey;
int retlen, retkeylen;
char *map;
struct svalue *f = &sp[-1];
|
3c04e8 | 1997-03-13 | Fredrik Hübinette (Hubbe) | | check_all_args("map", args, BIT_STRING, BIT_FUNCTION|BIT_ARRAY, 0 );
|
780686 | 1997-02-13 | Per Hedbor | |
map = sp[-2].u.string->str;
if(!(err = yp_first(this->domain,map, &retkey,&retkeylen, &retval, &retlen)))
do {
push_string(make_shared_binary_string(retkey, retkeylen));
push_string(make_shared_binary_string(retval, retlen));
apply_svalue( f, 2 );
err = yp_next(this->domain, map, retkey, retkeylen,
&retkey, &retkeylen, &retval, &retlen);
} while(!err);
if(err != YPERR_NOMORE)
YPERROR( "all", err );
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
pop_n_elems(args);
|
780686 | 1997-02-13 | Per Hedbor | | }
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | static void f_order(INT32 args)
{
int err;
|
abfe51 | 1998-08-08 | Henrik Grubbström (Grubba) | | YP_ORDER_TYPE ret;
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
3c04e8 | 1997-03-13 | Fredrik Hübinette (Hubbe) | | check_all_args("yp->order", args, BIT_STRING, 0);
|
780686 | 1997-02-13 | Per Hedbor | |
err = yp_order( this->domain, sp[-args].u.string->str, &ret);
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | YPERROR("order", err );
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | pop_n_elems( args );
push_int( (INT32) ret );
}
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | | static void f_match(INT32 args)
{
int err;
char *retval;
int retlen;
|
3c04e8 | 1997-03-13 | Fredrik Hübinette (Hubbe) | | check_all_args("yp->match", args, BIT_STRING, BIT_STRING, 0);
|
780686 | 1997-02-13 | Per Hedbor | |
err = yp_match( this->domain, sp[-args].u.string->str,
sp[-args+1].u.string->str, sp[-args+1].u.string->len,
&retval, &retlen );
if(err == YPERR_KEY)
{
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | | pop_n_elems( args );
|
780686 | 1997-02-13 | Per Hedbor | | push_int(0);
sp[-1].subtype = NUMBER_UNDEFINED;
return;
}
YPERROR( "match", err );
|
12887f | 1998-05-23 | Henrik Grubbström (Grubba) | |
pop_n_elems( args );
|
780686 | 1997-02-13 | Per Hedbor | | push_string(make_shared_binary_string( retval, retlen ));
}
static void init_yp_struct( struct object *o )
{
this->domain = 0;
this->last_size = 0;
}
static void exit_yp_struct( struct object *o )
{
if(this->domain)
{
yp_unbind( this->domain );
free(this->domain);
}
}
|
6e1652 | 2001-01-05 | Henrik Grubbström (Grubba) | |
|
780686 | 1997-02-13 | Per Hedbor | |
void pike_module_init(void)
{
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_EFUN("default_yp_domain", f_default_yp_domain,tFunc(tVoid,tStr),
|
780686 | 1997-02-13 | Per Hedbor | | OPT_EXTERNAL_DEPEND);
start_new_program();
|
90e978 | 1999-01-31 | Fredrik Hübinette (Hubbe) | | ADD_STORAGE(struct my_yp_domain);
|
780686 | 1997-02-13 | Per Hedbor | |
set_init_callback( init_yp_struct );
set_exit_callback( exit_yp_struct );
|
45ee5d | 1999-02-10 | Fredrik Hübinette (Hubbe) | |
ADD_FUNCTION("create", f_create,tFunc(tOr(tStr,tVoid),tVoid), 0);
ADD_FUNCTION("bind", f_create,tFunc(tStr,tVoid), 0);
ADD_FUNCTION("match", f_match,tFunc(tStr tStr,tStr), 0);
ADD_FUNCTION("server", f_server,tFunc(tStr,tStr), 0);
ADD_FUNCTION("all", f_all,tFunc(tStr,tMap(tStr,tStr)), 0);
ADD_FUNCTION("map", f_map,tFunc(tStr tOr(tFunction,tArr(tFunction)),tVoid), 0);
ADD_FUNCTION("order", f_order,tFunc(tStr,tInt), 0);
|
780686 | 1997-02-13 | Per Hedbor | |
|
61e9a0 | 1998-01-25 | Fredrik Hübinette (Hubbe) | | end_class("Domain", 0);
|
780686 | 1997-02-13 | Per Hedbor | | }
void pike_module_exit(void)
{
|
61e9a0 | 1998-01-25 | Fredrik Hübinette (Hubbe) | |
|
780686 | 1997-02-13 | Per Hedbor | | }
#else
|
6dc277 | 2000-07-28 | Fredrik Hübinette (Hubbe) | | #include "module_magic.h"
|
780686 | 1997-02-13 | Per Hedbor | | void pike_module_init(void) {}
void pike_module_exit(void) {}
#endif
|