Back to index

glibc  2.9
yp_xdr.c
Go to the documentation of this file.
00001 /*
00002  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00003  * unrestricted use provided that this legend is included on all tape
00004  * media and as a part of the software program in whole or part.  Users
00005  * may copy or modify Sun RPC without charge, but are not authorized
00006  * to license or distribute it to anyone else except as part of a product or
00007  * program developed by the user.
00008  *
00009  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00010  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00011  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00012  *
00013  * Sun RPC is provided with no support and without any obligation on the
00014  * part of Sun Microsystems, Inc. to assist in its use, correction,
00015  * modification or enhancement.
00016  *
00017  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00018  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00019  * OR ANY PART THEREOF.
00020  *
00021  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00022  * or profits or other special, indirect and consequential damages, even if
00023  * Sun has been advised of the possibility of such damages.
00024  *
00025  * Sun Microsystems, Inc.
00026  * 2550 Garcia Avenue
00027  * Mountain View, California  94043
00028  */
00029 
00030 #include <rpcsvc/yp.h>
00031 #include <rpcsvc/ypclnt.h>
00032 
00033 bool_t
00034 xdr_ypstat (XDR *xdrs, ypstat *objp)
00035 {
00036   return xdr_enum (xdrs, (enum_t *) objp);
00037 }
00038 libnsl_hidden_def (xdr_ypstat)
00039 
00040 bool_t
00041 xdr_ypxfrstat (XDR *xdrs, ypxfrstat *objp)
00042 {
00043   return xdr_enum (xdrs, (enum_t *) objp);
00044 }
00045 libnsl_hidden_def (xdr_ypxfrstat)
00046 
00047 bool_t
00048 xdr_domainname (XDR *xdrs, domainname *objp)
00049 {
00050   return xdr_string (xdrs, objp, ~0);
00051 }
00052 libnsl_hidden_def (xdr_domainname)
00053 
00054 bool_t
00055 xdr_mapname (XDR *xdrs, mapname *objp)
00056 {
00057   return xdr_string (xdrs, objp, ~0);
00058 }
00059 libnsl_hidden_def (xdr_mapname)
00060 
00061 bool_t
00062 xdr_peername (XDR *xdrs, peername *objp)
00063 {
00064   return xdr_string (xdrs, objp, ~0);
00065 }
00066 libnsl_hidden_def (xdr_peername)
00067 
00068 bool_t
00069 xdr_keydat (XDR *xdrs, keydat *objp)
00070 {
00071   return xdr_bytes (xdrs, (char **) &objp->keydat_val,
00072                   (u_int *) &objp->keydat_len, ~0);
00073 }
00074 libnsl_hidden_def (xdr_keydat)
00075 
00076 bool_t
00077 xdr_valdat (XDR *xdrs, valdat *objp)
00078 {
00079   return xdr_bytes (xdrs, (char **) &objp->valdat_val,
00080                   (u_int *) &objp->valdat_len, ~0);
00081 }
00082 libnsl_hidden_def (xdr_valdat)
00083 
00084 bool_t
00085 xdr_ypmap_parms (XDR *xdrs, ypmap_parms *objp)
00086 {
00087   if (!xdr_domainname (xdrs, &objp->domain))
00088     return FALSE;
00089   if (!xdr_mapname (xdrs, &objp->map))
00090     return FALSE;
00091   if (!xdr_u_int (xdrs, &objp->ordernum))
00092     return FALSE;
00093   return xdr_peername (xdrs, &objp->peer);
00094 }
00095 libnsl_hidden_def (xdr_ypmap_parms)
00096 
00097 bool_t
00098 xdr_ypreq_key (XDR *xdrs, ypreq_key *objp)
00099 {
00100   if (!xdr_domainname (xdrs, &objp->domain))
00101     return FALSE;
00102   if (!xdr_mapname (xdrs, &objp->map))
00103     return FALSE;
00104   return xdr_keydat (xdrs, &objp->key);
00105 }
00106 libnsl_hidden_def (xdr_ypreq_key)
00107 
00108 bool_t
00109 xdr_ypreq_nokey (XDR *xdrs, ypreq_nokey *objp)
00110 {
00111   if (!xdr_domainname (xdrs, &objp->domain))
00112     return FALSE;
00113   return xdr_mapname (xdrs, &objp->map);
00114 }
00115 libnsl_hidden_def (xdr_ypreq_nokey)
00116 
00117 bool_t
00118 xdr_ypreq_xfr (XDR *xdrs, ypreq_xfr *objp)
00119 {
00120   if (!xdr_ypmap_parms (xdrs, &objp->map_parms))
00121     return FALSE;
00122   if (!xdr_u_int (xdrs, &objp->transid))
00123     return FALSE;
00124   if (!xdr_u_int (xdrs, &objp->prog))
00125     return FALSE;
00126   return xdr_u_int (xdrs, &objp->port);
00127 }
00128 
00129 bool_t
00130 xdr_ypresp_val (XDR *xdrs, ypresp_val *objp)
00131 {
00132   if (!xdr_ypstat (xdrs, &objp->stat))
00133     return FALSE;
00134   return xdr_valdat (xdrs, &objp->val);
00135 }
00136 libnsl_hidden_def (xdr_ypresp_val)
00137 
00138 bool_t
00139 xdr_ypresp_key_val (XDR *xdrs, ypresp_key_val *objp)
00140 {
00141   if (!xdr_ypstat (xdrs, &objp->stat))
00142     return FALSE;
00143   if (!xdr_valdat (xdrs, &objp->val))
00144     return FALSE;
00145   return xdr_keydat (xdrs, &objp->key);
00146 }
00147 libnsl_hidden_def (xdr_ypresp_key_val)
00148 
00149 bool_t
00150 xdr_ypresp_master (XDR *xdrs, ypresp_master *objp)
00151 {
00152   if (!xdr_ypstat (xdrs, &objp->stat))
00153     return FALSE;
00154   return xdr_peername (xdrs, &objp->peer);
00155 }
00156 libnsl_hidden_def (xdr_ypresp_master)
00157 
00158 bool_t
00159 xdr_ypresp_order (XDR *xdrs, ypresp_order *objp)
00160 {
00161   if (!xdr_ypstat (xdrs, &objp->stat))
00162     return FALSE;
00163   return xdr_u_int (xdrs, &objp->ordernum);
00164 }
00165 libnsl_hidden_def (xdr_ypresp_order)
00166 
00167 bool_t
00168 xdr_ypresp_all (XDR *xdrs, ypresp_all *objp)
00169 {
00170   if (!xdr_bool (xdrs, &objp->more))
00171     return FALSE;
00172   switch (objp->more)
00173     {
00174     case TRUE:
00175       return xdr_ypresp_key_val (xdrs, &objp->ypresp_all_u.val);
00176     case FALSE:
00177       break;
00178     default:
00179       return FALSE;
00180     }
00181   return TRUE;
00182 }
00183 libnsl_hidden_def (xdr_ypresp_all)
00184 
00185 bool_t
00186 xdr_ypresp_xfr (XDR *xdrs, ypresp_xfr *objp)
00187 {
00188   if (!xdr_u_int (xdrs, &objp->transid))
00189     return FALSE;
00190   return xdr_ypxfrstat (xdrs, &objp->xfrstat);
00191 }
00192 
00193 bool_t
00194 xdr_ypmaplist (XDR *xdrs, ypmaplist *objp)
00195 {
00196   if (!xdr_mapname (xdrs, &objp->map))
00197     return FALSE;
00198   /* Prevent gcc warning about alias violation.  */
00199   char **tp = (void *) &objp->next;
00200   return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist);
00201 }
00202 libnsl_hidden_def (xdr_ypmaplist)
00203 
00204 bool_t
00205 xdr_ypresp_maplist (XDR *xdrs, ypresp_maplist *objp)
00206 {
00207   if (!xdr_ypstat (xdrs, &objp->stat))
00208     return FALSE;
00209   /* Prevent gcc warning about alias violation.  */
00210   char **tp = (void *) &objp->maps;
00211   return xdr_pointer (xdrs, tp, sizeof (ypmaplist), (xdrproc_t) xdr_ypmaplist);
00212 }
00213 libnsl_hidden_def (xdr_ypresp_maplist)
00214 
00215 bool_t
00216 xdr_yppush_status (XDR *xdrs, yppush_status *objp)
00217 {
00218   return xdr_enum (xdrs, (enum_t *) objp);
00219 }
00220 libnsl_hidden_def (xdr_yppush_status)
00221 
00222 bool_t
00223 xdr_yppushresp_xfr (XDR *xdrs, yppushresp_xfr *objp)
00224 {
00225   if (!xdr_u_int (xdrs, &objp->transid))
00226     return FALSE;
00227   return xdr_yppush_status (xdrs, &objp->status);
00228 }
00229 
00230 bool_t
00231 xdr_ypbind_resptype (XDR *xdrs, ypbind_resptype *objp)
00232 {
00233   return xdr_enum (xdrs, (enum_t *) objp);
00234 }
00235 libnsl_hidden_def (xdr_ypbind_resptype)
00236 
00237 bool_t
00238 xdr_ypbind_binding (XDR *xdrs, ypbind_binding *objp)
00239 {
00240   if (!xdr_opaque (xdrs, objp->ypbind_binding_addr, 4))
00241     return FALSE;
00242   return xdr_opaque (xdrs, objp->ypbind_binding_port, 2);
00243 }
00244 libnsl_hidden_def (xdr_ypbind_binding)
00245 
00246 bool_t
00247 xdr_ypbind_resp (XDR *xdrs, ypbind_resp *objp)
00248 {
00249   if (!xdr_ypbind_resptype (xdrs, &objp->ypbind_status))
00250     return FALSE;
00251   switch (objp->ypbind_status)
00252     {
00253     case YPBIND_FAIL_VAL:
00254       return xdr_u_int (xdrs, &objp->ypbind_resp_u.ypbind_error);
00255     case YPBIND_SUCC_VAL:
00256       return xdr_ypbind_binding (xdrs, &objp->ypbind_resp_u.ypbind_bindinfo);
00257     }
00258   return FALSE;
00259 }
00260 libnsl_hidden_def (xdr_ypbind_resp)
00261 
00262 bool_t
00263 xdr_ypbind_setdom (XDR *xdrs, ypbind_setdom *objp)
00264 {
00265   if (!xdr_domainname (xdrs, &objp->ypsetdom_domain))
00266     return FALSE;
00267   if (!xdr_ypbind_binding (xdrs, &objp->ypsetdom_binding))
00268     return FALSE;
00269   return xdr_u_int (xdrs, &objp->ypsetdom_vers);
00270 }
00271 
00272 bool_t
00273 xdr_ypall(XDR *xdrs, struct ypall_callback *incallback)
00274 {
00275     struct ypresp_key_val out;
00276     char key[YPMAXRECORD], val[YPMAXRECORD];
00277 
00278     /*
00279      * Set up key/val struct to be used during the transaction.
00280      */
00281     memset(&out, 0, sizeof out);
00282     out.key.keydat_val = key;
00283     out.key.keydat_len = sizeof(key);
00284     out.val.valdat_val = val;
00285     out.val.valdat_len = sizeof(val);
00286 
00287     for (;;) {
00288        bool_t more, status;
00289 
00290        /* Values pending? */
00291        if (!xdr_bool(xdrs, &more))
00292            return FALSE;           /* can't tell! */
00293        if (!more)
00294            return TRUE;            /* no more */
00295 
00296        /* Transfer key/value pair. */
00297        status = xdr_ypresp_key_val(xdrs, &out);
00298 
00299        /*
00300         * If we succeeded, call the callback function.
00301         * The callback will return TRUE when it wants
00302         * no more values.  If we fail, indicate the
00303         * error.
00304         */
00305        if (status) {
00306            if ((*incallback->foreach)(out.stat,
00307                                    (char *)out.key.keydat_val, out.key.keydat_len,
00308                                    (char *)out.val.valdat_val, out.val.valdat_len,
00309                                    incallback->data))
00310               return TRUE;
00311        } else
00312            return FALSE;
00313     }
00314 }