2
+----------------------------------------------------------------------+
4
+----------------------------------------------------------------------+
5
| Copyright (c) 1997-2004 The PHP Group |
6
+----------------------------------------------------------------------+
7
| This source file is subject to version 3.0 of the PHP license, |
8
| that is bundled with this package in the file LICENSE, and is |
9
| available through the world-wide-web at the following url: |
10
| http://www.php.net/license/3_0.txt. |
11
| If you did not receive a copy of the PHP license and are unable to |
12
| obtain it through the world-wide-web, please send a note to |
13
| license@php.net so we can mail you a copy immediately. |
14
+----------------------------------------------------------------------+
15
| Authors: Stephanie Wehner <_@r4k.net> |
17
+----------------------------------------------------------------------+
19
/* $Id: yp.c,v 1.45 2004/05/31 21:01:18 iliaa Exp $ */
26
#include "ext/standard/info.h"
32
#include <rpcsvc/ypclnt.h>
34
/* {{{ thread safety stuff */
39
PHP_YP_API php_yp_globals yp_globals;
44
function_entry yp_functions[] = {
45
PHP_FE(yp_get_default_domain, NULL)
46
PHP_FE(yp_order, NULL)
47
PHP_FE(yp_master, NULL)
48
PHP_FE(yp_match, NULL)
49
PHP_FE(yp_first, NULL)
53
PHP_FE(yp_errno, NULL)
54
PHP_FE(yp_err_string, NULL)
58
zend_module_entry yp_module_entry = {
59
STANDARD_MODULE_HEADER,
68
STANDARD_MODULE_PROPERTIES
75
/* {{{ proto string yp_get_default_domain(void)
76
Returns the domain or false */
77
PHP_FUNCTION(yp_get_default_domain)
81
if (ZEND_NUM_ARGS()) {
85
if((YP(error) = yp_get_default_domain(&outdomain))) {
86
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (YP(error)));
89
RETVAL_STRING(outdomain,1);
93
/* {{{ proto int yp_order(string domain, string map)
94
Returns the order number or false */
95
PHP_FUNCTION(yp_order)
100
unsigned long outval;
105
if((ZEND_NUM_ARGS() != 2) || zend_get_parameters_ex(2,&domain,&map) == FAILURE) {
109
convert_to_string_ex(domain);
110
convert_to_string_ex(map);
112
if((YP(error) = yp_order(Z_STRVAL_PP (domain), Z_STRVAL_PP (map), &outval))) {
113
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (YP(error)));
121
/* {{{ proto string yp_master(string domain, string map)
122
Returns the machine name of the master */
123
PHP_FUNCTION(yp_master)
125
pval **domain, **map;
128
if((ZEND_NUM_ARGS() != 2) || zend_get_parameters_ex(2,&domain,&map) == FAILURE) {
132
convert_to_string_ex(domain);
133
convert_to_string_ex(map);
135
if((YP(error) = yp_master(Z_STRVAL_PP (domain), Z_STRVAL_PP (map), &outname))) {
136
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (YP(error)));
140
RETVAL_STRING(outname,1);
144
/* {{{ proto string yp_match(string domain, string map, string key)
145
Returns the matched line or false */
146
PHP_FUNCTION(yp_match)
148
pval **domain, **map, **key;
152
if((ZEND_NUM_ARGS() != 3) || zend_get_parameters_ex(3,&domain,&map,&key) == FAILURE) {
156
convert_to_string_ex(domain);
157
convert_to_string_ex(map);
158
convert_to_string_ex(key);
160
if((YP(error) = yp_match(Z_STRVAL_PP (domain), Z_STRVAL_PP (map), Z_STRVAL_PP (key), Z_STRLEN_PP (key), &outval, &outvallen))) {
161
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (YP(error)));
165
RETVAL_STRINGL(outval,outvallen,1);
169
/* {{{ proto array yp_first(string domain, string map)
170
Returns the first key as array with $var[$key] and the the line as the value */
171
PHP_FUNCTION(yp_first)
173
pval **domain, **map;
174
char *outval, *outkey;
175
int outvallen, outkeylen;
177
if((ZEND_NUM_ARGS() != 2) || zend_get_parameters_ex(2,&domain,&map) == FAILURE) {
181
convert_to_string_ex(domain);
182
convert_to_string_ex(map);
184
if((YP(error) = yp_first(Z_STRVAL_PP (domain), Z_STRVAL_PP (map), &outkey, &outkeylen, &outval, &outvallen))) {
185
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (YP(error)));
188
array_init(return_value);
189
add_assoc_stringl_ex(return_value,outkey,outkeylen+1,outval,outvallen,1);
192
add_assoc_stringl(return_value,"key",outkey,outkeylen,1);
193
add_assoc_stringl(return_value,"value",outval,outvallen,1);
197
/* {{{ proto array yp_next(string domain, string map, string key)
198
Returns an array with $var[$key] and the the line as the value */
199
PHP_FUNCTION(yp_next)
201
pval **domain, **map, **key;
202
char *outval, *outkey;
203
int outvallen, outkeylen;
205
if((ZEND_NUM_ARGS() != 3) || zend_get_parameters_ex(3,&domain,&map,&key) == FAILURE) {
209
convert_to_string_ex(domain);
210
convert_to_string_ex(map);
211
convert_to_string_ex(key);
213
if((YP(error) = yp_next(Z_STRVAL_PP (domain), Z_STRVAL_PP (map), Z_STRVAL_PP (key), Z_STRLEN_PP (key), &outkey, &outkeylen, &outval, &outvallen))) {
214
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (YP(error)));
218
array_init(return_value);
219
add_assoc_stringl_ex(return_value,outkey,outkeylen+1,outval,outvallen,1);
223
/* {{{ php_foreach_all
225
static int php_foreach_all (int instatus, char *inkey, int inkeylen, char *inval, int invallen, char *indata)
228
zval *status, *key, *value;
237
MAKE_STD_ZVAL (status);
238
ZVAL_LONG (status, ypprot_err (instatus));
241
ZVAL_STRINGL (key, inkey, inkeylen, 1);
243
MAKE_STD_ZVAL (value);
244
ZVAL_STRINGL (value, inval, invallen, 1);
246
if(call_user_function_ex(CG(function_table), NULL, *((zval **)indata), &retval, 3, args, 0, NULL TSRMLS_CC) != SUCCESS)
248
zval_ptr_dtor(&status);
250
zval_ptr_dtor(&value);
252
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Function call failed");
256
convert_to_long_ex(&retval);
257
r = Z_LVAL_P (retval);
259
zval_ptr_dtor(&retval);
261
zval_ptr_dtor(&status);
263
zval_ptr_dtor(&value);
269
/* {{{ proto bool yp_all(string domain, string map, string callback)
270
Traverse the map and call a function on each entry */
273
pval **domain, **map, **php_callback;
274
struct ypall_callback callback;
276
if((ZEND_NUM_ARGS() != 3) || zend_get_parameters_ex(3,&domain,&map,&php_callback) == FAILURE) {
280
convert_to_string_ex(domain);
281
convert_to_string_ex(map);
283
callback.foreach = php_foreach_all;
284
callback.data = (char *) php_callback;
286
yp_all(Z_STRVAL_PP(domain),Z_STRVAL_PP(map),&callback);
292
/* {{{ php_foreach_cat
294
static int php_foreach_cat (int instatus, char *inkey, int inkeylen, char *inval, int invallen, char *indata)
298
err = ypprot_err (instatus);
303
char *key = emalloc(inkeylen+1);
304
strlcpy(key, inkey, inkeylen+1);
305
add_assoc_stringl_ex((zval *) indata, key, inkeylen+1, inval, invallen, 1);
312
if (err != YPERR_NOMORE)
317
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", yperr_string (err));
324
/* {{{ proto array yp_cat(string domain, string map)
325
Return an array containing the entire map */
328
pval **domain, **map;
329
struct ypall_callback callback;
331
if((ZEND_NUM_ARGS() != 2) || zend_get_parameters_ex(2,&domain,&map) == FAILURE) {
335
convert_to_string_ex(domain);
336
convert_to_string_ex(map);
338
array_init(return_value);
340
callback.foreach = php_foreach_cat;
341
callback.data = (char *) return_value;
343
yp_all(Z_STRVAL_PP(domain),Z_STRVAL_PP(map),&callback);
347
/* {{{ proto int yp_errno()
348
Returns the error code from the last call or 0 if no error occured */
349
PHP_FUNCTION(yp_errno)
351
if((ZEND_NUM_ARGS() != 0)) {
355
RETURN_LONG (YP(error));
359
/* {{{ proto string yp_err_string(int errorcode)
360
Returns the corresponding error string for the given error code */
361
PHP_FUNCTION(yp_err_string)
366
if((ZEND_NUM_ARGS() != 1) || zend_get_parameters_ex(1,&error) == FAILURE) {
370
convert_to_long_ex(error);
372
if((string = yperr_string(Z_LVAL_PP(error))) == NULL) {
376
RETVAL_STRING(string,1);
380
/* {{{ PHP_MINIT_FUNCTION
382
PHP_MINIT_FUNCTION(yp)
385
ts_allocate_id(&yp_globals_id, sizeof(php_yp_globals), NULL, NULL);
388
REGISTER_LONG_CONSTANT("YPERR_BADARGS", YPERR_BADARGS, CONST_CS | CONST_PERSISTENT);
389
REGISTER_LONG_CONSTANT("YPERR_BADDB", YPERR_BADDB, CONST_CS | CONST_PERSISTENT);
390
REGISTER_LONG_CONSTANT("YPERR_BUSY", YPERR_BUSY, CONST_CS | CONST_PERSISTENT);
391
REGISTER_LONG_CONSTANT("YPERR_DOMAIN", YPERR_DOMAIN, CONST_CS | CONST_PERSISTENT);
392
REGISTER_LONG_CONSTANT("YPERR_KEY", YPERR_KEY, CONST_CS | CONST_PERSISTENT);
393
REGISTER_LONG_CONSTANT("YPERR_MAP", YPERR_MAP, CONST_CS | CONST_PERSISTENT);
394
REGISTER_LONG_CONSTANT("YPERR_NODOM", YPERR_NODOM, CONST_CS | CONST_PERSISTENT);
395
REGISTER_LONG_CONSTANT("YPERR_NOMORE", YPERR_NOMORE, CONST_CS | CONST_PERSISTENT);
396
REGISTER_LONG_CONSTANT("YPERR_PMAP", YPERR_PMAP, CONST_CS | CONST_PERSISTENT);
397
REGISTER_LONG_CONSTANT("YPERR_RESRC", YPERR_RESRC, CONST_CS | CONST_PERSISTENT);
398
REGISTER_LONG_CONSTANT("YPERR_RPC", YPERR_RPC, CONST_CS | CONST_PERSISTENT);
399
REGISTER_LONG_CONSTANT("YPERR_YPBIND", YPERR_YPBIND, CONST_CS | CONST_PERSISTENT);
400
REGISTER_LONG_CONSTANT("YPERR_YPERR", YPERR_YPERR, CONST_CS | CONST_PERSISTENT);
401
REGISTER_LONG_CONSTANT("YPERR_YPSERV", YPERR_YPSERV, CONST_CS | CONST_PERSISTENT);
402
REGISTER_LONG_CONSTANT("YPERR_VERS", YPERR_VERS, CONST_CS | CONST_PERSISTENT);
408
PHP_RINIT_FUNCTION(yp)
415
PHP_MINFO_FUNCTION(yp)
417
php_info_print_table_start();
418
php_info_print_table_row(2, "YP Support", "enabled");
419
php_info_print_table_end();
428
* vim600: sw=4 ts=4 fdm=marker