AutoXDR - NFSv4 Example Enum translator


This code translates enumerations into strings and back. It can be used on either the client or server side, but the interface is declared in the client header.

/*
 *  DO NOT EDIT THIS FILE   (nfsv4-enum.c)
 *  
 *  It has been AutoGen-ed  Saturday May 26, 2001 at 04:36:08 PM PDT
 *  From the definitions    nfsv4.def
 *  and the template file   autoxdr.tpl
 *
 *  This file has been generated by the AutoXDR AutoGen template suite.
 *
 *  These files are compatible with:
 *  RFC1831 - Remote Procedure Call Protocol Specification Version 2
 *  RFC1832 - External Data Representation Standard
 *  and are intended to be used as a layer on top of the ONC IDL
 *  in conjunction with RPCGEN.
 *
 */
#include <stdio.h>
#include "nfsv4-clhdr.h"
#include "nfsv4.h"

static const char zOopFmt[] =
   "`%d' is not in NFS4's %s enumeration\n";
static const char zOopFmt2[] =
   "`%s' is not in NFS4's %s enumeration\n";
static char zOops[ sizeof(zOopFmt) + 64 ];

typedef struct enum_info {
  int           eid;
  const char*   pz_name;
  const char*   pz_info;
  int           unused;
} t_enum_info;

/*
 *  NFS4's status enumeration conversions
 */
static t_enum_info a_nfs4_status_info[] = {
  { 0, "OK", "successful completion", 0 },
  { 1, "PERM", "caller is either not privileged or not owner", 0 },
  { 2, "NOENT", "No such file or directory", 0 },
  { 256, "OMITTED", "operation omitted", 0 }
};



const char*
info_nfs4_status( nfs4_status eid )
{
  int lo = 0;
  int hi = 3;
  int av = (lo + hi)/2;

  for (;;)
    {
      int c = (int)eid - a_nfs4_status_info[ av ].eid;
      if (c == 0)
        return a_nfs4_status_info[ av ].pz_info;
      if (c < 0)
        hi = av - 1;
      else
        lo = av + 1;

      if (hi < lo)
        break;
      av = (lo + hi)/2;
    }

  snprintf( zOops, sizeof( zOops ), zOopFmt, eid, "status" );
  return zOops;
}


const char*
name_nfs4_status( nfs4_status eid )
{
  int lo = 0;
  int hi = 3;
  int av = (lo + hi)/2;

  for (;;)
    {
      int c = (int)eid - a_nfs4_status_info[ av ].eid;
      if (c == 0)
        return a_nfs4_status_info[ av ].pz_name;
      if (c < 0)
        hi = av - 1;
      else
        lo = av + 1;

      if (hi < lo)
        break;
      av = (lo + hi)/2;
    }

  snprintf( zOops, sizeof( zOops ), zOopFmt, eid, "status" );
  return zOops;
}

nfs4_status nfs4_status_enum( const char* pz_name )
{
  int i = 0;
  do
    {
      const char* pz = a_nfs4_status_info[i].pz_name;
      if ((pz != NULL) && (strcmp( pz, pz_name ) == 0))
        return a_nfs4_status_info[i].eid;
    }
  while (++i < 4);
  fprintf( stderr, zOopFmt2, pz_name, "status" );
  return (nfs4_status)-1;
}

const char*
name_nfs4_compound_ops( nfs4_compound_ops op )
{
  static const char* apz_op_names[] = {
    "ACCESS4" };
  int idx = (int)op - 3;
  if ((unsigned)idx > 0)
    return (const char*)NULL;
  return apz_op_names[ idx ];
}


Viewable With Any Browser


AutoGen, AutoOpts, columns, getdefs, AutoFSM, AutoXDR and these web pages copyright (c) 1999, 2000, 2001 Bruce Korb, all rights reserved.

AutoXDR copyright (c) 2000 Bruce Korb, all rights reserved.