/*****************************************************************/
/**                                                             **/
/**             (C) Copyright 1992 the Regents of the           **/
/**        University of California.  All Rights Reserved.      **/
/**                                                             **/
/**        This work was produced under the sponsorship of      **/
/**         the U.S. Department of Energy.  The Government      **/
/**                retains certain rights therein.              **/
/**                                                             **/
/**                         Written by                          **/
/**         Distributed Programming Environments Project        **/
/**           Computer Software and Networking Division,        **/
/**                   Livermore Computer Center,                **/
/**            Lawrence Livermore National Laboratory           **/
/**                                                             **/
/*****************************************************************/

static char sccsid_sendP_charstr[] = "@(#)sendP_charstr.c	1.4 10/20/92 06:01:27 LLNL ";

/*
	Embedded Language for Remote Operations Services
	ELROS

	AUTHOR:		Linda Stanberry
			Computer Software and Networking Division

	DATE WRITTEN:	7/7/92

	ROUTINE:	__ROr_BERsendP_CharString
			

PURPOSE:
	Encode the value data of char strings in ASN.1.
	

IN:
	instance
		Send state and buffer.
	value -	The data to be encoded
	valuelength - Length of the data to be encoded.
 	maxlength - Maximum length of the encoded data.
	

OUT:
	instance -
		Send state and error state are update.
		Data buffer.


CALLED ROUTINES:
		__ROr_encP_length
		instance->send_data
	

	
MODIFICATION HISTORY:


*/

#include <elros/instance.h>
#include <elros/enc_dcd.h>
#include <elros/encP_length.h>
#include <elros/sendP_element.h>

int __ROr_BERsendP_CharString( instance, value, valuelength, maxlength, maxlength2)

   __RO_Instance_Record *instance;	/* pointer to instance record	*/
   char 		*value;		/* location of unencoded value	*/
   unsigned long	*valuelength;	/* physical length of unencoded value */
   unsigned long	*maxlength;	/* maximum length of encoded data */
   unsigned long	*maxlength2;	/* 2nd max length for 2 part encoding */

{  unsigned long length;
   
   if (value)
      length = strlen(value);
   else
      length = 0;

   if( *maxlength && (length > *maxlength) ) {
	__RO_RETURN_RUNTIME( instance, __ROx_ENC_EXCEEDEDMAXLEN );
   }

   __ROr_encP_length( instance,  &length );

   if (value)
      __ROr_sendP_Nelement( instance, value, length );

   return (SUCCESS);
}
