Sun Microsystems, Inc.
spacerspacer
spacer www.sun.com docs.sun.com |
spacer
black dot
 
 
B.  RPC Protocol and Language Specification Authentication Protocols AUTH_KERB Authentication KERB Authentication Protocol  Previous   Contents   Next 
   
 

RPC Language Specification

Just as the XDR data types needed to be described in a formal language, the procedures that operate on these XDR data types in a formal language needed to be described. The RPC Language, an extension to the XDR language, serves this purpose. The following example is used to describe the essence of the language.

Example Service Described in the RPC Language

The following code example shows the specification of a simple ping program.


Example B-4 ping Service Using RPC Language

/*
 * Simple ping program
 */
program PING_PROG {
 	version PING_VERS_PINGBACK {
 		void		
 		PINGPROC_NULL(void) = 0;
 		/*
		 * ping the caller, return the round-trip time
		 * in milliseconds. Return a minus one (-1) if
 		 * operation times-out
		 */
		int
 		PINGPROC_PINGBACK(void) = 1;
 		/* void - above is an argument to the call */
 	} = 2;
/*
 * Original version
 */
 	version PING_VERS_ORIG {
 		void
 		PINGPROC_NULL(void) = 0;
 	} = 1;
} = 200000;	
const PING_VERS = 2; /* latest version */

The first version described is PING_VERS_PINGBACK with two procedures, PINGPROC_NULL and PINGPROC_PINGBACK.

PINGPROC_NULL takes no arguments and returns no results, but it is useful for such things as computing round-trip times from the client to the server and back again. By convention, procedure 0 of any RPC program should have the same semantics, and never require authentication.

The second procedure returns the amount of time in microseconds that the operation used.

The next version, PING_VERS_ORIG, is the original version of the protocol and does not contain the PINGPROC_PINGBACK procedure. It is useful for compatibility with old client programs.

RPCL Syntax

The RPC language (RPCL) is similar to C. This section describes the syntax of the RPC language, and includes examples. It also shows how RPC and XDR type definitions are compiled into C type definitions in the output header file.

An RPC language file consists of a series of definitions.

   definition-list:
      definition;
      definition; definition-list 

The file recognizes six types of definitions:

definition:
      enum-definition
 		const-definition
 		typedef-definition
 		struct-definition
 		union-definition
 		program-definition  

Definitions are not the same as declarations. No space is allocated by a definition, only the type definition of a single or series of data elements. This behavior means that variables still must be declared.

The RPC language is identical to the XDR language, except for the added definitions described in the following table.

Table B-2 RPC Language Definitions

Term

Definition

program-definition

program program-ident {version-list} = value

version-list

version;

version; version-list

version

version version-ident {procedure-list} = value

procedure-list

procedure;

procedure; procedure-list

procedure

type-ident procedure-ident (type-ident) = value

In the RPC language:

  • The following keywords are added and cannot be used as identifiers:

    program version.

  • Neither version name nor a version number can occur more than once within the scope of a program definition.

  • Neither a procedure name nor a procedure number can occur more than once within the scope of a version definition.

  • Program identifiers are in the same namespace as constant and type identifiers.

  • Only unsigned constants can be assigned to programs, versions, and procedures.

RPCL Enumerations

RPC/XDR enumerations have a similar syntax to C enumerations.

enum-definition:
   "enum" enum-ident "{"
 		enum-value-list
 	"}"
enum-value-list:
 	enum-value
 	enum-value "," enum-value-list
enum-value:
 	enum-value-ident
 	enum-value-ident "=" value   

Here is an example of an XDR enum and the C enum to which it gets compiled.

enum colortype {               enum colortype {
 	RED = 0,                       RED = 0,
 	GREEN = 1,       -->           GREEN = 1,
 	BLUE = 2                       BLUE = 2,
};                             };
                               typedef enum colortype colortype;
 
 
 
  Previous   Contents   Next