Back to index

glibc  2.9
Classes | Defines | Typedefs | Functions | Variables
rpc_util.h File Reference
#include <stdlib.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  list
struct  xdrfunc

Defines

#define alloc(size)   malloc((unsigned)(size))
#define ALLOC(object)   (object *) malloc(sizeof(object))
#define s_print   (void) sprintf
#define f_print   (void) fprintf
#define PUT   1
#define GET   2
#define MAXLINESIZE   1024
#define STOREVAL(list, item)   storeval(list,item)
#define FINDVAL(list, item, finder)   findval(list, item, finder)

Typedefs

typedef struct list
typedef struct xdrfunc

Functions

void storeval (list **lstp, definition *val)
definition * findval (list *lst, const char *val, int(*cmp)(const definition *, const char *))
const char * fixtype (const char *type)
const char * stringfix (const char *type)
char * locase (const char *str)
void pvname_svc (const char *pname, const char *vnum)
void pvname (const char *pname, const char *vnum)
void ptype (const char *prefix, const char *type, int follow)
int isvectordef (const char *type, relation rel)
int streq (const char *a, const char *b)
void error (const char *msg)
void tabify (FILE *f, int tab)
void record_open (const char *file)
bas_type * find_type (const char *type)
void emit (definition *def)
void print_datadef (definition *def)
void print_funcdef (definition *def)
void write_most (const char *infile, int netflag, int nomain)
void write_register (void)
void write_rest (void)
void write_programs (const char *storage)
void write_svc_aux (int nomain)
void write_inetd_register (const char *transp)
void write_netid_register (const char *)
void write_nettype_register (const char *)
void write_stubs (void)
void write_tables (void)

Variables

char curline [MAXLINESIZE]
const char * where
int linenum
const char * infilename
FILEfout
FILEfin
listdefined
bas_type * typ_list_h
bas_type * typ_list_t
xdrfuncxdrfunc_head
xdrfuncxdrfunc_tail
int inetdflag
int pmflag
int tblflag
int logflag
int newstyle
int Cflag
int CCflag
int tirpcflag
int inlineflag
int mtflag
int indefinitewait
int exitnow
int timerflag
int nonfatalerrors

Class Documentation

struct list

Definition at line 93 of file dl-deps.c.

Collaboration diagram for list:
Class Members
int done
struct link_map * map
struct list * next
definition * val
struct xdrfunc

Definition at line 51 of file rpc_util.h.

Collaboration diagram for xdrfunc:
Class Members
char * name
struct xdrfunc * next
int pointerp

Define Documentation

#define alloc (   size)    malloc((unsigned)(size))

Definition at line 39 of file rpc_util.h.

#define ALLOC (   object)    (object *) malloc(sizeof(object))

Definition at line 40 of file rpc_util.h.

#define f_print   (void) fprintf

Definition at line 43 of file rpc_util.h.

#define FINDVAL (   list,
  item,
  finder 
)    findval(list, item, finder)

Definition at line 110 of file rpc_util.h.

#define GET   2

Definition at line 59 of file rpc_util.h.

#define MAXLINESIZE   1024

Definition at line 64 of file rpc_util.h.

#define PUT   1

Definition at line 58 of file rpc_util.h.

#define s_print   (void) sprintf

Definition at line 42 of file rpc_util.h.

#define STOREVAL (   list,
  item 
)    storeval(list,item)

Definition at line 106 of file rpc_util.h.


Typedef Documentation

typedef struct list

Definition at line 49 of file rpc_util.h.

typedef struct xdrfunc

Definition at line 56 of file rpc_util.h.


Function Documentation

void emit ( definition *  def)

Definition at line 72 of file rpc_cout.c.

{
  if (def->def_kind == DEF_CONST)
    {
      return;
    }
  if (def->def_kind == DEF_PROGRAM)
    {
      emit_program (def);
      return;
    }
  if (def->def_kind == DEF_TYPEDEF)
    {
      /* now we need to handle declarations like
         struct typedef foo foo;
         since we don't want this to be expanded
         into 2 calls to xdr_foo */

      if (strcmp (def->def.ty.old_type, def->def_name) == 0)
       return;
    };

  print_header (def);
  switch (def->def_kind)
    {
    case DEF_UNION:
      emit_union (def);
      break;
    case DEF_ENUM:
      emit_enum (def);
      break;
    case DEF_STRUCT:
      emit_struct (def);
      break;
    case DEF_TYPEDEF:
      emit_typedef (def);
      break;
    default:
      /* can't happen */
      break;
    }
  print_trailer ();
}

Here is the call graph for this function:

void error ( const char *  msg)

Definition at line 275 of file rpc_util.c.

{
  printwhere ();
  f_print (stderr, "%s, line %d: ", infilename, linenum);
  f_print (stderr, "%s\n", msg);
  crash ();
}
bas_type* find_type ( const char *  type)

Definition at line 512 of file rpc_util.c.

{
  bas_type *ptr;

  ptr = typ_list_h;


  while (ptr != NULL)
    {
      if (strcmp (ptr->name, type) == 0)
       return ptr;
      else
       ptr = ptr->next;
    };
  return NULL;
}

Here is the caller graph for this function:

definition* findval ( list lst,
const char *  val,
int(*)(const definition *, const char *)  cmp 
)

Definition at line 96 of file rpc_util.c.

{

  for (; lst != NULL; lst = lst->next)
    {
      if (cmp (lst->val, val))
       {
         return lst->val;
       }
    }
  return NULL;
}

Here is the caller graph for this function:

const char* fixtype ( const char *  type)

Definition at line 158 of file rpc_util.c.

{
  return fixit (type, type);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int isvectordef ( const char *  type,
relation  rel 
)

Definition at line 218 of file rpc_util.c.

{
  definition *def;

  for (;;)
    {
      switch (rel)
       {
       case REL_VECTOR:
         return !streq (type, "string");
       case REL_ARRAY:
         return 0;
       case REL_POINTER:
         return 0;
       case REL_ALIAS:
         def = findval (defined, type, typedefed);
         if (def == NULL)
           {
             return 0;
           }
         type = def->def.ty.old_type;
         rel = def->def.ty.rel;
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* locase ( const char *  str)

Definition at line 245 of file rpc_util.c.

{
  char c;
  static char buf[100];
  char *p = buf;

  while ((c = *str++) != 0)
    {
      *p++ = (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c;
    }
  *p = 0;
  return buf;
}

Here is the caller graph for this function:

void print_datadef ( definition *  def)

Definition at line 86 of file rpc_hout.c.

{

  if (def->def_kind == DEF_PROGRAM)       /* handle data only */
    return;

  if (def->def_kind != DEF_CONST)
    {
      f_print (fout, "\n");
    }
  switch (def->def_kind)
    {
    case DEF_STRUCT:
      pstructdef (def);
      break;
    case DEF_UNION:
      puniondef (def);
      break;
    case DEF_ENUM:
      penumdef (def);
      break;
    case DEF_TYPEDEF:
      ptypedef (def);
      break;
    case DEF_PROGRAM:
      pprogramdef (def);
      break;
    case DEF_CONST:
      pconstdef (def);
      break;
    }
  if (def->def_kind != DEF_PROGRAM && def->def_kind != DEF_CONST)
    {
      storexdrfuncdecl(def->def_name,
                     def->def_kind != DEF_TYPEDEF ||
                     !isvectordef(def->def.ty.old_type,
                                def->def.ty.rel));
    }
}

Here is the call graph for this function:

void print_funcdef ( definition *  def)

Definition at line 128 of file rpc_hout.c.

{
  switch (def->def_kind)
    {
    case DEF_PROGRAM:
      f_print (fout, "\n");
      pprogramdef (def);
      break;
    default:
      break;
      /* ?... shouldn't happen I guess */
    }
}

Here is the call graph for this function:

void ptype ( const char *  prefix,
const char *  type,
int  follow 
)

Definition at line 177 of file rpc_util.c.

{
  if (prefix != NULL)
    {
      if (streq (prefix, "enum"))
       {
         f_print (fout, "enum ");
       }
      else
       {
         f_print (fout, "struct ");
       }
    }
  if (streq (type, "bool"))
    {
      f_print (fout, "bool_t ");
    }
  else if (streq (type, "string"))
    {
      f_print (fout, "char *");
    }
  else
    {
      f_print (fout, "%s ", follow ? fixtype (type) : type);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pvname ( const char *  pname,
const char *  vnum 
)

Definition at line 266 of file rpc_util.c.

{
  f_print (fout, "%s_%s", locase (pname), vnum);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pvname_svc ( const char *  pname,
const char *  vnum 
)

Definition at line 260 of file rpc_util.c.

{
  f_print (fout, "%s_%s_svc", locase (pname), vnum);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void record_open ( const char *  file)

Definition at line 300 of file rpc_util.c.

{
  if (nfiles < NFILES)
    {
      outfiles[nfiles++] = file;
    }
  else
    {
      f_print (stderr, "too many files!\n");
      crash ();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void storeval ( list **  lstp,
definition *  val 
)

Definition at line 114 of file rpc_util.c.

{
  list **l;
  list *lst;


  for (l = lstp; *l != NULL; l = (list **) & (*l)->next);
  lst = ALLOC (list);
  lst->val = val;
  lst->next = NULL;
  *l = lst;
}
int streq ( const char *  a,
const char *  b 
)

Definition at line 87 of file rpc_util.c.

{
  return strcmp (a, b) == 0;
}
const char* stringfix ( const char *  type)

Definition at line 164 of file rpc_util.c.

{
  if (streq (type, "string"))
    {
      return "wrapstring";
    }
  else
    {
      return type;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tabify ( FILE f,
int  tab 
)

Definition at line 352 of file rpc_util.c.

{
  while (tab--)
    {
      (void) fputc ('\t', f);
    }
}

Here is the call graph for this function:

void write_inetd_register ( const char *  transp)

Definition at line 1036 of file rpc_svcout.c.

{
  list *l;
  definition *def;
  version_list *vp;
  const char *sp;
  int isudp;
  char tmpbuf[32];

  if (inetdflag)
    sp = "\t";
  else
    sp = "";
  if (streq (transp, "udp") || streq (transp, "udp6"))
    isudp = 1;
  else
    isudp = 0;
  f_print (fout, "\n");
  if (inetdflag)
    {
      f_print (fout, "\tif ((_rpcfdtype == 0) || (_rpcfdtype == %s)) {\n",
              isudp ? "SOCK_DGRAM" : "SOCK_STREAM");
    }
  f_print (fout, "%s\t%s = svc%s_create(%s",
          sp, TRANSP, transp, inetdflag ? "sock" : "RPC_ANYSOCK");
  if (!isudp)
    f_print (fout, ", 0, 0");
  f_print (fout, ");\n");
  f_print (fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
  (void) sprintf (_errbuf, "cannot create %s service.", transp);
  (void) sprintf (tmpbuf, "%s\t\t", sp);
  print_err_message (tmpbuf);
  f_print (fout, "%s\t\texit(1);\n", sp);
  f_print (fout, "%s\t}\n", sp);

  if (inetdflag)
    {
      f_print (fout, "%s\tif (!_rpcpmstart)\n\t", sp);
      f_print (fout, "%s\tproto = IPPROTO_%s;\n",
              sp, isudp ? "UDP" : "TCP");
    }
  for (l = defined; l != NULL; l = l->next)
    {
      def = (definition *) l->val;
      if (def->def_kind != DEF_PROGRAM)
       {
         continue;
       }
      for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
       {
         f_print (fout, "%s\tif (!svc_register(%s, %s, %s, ",
                 sp, TRANSP, def->def_name, vp->vers_name);
         pvname (def->def_name, vp->vers_num);
         if (inetdflag)
           f_print (fout, ", proto)) {\n");
         else
           f_print (fout, ", IPPROTO_%s)) {\n",
                   isudp ? "UDP" : "TCP");
         (void) sprintf (_errbuf, "unable to register (%s, %s, %s).",
                       def->def_name, vp->vers_name, transp);
         print_err_message (tmpbuf);
         f_print (fout, "%s\t\texit(1);\n", sp);
         f_print (fout, "%s\t}\n", sp);
       }
    }
  if (inetdflag)
    f_print (fout, "\t}\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_most ( const char *  infile,
int  netflag,
int  nomain 
)

Definition at line 91 of file rpc_svcout.c.

{
  if (inetdflag || pmflag)
    {
      const char *var_type;
#ifdef __GNU_LIBRARY__
      /* WHY? */
      var_type = (nomain ? "extern" : "");
#else
      var_type = (nomain ? "extern" : "static");
#endif
      f_print (fout, "%s int _rpcpmstart;", var_type);
      f_print (fout, "\t\t/* Started by a port monitor ? */\n");
      if (!tirpcflag)
       {
         f_print (fout, "%s int _rpcfdtype;", var_type);
         f_print (fout, "\t\t/* Whether Stream or Datagram ? */\n");
       }
      if (timerflag)
       {
#if 0
         f_print (fout, "%s int _rpcsvcdirty;", var_type);
         f_print (fout, "\t/* Still serving ? */\n");
#else
         f_print(fout, " /* States a server can be in wrt request */\n\n");
         f_print(fout, "#define\t_IDLE 0\n");
         f_print(fout, "#define\t_SERVED 1\n");
         f_print(fout, "#define\t_SERVING 2\n\n");
         f_print(fout, "static int _rpcsvcstate = _IDLE;");
         f_print(fout, "\t /* Set when a request is serviced */\n");

         if (mtflag)
           {
             f_print (fout, "mutex_t _svcstate_lock;");
             f_print (fout,
                     "\t\t\t/* Mutex lock for variable_rpcsvcstate */\n");
           }
#endif
       }
      write_svc_aux (nomain);
    }
  /* write out dispatcher and stubs */
  write_programs (nomain ? NULL : "static");

  if (nomain)
    return;

#ifdef __GNU_LIBRARY__
  if (Cflag)
    f_print (fout, "\nint\nmain (int argc, char **argv)\n");
  else
    {
      f_print (fout, "\nint\nmain (argc, argv)\n");
      f_print (fout, "\tint argc;\n");
      f_print (fout, "\tchar **argv;\n");
    }
#else
  f_print (fout, "\nmain()\n");
#endif
  f_print (fout, "{\n");
  if (inetdflag)
    {
      write_inetmost (infile);     /* Includes call to write_rpc_svc_fg() */
    }
  else
    {
      if (tirpcflag)
       {
         if (netflag)
           {
             f_print (fout, "\tregister SVCXPRT *%s;\n", TRANSP);
             f_print (fout, "\tstruct netconfig *nconf = NULL;\n");
           }
         f_print (fout, "\tpid_t pid;\n");
         f_print (fout, "\tint i;\n");
         f_print (fout, "\tchar mname[FMNAMESZ + 1];\n\n");

         if (mtflag & timerflag)
           f_print (fout,
                   "\tmutex_init (&_svcstate_lock, USYNC_THREAD, NULL);\n");

         write_pm_most (infile, netflag);
         f_print (fout, "\telse {\n");
         write_rpc_svc_fg (infile, "\t\t");
         f_print (fout, "\t}\n");
       }
      else
       {
         f_print (fout, "\tregister SVCXPRT *%s;\n", TRANSP);
         f_print (fout, "\n");
         print_pmapunset ("\t");
       }
    }

  if (logflag && !inetdflag)
    {
      open_log_file (infile, "\t");
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_netid_register ( const char *  )

Definition at line 195 of file rpc_svcout.c.

{
  list *l;
  definition *def;
  version_list *vp;
  const char *sp;
  char tmpbuf[32];

  sp = "";
  f_print (fout, "\n");
  f_print (fout, "%s\tnconf = getnetconfigent (\"%s\");\n", sp, transp);
  f_print (fout, "%s\tif (nconf == NULL) {\n", sp);
  (void) sprintf (_errbuf, "cannot find %s netid.", transp);
  sprintf (tmpbuf, "%s\t\t", sp);
  print_err_message (tmpbuf);
  f_print (fout, "%s\t\texit (1);\n", sp);
  f_print (fout, "%s\t}\n", sp);
  f_print (fout, "%s\t%s = svc_tli_create (RPC_ANYFD, nconf, 0, 0, 0);\n",
          sp, TRANSP /*, transp *//* ?!?... */ );
  f_print (fout, "%s\tif (%s == NULL) {\n", sp, TRANSP);
  sprintf (_errbuf, "cannot create %s service.", transp);
  print_err_message (tmpbuf);
  f_print (fout, "%s\t\texit (1);\n", sp);
  f_print (fout, "%s\t}\n", sp);

  for (l = defined; l != NULL; l = l->next)
    {
      def = (definition *) l->val;
      if (def->def_kind != DEF_PROGRAM)
       {
         continue;
       }
      for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
       {
         f_print (fout, "%s\t(void) rpcb_unset (%s, %s, nconf);\n",
                 sp, def->def_name, vp->vers_name);
         f_print (fout, "%s\tif (!svc_reg (%s, %s, %s, ",
                 sp, TRANSP, def->def_name, vp->vers_name);
         pvname (def->def_name, vp->vers_num);
         f_print (fout, ", nconf)) {\n");
         (void) sprintf (_errbuf, "unable to register (%s, %s, %s).",
                       def->def_name, vp->vers_name, transp);
         print_err_message (tmpbuf);
         f_print (fout, "%s\t\texit (1);\n", sp);
         f_print (fout, "%s\t}\n", sp);
       }
    }
  f_print (fout, "%s\tfreenetconfigent (nconf);\n", sp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_nettype_register ( const char *  )

Definition at line 249 of file rpc_svcout.c.

{
  list *l;
  definition *def;
  version_list *vp;

  for (l = defined; l != NULL; l = l->next)
    {
      def = (definition *) l->val;
      if (def->def_kind != DEF_PROGRAM)
       {
         continue;
       }
      for (vp = def->def.pr.versions; vp != NULL; vp = vp->next)
       {
         f_print (fout, "\tif (!svc_create (");
         pvname (def->def_name, vp->vers_num);
         f_print (fout, ", %s, %s, \"%s\")) {\n ",
                 def->def_name, vp->vers_name, transp);
         (void) sprintf (_errbuf,
                       "unable to create (%s, %s) for %s.",
                       def->def_name, vp->vers_name, transp);
         print_err_message ("\t\t");
         f_print (fout, "\t\texit (1);\n");
         f_print (fout, "\t}\n");
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_programs ( const char *  storage)

Definition at line 311 of file rpc_svcout.c.

{
  list *l;
  definition *def;

  /* write out stubs for procedure  definitions */
  for (l = defined; l != NULL; l = l->next)
    {
      def = (definition *) l->val;
      if (def->def_kind == DEF_PROGRAM)
       {
         write_real_program (def);
       }
    }

  /* write out dispatcher for each program */
  for (l = defined; l != NULL; l = l->next)
    {
      def = (definition *) l->val;
      if (def->def_kind == DEF_PROGRAM)
       {
         write_program (def, storage);
       }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_register ( void  )
void write_rest ( void  )

Definition at line 282 of file rpc_svcout.c.

{
  f_print (fout, "\n");
  if (inetdflag)
    {
      f_print (fout, "\tif (%s == (SVCXPRT *)NULL) {\n", TRANSP);
      (void) sprintf (_errbuf, "could not create a handle");
      print_err_message ("\t\t");
      f_print (fout, "\t\texit (1);\n");
      f_print (fout, "\t}\n");
      if (timerflag)
       {
         f_print (fout, "\tif (_rpcpmstart) {\n");
         f_print (fout,
                 "\t\t(void) signal (SIGALRM, %s closedown);\n",
                 Cflag ? "(SIG_PF)" : "(void(*)())");
         f_print (fout, "\t\t(void) alarm (_RPCSVC_CLOSEDOWN);\n");
         f_print (fout, "\t}\n");
       }
    }
  f_print (fout, "\tsvc_run ();\n");
  (void) sprintf (_errbuf, "svc_run returned");
  print_err_message ("\t");
  f_print (fout, "\texit (1);\n");
  f_print (fout, "\t/* NOTREACHED */\n");
  f_print (fout, "}\n");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void write_stubs ( void  )

Definition at line 56 of file rpc_clntout.c.

{
  list *l;
  definition *def;

  fprintf (fout,
          "\n/* Default timeout can be changed using clnt_control() */\n");
  fprintf (fout, "static struct timeval TIMEOUT = { %d, 0 };\n",
          DEFAULT_TIMEOUT);
  for (l = defined; l != NULL; l = l->next)
    {
      def = (definition *) l->val;
      if (def->def_kind == DEF_PROGRAM)
       {
         write_program (def);
       }
    }
}

Here is the call graph for this function:

void write_svc_aux ( int  nomain)

Definition at line 762 of file rpc_svcout.c.

{
  if (!logflag)
    write_msg_out ();
  if (!nomain)
    write_timeout_func ();
}

Here is the call graph for this function:

void write_tables ( void  )

Definition at line 64 of file rpc_tblout.c.

{
  list *l;
  definition *def;

  f_print (fout, "\n");
  for (l = defined; l != NULL; l = l->next)
    {
      def = (definition *) l->val;
      if (def->def_kind == DEF_PROGRAM)
       {
         write_table (def);
       }
    }
}

Here is the call graph for this function:


Variable Documentation

Definition at line 49 of file rpc_util.c.

Definition at line 62 of file rpc_util.c.

Definition at line 60 of file rpc_util.c.

Definition at line 59 of file rpc_util.c.

Definition at line 53 of file rpc_util.c.

Definition at line 51 of file rpc_util.c.

bas_type* typ_list_h

Definition at line 477 of file rpc_util.c.

bas_type* typ_list_t

Definition at line 478 of file rpc_util.c.

const char* where

Definition at line 50 of file rpc_util.c.