178 lines
5.7 KiB
C
178 lines
5.7 KiB
C
#include "scheme48.h"
|
|
#include <sys/types.h>
|
|
#include <rpc/rpc.h>
|
|
#include <rpcsvc/ypclnt.h>
|
|
#include <rpcsvc/yp_prot.h>
|
|
|
|
#define DECLARE_S48VALUE_STATIC(NAME) \
|
|
static s48_value NAME = S48_FALSE;
|
|
|
|
#define GC_PROTECT_ENTER_INT(CNAME, SNAME, VALUE) \
|
|
S48_GC_PROTECT_GLOBAL(CNAME); \
|
|
CNAME = s48_enter_integer(VALUE); \
|
|
s48_define_exported_binding(SNAME, CNAME);
|
|
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_badargs);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_baddb);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_domain);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_key);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_map);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_nodom);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_nomore);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_pmap);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_resrc);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_rpc);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_vers);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_ypbind);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_yperr);
|
|
DECLARE_S48VALUE_STATIC(scsh_yp_error_ypserv);
|
|
|
|
s48_value scsh_yp_getdefaultdomain(void)
|
|
{
|
|
char *buf;
|
|
int i;
|
|
s48_value str, res = S48_FALSE;
|
|
S48_DECLARE_GC_PROTECT(2);
|
|
|
|
S48_GC_PROTECT_2(res, str);
|
|
i = yp_get_default_domain(&buf);
|
|
str = (i == 0) ? s48_enter_string(buf) : S48_UNSPECIFIC;
|
|
res = s48_list_2(s48_enter_integer(i), str);
|
|
S48_GC_UNPROTECT();
|
|
return res;
|
|
}
|
|
|
|
s48_value scsh_yp_bind(s48_value domain)
|
|
{
|
|
return s48_enter_integer(yp_bind(s48_extract_string(domain)));
|
|
}
|
|
|
|
s48_value scsh_yp_unbind(s48_value domain)
|
|
{
|
|
yp_unbind(s48_extract_string(domain));
|
|
return S48_UNSPECIFIC;
|
|
}
|
|
|
|
s48_value scsh_yp_errstring(s48_value code)
|
|
{
|
|
return s48_enter_string(yperr_string(s48_extract_integer(code)));
|
|
}
|
|
|
|
s48_value scsh_yp_proterr(s48_value code)
|
|
{
|
|
return s48_enter_integer(ypprot_err(s48_extract_integer(code)));
|
|
}
|
|
|
|
s48_value scsh_yp_match(s48_value indomain, s48_value inmap,
|
|
s48_value inkey)
|
|
{
|
|
int r, l;
|
|
char *outval;
|
|
s48_value str, res = S48_FALSE;
|
|
S48_DECLARE_GC_PROTECT(5);
|
|
|
|
S48_GC_PROTECT_5(indomain, inmap, inkey, res, str);
|
|
r = yp_match(s48_extract_string(indomain), s48_extract_string(inmap),
|
|
s48_extract_string(inkey), S48_STRING_LENGTH(inkey),
|
|
&outval, &l);
|
|
str = (r == 0) ? s48_enter_string(outval) : S48_UNSPECIFIC;
|
|
res = s48_list_2 (s48_enter_integer(r), str);
|
|
S48_GC_UNPROTECT();
|
|
return res;
|
|
}
|
|
|
|
s48_value scsh_yp_order(s48_value domain, s48_value map)
|
|
{
|
|
int r, outorder;
|
|
s48_value res, i;
|
|
S48_DECLARE_GC_PROTECT(2);
|
|
|
|
S48_GC_PROTECT_2(domain, map);
|
|
r = yp_order(s48_extract_string(domain), s48_extract_string(map),
|
|
(int *) &outorder);
|
|
i = (r == 0) ? s48_enter_integer(outorder) : S48_UNSPECIFIC;
|
|
res = s48_list_2(s48_enter_integer(r), i);
|
|
S48_GC_UNPROTECT();
|
|
return res;
|
|
}
|
|
|
|
s48_value scsh_yp_master(s48_value domain, s48_value map)
|
|
{
|
|
int r;
|
|
char *outname;
|
|
s48_value res, str;
|
|
S48_DECLARE_GC_PROTECT(4);
|
|
|
|
S48_GC_PROTECT_4(domain, map, res, str);
|
|
r = yp_master(s48_extract_string(domain), s48_extract_string(map),
|
|
&outname);
|
|
str = (r == 0) ? s48_enter_string(outname) : S48_UNSPECIFIC;
|
|
res = s48_list_2(s48_enter_integer(r), str);
|
|
S48_GC_UNPROTECT();
|
|
return res;
|
|
}
|
|
|
|
s48_value scsh_yp_first(s48_value domain, s48_value map)
|
|
{
|
|
char *key, *val;
|
|
int keylen, vallen, r;
|
|
s48_value res, str1, str2;
|
|
S48_DECLARE_GC_PROTECT(5);
|
|
|
|
S48_GC_PROTECT_5(domain, map, res, str1, str2);
|
|
r = yp_first(s48_extract_string(domain), s48_extract_string(map),
|
|
&key, &keylen, &val, &vallen);
|
|
str1 = (r == 0) ? s48_enter_string(key) : S48_UNSPECIFIC;
|
|
str2 = (r == 0) ? s48_enter_string(val) : S48_UNSPECIFIC;
|
|
res = s48_list_3(s48_enter_integer(r), str1, str2);
|
|
S48_GC_UNPROTECT();
|
|
return res;
|
|
}
|
|
|
|
s48_value scsh_yp_next(s48_value domain, s48_value map, s48_value inkey)
|
|
{
|
|
char *key, *val;
|
|
int keylen, vallen, r;
|
|
s48_value res, str1, str2;
|
|
S48_DECLARE_GC_PROTECT(6);
|
|
|
|
S48_GC_PROTECT_6(domain, map, inkey, res, str1, str2);
|
|
r = yp_next(s48_extract_string(domain), s48_extract_string(map),
|
|
s48_extract_string(inkey), S48_STRING_LENGTH(inkey),
|
|
&key, &keylen, &val, &vallen);
|
|
str1 = (r == 0) ? s48_enter_string(key) : S48_UNSPECIFIC;
|
|
str2 = (r == 0) ? s48_enter_string(val) : S48_UNSPECIFIC;
|
|
res = s48_list_3(s48_enter_integer(r), str1, str2);
|
|
S48_GC_UNPROTECT();
|
|
return res;
|
|
}
|
|
|
|
void scsh_yp_main(void)
|
|
{
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_badargs, "yp-error-badargs", YPERR_BADARGS);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_baddb, "yp-error-baddb", YPERR_BADDB);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_domain, "yp-error-domain", YPERR_DOMAIN);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_key, "yp-error-key", YPERR_KEY);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_map, "yp-error-map", YPERR_MAP);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_nodom, "yp-error-nodom", YPERR_NODOM);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_nomore, "yp-error-nomore", YPERR_NOMORE);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_pmap, "yp-error-pmap", YPERR_PMAP);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_resrc, "yp-error-resrc", YPERR_RESRC);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_rpc, "yp-error-rpc", YPERR_RPC);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_vers, "yp-error-vers", YPERR_VERS);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_ypbind, "yp-error-bind", YPERR_YPBIND);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_yperr, "yp-error-yperr", YPERR_YPERR);
|
|
GC_PROTECT_ENTER_INT(scsh_yp_error_ypserv, "yp-error-ypserv", YPERR_YPSERV);
|
|
|
|
S48_EXPORT_FUNCTION(scsh_yp_getdefaultdomain);
|
|
S48_EXPORT_FUNCTION(scsh_yp_bind);
|
|
S48_EXPORT_FUNCTION(scsh_yp_unbind);
|
|
S48_EXPORT_FUNCTION(scsh_yp_errstring);
|
|
S48_EXPORT_FUNCTION(scsh_yp_proterr);
|
|
S48_EXPORT_FUNCTION(scsh_yp_match);
|
|
S48_EXPORT_FUNCTION(scsh_yp_order);
|
|
S48_EXPORT_FUNCTION(scsh_yp_master);
|
|
S48_EXPORT_FUNCTION(scsh_yp_first);
|
|
S48_EXPORT_FUNCTION(scsh_yp_next);
|
|
}
|