Пример #1
0
void
CS_set_server_connect(char *listen_id)
{
    i4		i;

    CS_find_server_slot(&i);

    STncpy( Cs_svinfo->csi_connect_id, listen_id,
	(sizeof(Cs_svinfo->csi_connect_id) - 1) );
    Cs_svinfo->csi_connect_id[ sizeof(Cs_svinfo->csi_connect_id) - 1 ] = EOS;
}
Пример #2
0
static STATUS
my_dynamic_index(i4 msg,
		 PTR cdata,
		 i4  linstance,
		 char *instance, 
		 PTR *instdata )
{
    STATUS stat = OK;
    i4 ival;
    char buf[ 20 ];

    switch( msg )
    {
    case MO_GET:
	*instdata = (PTR)instance;
	break;

    case MO_GETNEXT:
	if( *instance == EOS )
	    ival = 0;

	stat = CVal( instance, &ival ); /* value is the instance */
	if( stat != OK )
	    break;
	
	if( ival > 9 )		/* validate this instance */
	    stat = MO_NO_INSTANCE;
	else if( ++ival > 9 ) /* validate next */
	    stat = MO_NO_NEXT;

	if( stat != OK )
	    break;

	CVla( ival, buf );
	
	/* assumes caller doesn't blast instance before passing
	   it to a get/set method.  Otherwise hard to handle,
	   because we don't want to allocate memory here to
	   be freed in the get or set routine. */

	*instdata = (PTR)instance;
	
	STncpy( instance, buf, linstance );
	instance [ linstance ] = EOS;
	if( STlength( buf ) != STlen ( instance ))
	    stat = MO_INSTANCE_TRUNCATED;

	break;

    default:
	stat = MO_BAD_MSG;
    }
    return( stat );
}
Пример #3
0
static STATUS
my_dynamic_get( i4  offset,
	       i4  objsize,
	       PTR object,
	       i4  luserbuf,
	       char *userbuf )
{
    STATUS stat = OK;
    char *src = (char *)object;
    
    STncpy( userbuf, src, luserbuf );
    userbuf[ luserbuf ] = EOS;
    if( STlength( src ) != STlen( userbuf ))
	stat = MO_VALUE_TRUNCATED;
    return( stat );
}
Пример #4
0
static STATUS
mystrset( i4  offset,
    i4  luserbuf,
    char *userbuf,
    i4  objsize,
    PTR object )
{
    STATUS stat;
    
    STncpy( private_string, userbuf, sizeof( private_string ) );
    private_string[ luserbuf ] = EOS;
    if( STlength( userbuf ) == STlen( private_string ))
	stat = OK;
    else
	stat = MO_VALUE_TRUNCATED;

    return( stat );
}
Пример #5
0
static STATUS
mystrget( i4  offset,
	 i4  objsize,
	 PTR object,
	 i4  luserbuf,
	 char *userbuf )
{
    STATUS stat;
    
    STncpy( userbuf, private_string, luserbuf );
    userbuf[ luserbuf ] = EOS;
    if( STlength( private_string ) == STlen( userbuf ))
	stat = OK;
    else
	stat = MO_VALUE_TRUNCATED;

    return( stat );
}
Пример #6
0
static STATUS
myintget( i4  offset,
	 i4  objsize,
	 PTR object,
	 i4  luserbuf,
	 char *userbuf )
{
    STATUS stat = OK;

    char buf[ 20 ];

    CVla( private_num, buf );
    STncpy( userbuf, buf, luserbuf ) ;
    userbuf[ luserbuf ] = EOS;
    if( STlength( buf ) != STlength( userbuf ) )
	stat = MO_VALUE_TRUNCATED;
    return( stat );
}
Пример #7
0
STATUS
BS_tcp_addrinfo( char *buf, bool outbound, int ip_family, struct addrinfo **aiList )
{
	char	*p;
	char	port_zero[] = "0";
	char	hostname_buf[ MAXHOSTNAME ] = {0};
	char	*hostname = hostname_buf;
	int	status;
	struct addrinfo hints;
#if defined(axp_osf)
        struct addrinfo *aiList4 = NULL;
        struct addrinfo *last_ipv6_record, *ptr;
        bool   no_ipv6_result = FALSE ;
        bool   no_ipv4_result = FALSE ;
#endif
char gai_buf[1024]; 
	/* set defaults */
	MEfill(sizeof(struct addrinfo), 0, &hints);
	hints.ai_family = ip_family;
	hints.ai_socktype = SOCK_STREAM;  
	hints.ai_protocol = IPPROTO_TCP;  
	hints.ai_flags    = outbound ? 0 : AI_PASSIVE;

	/* parse address - look for a ";" */

	for( p = buf; *p; p++ )
	    if( p[0] == ';' )
		break;

	/* get hostname, if present */

	if( *p )
	{
	    if( (p - buf) == 0 )
		hostname = NULL;
	    else
	    {
		/* host;;port */
		STncpy( hostname, buf, p - buf );
		hostname[ p - buf ] = EOS;
	    }
	}
	else
		hostname = NULL;

	/* now get port, if present - allow an extra ; */

	if( p[0] == '\0' )
	    p = buf;
	else if( p[1] == ';' )
	    p = p + 2;
	else
	    p = p + 1;

	if( CMdigit( p ) )
	{
		/* 1234 port number */
		if( !htons( (u_short)atoi( p ) ) && outbound)
		    return BS_NOPORT_ERR;
	}
	else if( *p || outbound )
	{
		return BS_NOPORT_ERR;
	}

	if( STlength( p ) == 0 )   /* Replace empty string for port with "0". */
	    p = port_zero;

	/* no obvious errors */

#if defined(axp_osf)
        if( outbound && (hostname != NULL) ) 
         { 
	   status = getaddrinfo( hostname, p, &hints, aiList);
	   if( status || !(*aiList))
	      return BS_NOHOST_ERR;
         } 
        else 
         { 
           /*
           ** SegV or malloc error occurred on 5.1B with patch kit 6 
           ** if ai_family is AF_UNSPEC in getaddrinfo call.  
           ** So make two calls (first IPv6,then IPv4), after the lists     
           ** are retrieved, merge them into one list. 
           */ 
	   hints.ai_family = AF_INET6;
	   status = getaddrinfo( NULL, p, &hints, aiList );
	   if( status || !( *aiList ))
	      no_ipv6_result = TRUE;    
	   hints.ai_family = AF_INET;
	   status = getaddrinfo( NULL, p, &hints, &aiList4);
	   if( status || !( aiList4 ))
	      no_ipv4_result = TRUE;    
	   if( no_ipv6_result && no_ipv4_result )
	      return BS_NOHOST_ERR;
           if( aiList4 )
            {
             if ( *aiList )   /* merge aiList and aiList4 if not NULL */  
               {
                 for(ptr=*aiList; ptr; ptr=ptr->ai_next)  
                   last_ipv6_record = ptr; 
                 last_ipv6_record->ai_next = aiList4; 
                }
             else  
               *aiList = aiList4; 
            }
         } 

#else  /* if defined(axp_osf) */

	status = getaddrinfo(outbound ? hostname : NULL, p, &hints, aiList);
	if( status || !(*aiList))
	    return BS_NOHOST_ERR;

#endif /* if defined(axp_osf) */ 

	return OK;
}
Пример #8
0
STATUS
BS_tcp_addr( char *buf, bool outbound, struct sockaddr_in *s )
{
	char	*p;
	char	hostname[ MAXHOSTNAME ];
	struct hostent *hp;
	struct hostent host;
	struct hostent *iiCLgethostbyname();
# if defined(i64_hpu)
	struct hostent hostbuf;
# elif defined(POSIX_THREADS) && defined(any_hpux)
	struct hostent_data hostbuf;
# else
	union
	{
# if defined(any_aix)
	    struct hostent_data h;   /* for alignment purposes only */
	    char   buf[sizeof(struct hostent_data)+512]; /* temporary buffer */
# else
	    struct hostent h;   /* for alignment purposes only */
	    char   buf[sizeof(struct hostent)+512]; /* temporary buffer */
# endif
	} hostbuf;
# endif
	int local_errno;

# if defined(POSIX_THREADS) && defined(any_hpux) && !defined(i64_hpu)
	hostbuf.current = NULL;
# endif /* POSIX_THREADS && hp8_us5 */

# if defined(any_aix)
	MEfill( sizeof(hostbuf), 0, &hostbuf );
# endif

	/* set defaults */

	s->sin_family = AF_INET;
	s->sin_addr.s_addr = outbound ? htonl(INADDR_LOOPBACK) : INADDR_ANY;
	s->sin_port = 0;

	/* parse address - look for a ";" */

	for( p = buf; *p; p++ )
	    if( p[0] == ';' )
		break;

	/* get hostname, if present */

	if( *p )
	{
		/* host;;port */

		STncpy( hostname, buf, p - buf );
		hostname[ p - buf ] = EOS;

		if( ( hp = iiCLgethostbyname( hostname,
					       &host,
					       &hostbuf,
					       sizeof(hostbuf),
					       &local_errno ) ) )
		    MEcopy(hp->h_addr, hp->h_length, (PTR)&s->sin_addr);
		else 
		    if( CMdigit( hostname ) )
		    {
			/* host id, e.g. 128.0.2.1 */

			if( !( s->sin_addr.s_addr = inet_addr( hostname ) ) )
				return BS_NOHOST_ERR;
		    }
		    else 
		    {
			return BS_NOHOST_ERR;
		    }
	}

	/* now get port, if present - allow an extra ; */

	if( p[0] == '\0' )
	    p = buf;
	else if( p[1] == ';' )
	    p = p + 2;
	else
	    p = p + 1;

	if( CMdigit( p ) )
	{
		/* 1234 port number */
		s->sin_port = htons( (u_short)atoi( p ) );
	}
	else if( *p || outbound )
	{
		return BS_NOPORT_ERR;
	}

	/* no obvious errors */

	return OK;
}
Пример #9
0
STATUS
dmf_get_srs(
    DB_SPATIAL_REF_SYS *db_srs,
    i4 *errcode)
{
	DMT_SHW_CB srs_show;
	DMT_TBL_ENTRY srs_table;
	STATUS status;
    DML_SCB	*scb;
    CS_SID sid;
    DMT_CB dmt_cb;
    DMR_CB dmr_cb;
    DMR_ATTR_ENTRY key, *kptr = &key;
    SRS_ROW row;

    CSget_sid(&sid);
	scb = GET_DML_SCB(sid);

	/*
	** make sure we are have a transaction
	*/
	if (scb->scb_x_ref_count != 1)
	{
		*errcode = E_AD5603_NO_TRANSACTION;
	    return E_DB_ERROR;
	}

	/*
	 * First we need to grab spatial_ref_sys information
	 */
	MEfill(sizeof(DB_OWN_NAME), ' ', &srs_show.dmt_owner);
	MEfill(sizeof(DB_TAB_NAME), ' ', &srs_show.dmt_name);
	STncpy(srs_show.dmt_name.db_tab_name, "spatial_ref_sys", STlen("spatial_ref_sys"));
	STncpy(srs_show.dmt_owner.db_own_name, "$ingres", STlen("$ingres"));
	srs_show.type = DMT_SH_CB;
	srs_show.length = sizeof(DMT_SHW_CB);
	srs_show.dmt_session_id = sid;
	srs_show.dmt_db_id = (PTR) scb->scb_x_next->xcb_odcb_ptr;
	srs_show.dmt_flags_mask = DMT_M_NAME | DMT_M_TABLE;
	srs_show.dmt_char_array.data_address = (PTR) NULL;
	srs_show.dmt_char_array.data_in_size = 0;
	srs_show.dmt_char_array.data_out_size = 0;
	srs_show.dmt_table.data_address = (PTR) &srs_table;
	srs_show.dmt_table.data_in_size = sizeof(DMT_TBL_ENTRY);
	status = dmt_show(&srs_show);
	if(status != E_DB_OK)
	{
		//something went wrong
		*errcode = E_AD5604_SRS_NONEXISTENT;
		return status;
	}
	/*
	 * Next open the spatial_ref_sys table
	 */
	MEfill(sizeof(DMT_CB), 0, (PTR) &dmt_cb);
	dmt_cb.type = DMT_TABLE_CB;
	dmt_cb.length = sizeof(DMT_CB);
	dmt_cb.dmt_db_id = (PTR) scb->scb_x_next->xcb_odcb_ptr;
	STRUCT_ASSIGN_MACRO(srs_table.tbl_id, dmt_cb.dmt_id);
	dmt_cb.dmt_flags_mask = 0;
	dmt_cb.dmt_lock_mode = DMT_IS;
	dmt_cb.dmt_update_mode = DMT_U_DIRECT;
	dmt_cb.dmt_mustlock = FALSE;
	dmt_cb.dmt_access_mode = DMT_A_READ;
	dmt_cb.dmt_char_array.data_in_size = 0;
	dmt_cb.dmt_sequence = 0;
	dmt_cb.dmt_tran_id = (PTR) scb->scb_x_next;
	status = dmt_open(&dmt_cb);
	if (status != E_DB_OK)
	{
		*errcode = E_AD5601_GEOSPATIAL_INTERNAL;
		return status;
	}
	/*
	 * Let's set up for the actual gets
	 */
	dmr_cb.type = DMR_RECORD_CB;
	dmr_cb.length = sizeof(DMR_CB);
	dmr_cb.dmr_access_id = dmt_cb.dmt_record_access_id;
	dmr_cb.dmr_tid = 0;
	dmr_cb.dmr_q_fcn = NULL;
	dmr_cb.dmr_position_type = DMR_QUAL;
	kptr->attr_number = SRS_SRID_COL;
	kptr->attr_operator = DMR_OP_EQ;
	kptr->attr_value = (char *) &db_srs->srs_srid;
	dmr_cb.dmr_attr_desc.ptr_address = (PTR) &kptr;
	dmr_cb.dmr_attr_desc.ptr_in_count = 1;
	dmr_cb.dmr_attr_desc.ptr_size = sizeof (DMR_ATTR_ENTRY);
	dmr_cb.dmr_flags_mask = 0;
	status = dmr_position(&dmr_cb);
	if (status != E_DB_OK)
	{
		if (dmr_cb.error.err_code == E_DM0055_NONEXT)
			*errcode = E_AD5605_INVALID_SRID;
		else
			*errcode = E_AD5601_GEOSPATIAL_INTERNAL;
		dmt_close(&dmt_cb);
		return status;
	}

	dmr_cb.dmr_data.data_in_size = SRS_ROW_SIZE;
	dmr_cb.dmr_data.data_address = row;
	dmr_cb.dmr_flags_mask = DMR_NEXT;
	status = dmr_get(&dmr_cb);
	if (status != E_DB_OK)
	{
		if (dmr_cb.error.err_code == E_DM0055_NONEXT)
		{
			*errcode = E_AD5605_INVALID_SRID;
		}
		else
		{
			*errcode = E_AD5601_GEOSPATIAL_INTERNAL;
		}
		dmt_close(&dmt_cb);
		return status;
	}

	/*
	 * If we get here we retrieved a row yay!
	 */
	MEcopy((row + SRS_AUTH_NAME_OFFSET), sizeof(db_srs->srs_auth_name), db_srs->srs_auth_name);
	db_srs->srs_auth_name[STlen(db_srs->srs_auth_name)] = '\0';
	MEcopy((row + SRS_AUTH_ID_OFFSET), sizeof(i4), &db_srs->srs_auth_id);
	MEcopy((row + SRS_SRTEXT_OFFSET), sizeof(db_srs->srs_srtext), db_srs->srs_srtext);
	db_srs->srs_srtext[STlen(db_srs->srs_srtext)] = '\0';
	MEcopy((row + SRS_PROJ4TEXT_OFFSET), sizeof(db_srs->srs_proj4text), db_srs->srs_proj4text);
	db_srs->srs_proj4text[STlen(db_srs->srs_proj4text)] = '\0';
	/*
	 * Must close the table when we're done
	 */
	status = dmt_close(&dmt_cb);
	if(status != E_DB_OK)
	{
		/* close failed?? */
		*errcode = E_AD5601_GEOSPATIAL_INTERNAL;
		return status;
	}
	return E_DB_OK;
}
Пример #10
0
/*
** Name: psq_store_text - store query text in a contiguous block of QSF memory
**
** Description:
**	Copy contents of a query text chain (prepended, if necessary with RANGE
**	statements) into a contiguous block of QSF memory.  Caller may specify
**	that the text be stored in DB_TEXT_STRING format by setting
**	return_db_text_string to TRUE; otherwise the function will return a i4
**	followed by query text.
**
** Input:
**	rngtab			if non-NULL, range statements will be
**				generated for all entries of the range table
**				that are active (pss_used && pss_rgno >= 0);
**				should be non-NULL only for QUEL queries
**      header			Pointer to chain header
**	mstream			Pointer to opened memory stream
**	return_db_text_string	if TRUE, function will store text in
**				DB_TEXT_STRING format; otherwise it will store
**				it a a i4  (length) followed by text
**
** Output:
**	result			query text in specified format
**	err_blk			Filled in if an error happens
**
** Side efects:
**	allocates memory
**
** Returns:
**	E_DB_{OK,ERROR}
**
** History:
**	09-jan-93 (andre)
**	    written
**	29-jul-2001 (toumi01)
**	    problem found doing i64_aix port:
**	    (u_char *)'\n' should be (uchar)'\n'
**	    (u_char *)'\0' should be (uchar)'\0'
**      26-Oct-2009 (coomi01) b122714
**          Move psq_store_text() declarator to pshparse.h and make it public here.
**	24-Jun-2010 (kschendel) b123775
**	    Correct a call to trim-whitespace.
*/
DB_STATUS
psq_store_text(
	PSS_SESBLK	    *sess_cb,
	PSS_USRRANGE	    *rngtab,
	PTR		    header,
	PSF_MSTREAM	    *mstream,
	PTR		    *result,
	bool		    return_db_text_string,
	DB_ERROR	    *err_blk)
{
    DB_STATUS		status;
    i4			i;
    PSQ_THEAD		*hp = (PSQ_THEAD *) header;
    i4			size = hp->psq_tsize;
    PSQ_TEXT		*tp;
    PSS_RNGTAB		*rngvar;
    u_char		*out;
    
    if (rngtab)
    {
	/*
	** allocate enough space for range statements. each range statement
	** looks like range of 'rngname' is 'tabname'\n.
	** Thus, max space is 14+2*DB_MAX_NAME.
	*/
	for (i = 0, rngvar = rngtab->pss_rngtab; i < PST_NUMVARS; i++, rngvar++)
	{
	    /* Only look at range vars that are being used */
	    if (rngvar->pss_used && rngvar->pss_rgno >= 0)
	    {
		size += (  14   /* "range of  is \n" */
			 + psf_trmwhite(DB_TAB_MAXNAME, rngvar->pss_rgname)
			 + psf_trmwhite(sizeof(DB_TAB_NAME),
			       (char *) &rngvar->pss_tabname));
	    }
	}
    }
    
    if (return_db_text_string)
    {
	DB_TEXT_STRING	    *str;

	status = psf_malloc(sess_cb, mstream, size + sizeof(*str) - sizeof(u_char),
	    result, err_blk);
	if (status != E_DB_OK)
	    return (status);

	str = (DB_TEXT_STRING *) *result;

	/*
	** store the total length of query text 
	*/
	str->db_t_count = size;

	out = str->db_t_text;

    }
    else
    {
	/* Allocate a piece large enough for all the text + a i4  (count) */
	status = psf_malloc(sess_cb, mstream, size + sizeof(i4), result, err_blk);
	if (status != E_DB_OK)
	    return (status);

	out = (u_char *) *result;
	
	/* Copy the length into the buffer */
	MEcopy((char *) &size, sizeof(size), (char *) out);

	out += sizeof(size);
    }
    
    /* Copy the pieces into the buffer; first put the range statements */
    if (rngtab)
    {
	for (i = 0, rngvar = rngtab->pss_rngtab; i < PST_NUMVARS; i++, rngvar++)
	{
	    /* Only look at range vars that are being used */
	    if (rngvar->pss_used && rngvar->pss_rgno >= 0)
	    {
		i4 plen;

		STncpy( (char *)out, "range of ", 9);
		out += 9;

		/* add in range name */
		plen = psf_trmwhite(DB_TAB_MAXNAME, rngvar->pss_rgname);
		STncpy( (char *)out, rngvar->pss_rgname, plen);
		out += plen;

		STncpy( (char *)out, " is ", 4);
		out += 4;

		plen = psf_trmwhite(DB_TAB_MAXNAME, rngvar->pss_tabname.db_tab_name);
		STncpy( (char *)out, (char *)&rngvar->pss_tabname, plen);
		out += plen;

		*out = (u_char)'\n';
		out++;
		*out = (u_char)'\0';
	    }
	}
    }

    for (tp = hp->psq_first; tp != (PSQ_TEXT *) NULL; tp = tp->psq_next)
    {
	MEcopy((char *) tp->psq_tval, tp->psq_psize, (char *) out);
	out += tp->psq_psize;
    }

    return(E_DB_OK);
}
Пример #11
0
STATUS
ERslookup(
    i4		    msg_number,
    CL_ERR_DESC	    *clerror,
    i4		    flags,
    char	    *sqlstate,
    char	    *msg_buf,
    i4		    msg_buf_size,
    i4		    language,
    i4		    *msg_length,
    CL_ERR_DESC	    *err_code,
    i4		    num_param,
    ER_ARGUMENT	    *param )
{
    i4			erindex;	/* index of ERmulti table */
    i4		status;
    i4			length = 0;
    ER_ARGUMENT		*p;
    ER_ARGUMENT		hidden[CLE_INFO_ITEMS];	/* to access info in clerror */
    char		tempbuf[ER_MAX_LEN+ER_MAX_NAME+2];
    i4			templen;
    char		*p_msg_buf;
    char		*p_tempbuf;
    SYSTIME		stime;
    char		langbuf[ER_MAX_LANGSTR];
    EX_CONTEXT		context;
    ER_SEMFUNCS		*sems;

#define			    D_WIDTH	    23
#define			    F_WIDTH	    20
#define			    X_WIDTH	    18


    /*	Validate the parameters. */

    if (msg_buf == 0 || msg_buf_size == 0 || msg_length == 0)
    {
	return (ER_BADPARAM);
    }
    if (language != -1 && ERlangstr(language,langbuf) != OK)
    {
	return (ER_BADLANGUAGE);
    }
 
    if (!(flags & ER_NAMEONLY))
    {
        EXdump(msg_number,0);
    }
 

    /*	Insert timestamp if requested. */

    if (flags & ER_TIMESTAMP)
    {
	if (msg_buf_size < 21)
	{
	    return (ER_TOOSMALL);
	}
	TMnow(&stime);
	TMstr(&stime,msg_buf);

	length = (i4)STlength(msg_buf);	
	msg_buf[length++] = ' ';
    }

    /*
    **    if (clerror && msg_number)
    **        look up msg_number, optional parameters in clerror->moreinfo
    **    else if (clerror)
    **    {
    **        if (clerror->intern)
    **            look up clerror.intern, optional params in clerror->moreinfo
    **        if (clerror->callid)
    **            look up system error message
    **    }
    */
    if (clerror)
    {
	if (msg_number)	/* Look up message after system error */
	{
	    /*
	    ** Set up an ER_ARGUMENT that references system-dependent
	    ** information in `clerror', and point `param' at it.
	    */
	    i4  i;

	    for (i = 0; i < CLE_INFO_ITEMS; ++i)
	    {
	        /* "...all of whose members begin at offset 0..." (K&R) */

	        hidden[i].er_value = (PTR)&clerror->moreinfo[i].data._i4;
	        hidden[i].er_size = clerror->moreinfo[i].size;
	    }

	    param = &hidden[0];
	    num_param = CLE_INFO_ITEMS;
	}
        else		/* retrieve system-dependent error messages */
	{
	    i4	        len;
	    ER_ARGUMENT	argv[3];

	    if (clerror->intern)    /* look up internal CL error */
	    {
	        i4  i;

	        for (i = 0; i < CLE_INFO_ITEMS; ++i)
	        {
	            argv[i].er_value = (PTR)&clerror->moreinfo[i].data._i4;
	            argv[i].er_size = clerror->moreinfo[i].size;
	        }

	        /*
	        ** Don't timestamp on recursive call, since it's been done
	        ** already (if requested).
	        */
	        if ((status = ERslookup((i4) clerror->intern,
		    (CL_ERR_DESC*) NULL, flags & ~ER_TIMESTAMP | ER_TEXTONLY,
		    NULL, &msg_buf[length], msg_buf_size-length, language, &len,
		    err_code, CLE_INFO_ITEMS, argv)) != OK)
	        {
	            return (status);
	        }
	        length += len;

		if (clerror->callid)
		    msg_buf[length++] = '\n';
	    }

	    if (clerror->callid)    /* look up system error message text */
	    {
                DESCRIPTOR	msg_desc;

    	        msg_desc.desc_length = sizeof(tempbuf) - 1;
	        msg_desc.desc_value = tempbuf;
	        if ((status = cer_sysgetmsg(clerror, &len, &msg_desc, err_code))
		    != OK)
	        {
	            return(status);
	        }

	        argv[0].er_size = argv[1].er_size = argv[2].er_size =
		    ER_PTR_ARGUMENT;

	        argv[0].er_value = (PTR)&clerror->errnum;
	        argv[1].er_value = (PTR)ERNAME((i4) clerror->callid);
	        argv[2].er_value = (PTR)tempbuf;

	        if ((status = ERslookup(ER_UNIXERROR, (CL_ERR_DESC*) NULL,
	                flags & ~ER_TIMESTAMP | ER_TEXTONLY, NULL,
			&msg_buf[length], msg_buf_size - length, language,
			&len,err_code, 3, argv))
		    != OK)
	        {
	            return (status);
	        }
	        length += len;
	    }

	    msg_buf[*msg_length = length] = EOS;
	    return (OK);
        }
    }


    /*
    **	Check if error message file is already opened or not yet. 
    **  First see if the language is initialized.  If not, initialize
    **  it and the message files.
    **	If it is already opened, cer_fndindex function returns the index of
    **	ERmulti table that internal language code is parameter 'language'.
    **  If not yet, it returns '-1'.
    */

    if (cer_issem(&sems))
    {
	if (((sems->sem_type & MU_SEM) ?
	    (*sems->er_p_semaphore)(&sems->er_mu_sem) :
	    (*sems->er_p_semaphore)(1, &sems->er_sem)) != OK)
	{
	    sems = NULL;
	}
    }

    if ((erindex = cer_fndindex(language)) == -1)
    {
	if ((status = cer_nxtindex(language,&erindex)) != OK)
	{   /* Error in initializing the language */
	    if (sems)
	    {
		if (sems->sem_type & MU_SEM)
		    _VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem);
		else
		    _VOID_ (*sems->er_v_semaphore)(&sems->er_sem);
	    }
	    return (status);
	}
    }

    /*  If the error message file is not opened, open the message file. */

    if (!cer_isopen(erindex,ER_SLOWSIDE))
    {
        if ((status = cer_sinit(language,msg_number,erindex,err_code)) != OK)
        {
	    if (sems)
	    {
		if (sems->sem_type & MU_SEM)
		    _VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem);
		else
		    _VOID_ (*sems->er_v_semaphore)(&sems->er_sem);
	    }
            return (status);
        }
    }

    /*	If not open then just return. */
    if (!cer_isopen(erindex,ER_SLOWSIDE))
    {
	if (sems)
	{
	    if (sems->sem_type & MU_SEM)
		_VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem);
	    else
		_VOID_ (*sems->er_v_semaphore)(&sems->er_sem);
	}
	/*
	**  As internal file id is '0', openning file will fail.
	**  In her,return status 'ER_BADOPEN' to show open fail.
	*/
	return (ER_BADOPEN);
    }
	
    /*
    **  Search message string from file and set to buffer.
    **	Error status on system call set to 'err_code'.
    */

    status = cer_sstr(msg_number, sqlstate, tempbuf,
			msg_buf_size - length, erindex, err_code,
			flags & ER_TEXTONLY? ER_GET : ER_LOOKUP);
    if (sems)
    {
	if (sems->sem_type & MU_SEM)
	    _VOID_ (*sems->er_v_semaphore)(&sems->er_mu_sem);
	else
	    _VOID_ (*sems->er_v_semaphore)(&sems->er_sem);
    }

    if (status != OK)
    {
	return (status);
    }

    /*
    **	Format the text with parameters into the callers buffer.
    **  The message is truncated if it will not fit.
    */

    /*  Insert part of name from temporary buffer to buffer */

    status = OK;
    templen = (i4)STlength(tempbuf);
    p_msg_buf = &msg_buf[length];
    p_tempbuf = tempbuf;
    if (!(flags & ER_TEXTONLY))
    {
        while(*p_tempbuf != '\t')
        {
	    CMcpyinc(p_tempbuf,p_msg_buf);
        }
        CMcpyinc(p_tempbuf,p_msg_buf);
    }
    

    /* ============================================ */
    /* Copy text to message substituting arguments. */
    /* -------------------------------------------- */
    /* (But first, declare an exception handler to  */
    /*  catch bad params that may access violate.)  */
    /* ============================================ */

    if (EXdeclare(er_exhandler, &context))
    {
	u_i4	res_len;
	u_i4	bytes_left_in_buf;

	bytes_left_in_buf = (u_i4)(msg_buf_size - (p_msg_buf - msg_buf));
	res_len = STlen( STncpy(p_msg_buf,
   ERx("*** ERslookup() ERROR: Missing or bad parameter for this message. ***"),
	bytes_left_in_buf ));
	p_msg_buf[ bytes_left_in_buf - 1 ] = EOS;
	p_msg_buf += res_len;
	*msg_length = (i4)(p_msg_buf - msg_buf);
	EXdelete();
	return (OK);
    }


    for( ;p_tempbuf - tempbuf < templen; CMnext(p_tempbuf))
    {
        long		number;
        u_long    	unumber;
        double		fnumber;
	i4		i;
	i4		pnum;
 
	if ( (*p_tempbuf != '%') || (flags & ER_NOPARAM) )
	{
	    if ((p_msg_buf - msg_buf) >= msg_buf_size)
		break;
	    CMcpychar(p_tempbuf,p_msg_buf);
	    CMnext(p_msg_buf);
	    continue;
	}
	if (p_tempbuf - tempbuf + 2 >= templen)
	    continue;
	CMnext(p_tempbuf);
	if (*p_tempbuf == '!')
	{
	    if ((p_msg_buf - msg_buf) + 3 >= msg_buf_size)
		continue;
	    CMcpychar(ERx("\r"),p_msg_buf);
	    CMnext(p_msg_buf);
	    CMcpychar(ERx("\n"),p_msg_buf);
	    CMnext(p_msg_buf);
	    CMcpychar(ERx("\t"),p_msg_buf);
	    CMnext(p_msg_buf);
	    continue;
	}
	/*
	** Only works for up to 10 parameters, and makes character set
	** assumptions - should be fixed.
	*/
	if ( *p_tempbuf < '0' || *p_tempbuf > '9' )
	{
	    /* treat any other character as a literal */
	    if ((p_msg_buf - msg_buf) >= msg_buf_size)
		break;
	    if ( *p_tempbuf != '%' )
	    {
	        CMcpychar("%",p_msg_buf);
	        CMnext(p_msg_buf);
	    }
	    CMcpychar(p_tempbuf,p_msg_buf);
	    CMnext(p_msg_buf);
	    continue;
	}
	pnum = *p_tempbuf - '0';
	if (pnum >= num_param)
	{
		EXdelete();
		return(ER_BADPARAM);
	}
	p = &param[pnum];
	CMnext(p_tempbuf);
	switch (*p_tempbuf)
	{
	  case 'd':
	    /* Convert an integer into the buffer with width D_WIDTH */

	    if (p->er_size == ER_PTR_ARGUMENT) /* this is ptr to i4 */
		number = *(i4 *)p->er_value;
	    else if (p->er_size == 0)   /* this is a i4 */
		number = (i4)(SCALARP)p->er_value;
	    else if (p->er_size == 1)
		number = *(i1 *)p->er_value;
	    else if (p->er_size == 2)
		number = *(i2 *)p->er_value;
	    else if (p->er_size == 4)
		number = *(i4 *)p->er_value;
	    else if (p->er_size == 8)
		number = *(i8 *)p->er_value;
	    else
		continue;

	    if (p_msg_buf - msg_buf + D_WIDTH >= msg_buf_size)
	        continue;

	    if (p->er_size == 8)
	    {
	        CVla8(number, p_msg_buf);
	    }
	    else
	    {
	        CVla((i4)number, p_msg_buf);
	    }
	    while (*p_msg_buf)
		CMnext(p_msg_buf);
	    continue;

	  case 'u':
	    /* Convert an integer into the buffer with width D_WIDTH */

	    if (p->er_size == ER_PTR_ARGUMENT) /* this is ptr to u_i4 */
		number = *(u_i4 *)p->er_value;
	    else if (p->er_size == 0)   /* this is a u_i4 */
		number = (u_i4)(SCALARP)p->er_value;
	    else if (p->er_size == 1)
		number = *(u_i1 *)p->er_value;
	    else if (p->er_size == 2)
		number = *(u_i2 *)p->er_value;
	    else if (p->er_size == 4)
		number = *(u_i4 *)p->er_value;
	    else if (p->er_size == 8)
		number = *(u_i8 *)p->er_value;
	    else
		continue;

	    if (p_msg_buf - msg_buf + D_WIDTH >= msg_buf_size)
	        continue;

	    if (p->er_size == 8)
	    {
	        CVula8(number, p_msg_buf);
	    }
	    else
	    {
	        CVula((u_i4)number, p_msg_buf);
	    }
	    while (*p_msg_buf)
		CMnext(p_msg_buf);
	    continue;

	  case 'f':
	  {
	    i2	    res_width;

	    /* Convert a float into the buffer with width F_WIDTH */

	    if (p->er_size == ER_PTR_ARGUMENT) /* Pointer to a double */
		fnumber = *(double *)p->er_value;
	    else if (p->er_size == 4)
		fnumber = *(f4 *)p->er_value;
	    else if (p->er_size == 8)
		fnumber = *(f8 *)p->er_value;
	    else
		continue;

	    if (p_msg_buf - msg_buf + F_WIDTH >= msg_buf_size)
		continue;

	    /* Always convert to 'e' format. */

	    CVfa(fnumber, (i4) 20, (i4) 5, 'e', '.', p_msg_buf, &res_width);
	    p_msg_buf += F_WIDTH;
	    continue;
	  }
	  case 'c':
	    /* Convert a character array into buffer. */

	    if (p->er_value == 0)
		p->er_value = (PTR)ERx("<missing>");
	    if ((p->er_size == 0) || (p->er_size == ER_PTR_ARGUMENT))
	    {
		for (i = 0; ((char *)p->er_value)[i]; i++)
		    ;
		p->er_size = i;
	    }
             
	    if (p_msg_buf - msg_buf + p->er_size >= msg_buf_size)
		continue;

	    if (p->er_size > msg_buf_size - (p_msg_buf - msg_buf))
		p->er_size = (i4)(msg_buf_size - (p_msg_buf - msg_buf));
/*	    p->er_size=STtrmwhite(p_msg_buf);*/
	    MEcopy(p->er_value, p->er_size, p_msg_buf);
	    p->er_size = (i4)STtrmnwhite(p_msg_buf, p->er_size);
	    p_msg_buf += p->er_size;
	    continue;

	  case 'x':
	    /* Convert an integer into the buffer with width D_WIDTH */

	    if (p->er_size == ER_PTR_ARGUMENT)
		unumber = *(u_i4 *)p->er_value;
	    else if (p->er_size == 0)
		unumber = (u_i4)(SCALARP)p->er_value;
	    else if (p->er_size == 1)
		unumber = *(u_i1 *)p->er_value;
	    else if (p->er_size == 2)
		unumber = *(u_i2 *)p->er_value;
	    else if (p->er_size == 4)
		unumber = *(u_i4 *)p->er_value;
	    else if (p->er_size == 8)
		unumber = *(u_i8 *)p->er_value;

	    if (p_msg_buf - msg_buf + X_WIDTH >= msg_buf_size)
		continue;

	    for (i = 8; --i >= 0; )
	    {
		/* {@fix_me@}
		** This is *NOT* machine independent.  This relys on an
		** ASCII-like character set, where the digits '0'-'9' are
		** contiguous and sequential, and the characters 'A'-'F'
		** are contiguous and sequential.  Both ASCII and EBCDIC
		** happen to be this way.
		*/
		if ((*(p_msg_buf + i) = (unumber & 0x0f) + '0') > '9')
		    *(p_msg_buf + i) += 'A' - '9' - 1;
		unumber >>= 4;
	    }
	    p_msg_buf += 8;
	    continue;

	default:
	    continue;
	}
    }
    *msg_length = (i4)(p_msg_buf - msg_buf);
    *p_msg_buf = EOS;
    EXdelete();
    return (OK);
}
Пример #12
0
i4
main(
i4	argc,
char *	argv[])
{
    char      c='\0';
    char      *tz_file=NULL;
    char      *tz_name=NULL;
    char      *tz_def;
    char      tzname[TM_MAX_TZNAME+1];
    char      tzfile[MAX_LOC+1];
    char      ioptarg[MAX_LOC + 1];
    char      tz_pmvalue[MAX_LOC + 1];
    char      tz_pmname[MAX_LOC + 1];
    char      *p, *ip, *pm_value;
    char      *tm_tztype;
    char      chr='/';
    char      *out_file;
    i4        ioptind=1, i;
    char      *tm_tztime;
    i4        timecnt, tempi, temptype, temptz;
    char      buf[sizeof(TM_TZ_CB)+TM_MAX_TIMECNT*(sizeof(i4)+1)];
    FILE      *fid;
    LOCATION  loc_root, tmp_loc;
    STATUS    status=OK;
    TM_TZ_CB  *tm_tz_cb;
    struct timevect time_v;

    appname = argv[0];

    if( TMtz_getopt(argc, argv, "n:name:f:file", &ioptind, ioptarg, &c) == OK)
    {
	switch (c) 
	{
	  case 'f':
	    tz_file = ioptarg;
	    break;
	  case 'n':
	    tz_name = ioptarg;
	    break;
	  default:
	    break;
	}
    }
    else
    {
	TMtz_usage();
	PCexit(FAIL);
    }

    if( tz_file == NULL)
    {
	if( tz_name == NULL)
	{
	    /* Get II_TIMEZONE_NAME value */
	    NMgtAt(ERx("II_TIMEZONE_NAME"), &tz_def);
	    if (!tz_def || !(*tz_def))
	    {
		SIprintf("%s: %s_TIMEZONE_NAME is not set\n", 
				appname, SystemVarPrefix);
		PCexit(FAIL);
	    }
	    STncpy(tzname, tz_def, TM_MAX_TZNAME);
	    tzname[ TM_MAX_TZNAME ] = EOS;
	}
	else
	{
	    STncpy(tzname, tz_name, TM_MAX_TZNAME);
	    tzname[ TM_MAX_TZNAME ] = EOS;
	}
	PMinit();	
	if( PMload( NULL, (PM_ERR_FUNC *)NULL) != OK)
	{
	    SIprintf("%s: Error loading PM %s_CONFIG/config.dat file\n", 
			appname, SystemVarPrefix);
	    PCexit(FAIL);	    
	}
	/* Get timezone file name */
	STprintf( tz_pmname, ERx("%s.*.tz.%s"), SystemCfgPrefix, tzname);
	if( PMget( tz_pmname, &pm_value) != OK)
	{
	    SIprintf("%s: Error locating %s in PM config.dat file\n",
		     appname, tz_pmname);
    	    PCexit(FAIL);	    
	}
	do
	{
	    if((status = NMloc(FILES, PATH, ERx("zoneinfo"), &loc_root)) != OK)
		break;
#if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64)
	    if((status = LOfaddpath(&loc_root, ERx("lp64"), &loc_root)) != OK)
	        break;
#endif
#if defined(conf_BUILD_ARCH_64_32) && defined(BUILD_ARCH32)
	    {
	        /*
	        ** Reverse hybrid support must be available in ALL
	        ** 32bit binaries
	        */
	        char    *rhbsup;
	        NMgtAt("II_LP32_ENABLED", &rhbsup);
	        if ( (rhbsup && *rhbsup) &&
	       ( !(STbcompare(rhbsup, 0, "ON", 0, TRUE)) ||
	         !(STbcompare(rhbsup, 0, "TRUE", 0, TRUE))))
	            status = LOfaddpath(&loc_root, "lp32", &loc_root);
	    }
#endif /* reverse hybrid */

	    STcopy( pm_value, tz_pmvalue);

	    /*
	     ** Compose the directory path 
	     */
	    for( p = tz_pmvalue, ip = tz_pmvalue; 
		(p = STchr(ip, chr)) != NULL;)
	    {
		*p = EOS;
		if((status = LOfaddpath(&loc_root, ip, &loc_root)) != OK)
		    break;
		ip = CMnext(p);
	    }
	   
	    /* 
	    ** Add file name to the directory path
	    */
	    if((status = LOfroms(FILENAME, ip, &tmp_loc)) != OK)
		break;
	    status = LOstfile( &tmp_loc, &loc_root);
	} while( FALSE);

	if( status != OK)
	{
	    SIprintf("%s: Error composing timezone file name for %s\n",
		     appname, tz_pmvalue);
	    PCexit(FAIL);
	}
    }
    else
    {
	STcopy("<unknown>", tzname);
	STncpy( tzfile, tz_file, MAX_LOC);
	tzfile[ MAX_LOC ] = EOS;
	if( LOfroms(FILENAME&PATH, tzfile, &loc_root) != OK)
	{
	    SIprintf("%s: Error composing timezone file name for %s\n",
		     appname, tz_pmvalue);
	    PCexit(FAIL);
	}
    }

    /*
    ** Now open the timezone information file
    */
    do
    {
	if((status = SIfopen( &loc_root, ERx("r"), SI_VAR, sizeof buf, &fid)) 
	             != OK)
	    break;
	status = SIread(fid, sizeof buf, &i, buf);
	status = SIclose(fid);
    } while(FALSE);

    if( status != OK)
    {
	LOtos( &loc_root, &out_file);
	SIprintf("%s: Error opening %s for timezone %s\n", 
		 appname, out_file, tzname);
	PCexit(FAIL);
    }

    tm_tz_cb = (TM_TZ_CB *)&buf;
    I4ASSIGN_MACRO( tm_tz_cb->timecnt, timecnt);

    /* Make sure the input file has correct file size */
    if( timecnt > TM_MAX_TIMECNT || timecnt < 0
        || i != sizeof(TM_TZ_CB) + timecnt*(sizeof(i4)+1))
    {
	LOtos( &loc_root, &out_file);
	SIprintf(
	  "%s: Invalid file format for timezone file %s for timezone %s\n",
          appname, out_file, tzname);
	SIprintf(
	  "         File size: %d, Expected file size: %d, time periods: %d\n",
	  i, sizeof(TM_TZ_CB) + timecnt*(sizeof(i4)+1), 
	  timecnt);
	PCexit(FAIL);
    }

    /* Now we are all set to display the content of timezone information file */
    LOtos( &loc_root, &out_file);    
    SIprintf("\n\n");
    SIprintf("timezone name:     %s\n", tzname);
    SIprintf("timezone file:     %s\n", out_file);    
    SIprintf("-------------------------------------");
    SIprintf("-------------------------------------\n");

    if(timecnt == 0)
    {
	I4ASSIGN_MACRO( tm_tz_cb->tzinfo[0].gmtoff, tempi);
	SIprintf("     Fixed GMT offset (secs): %d\n", tempi);      
    }
    else
    {
	SIprintf("\tPeriod Begin");
	SIprintf("\t\tGMT offset\n");
	SIprintf("\t(YYYY_MM_DD HH:MM)");
	SIprintf("\t(Minute)\n\n");
	tm_tztype = buf + sizeof(TM_TZ_CB);
	tm_tztime = tm_tztype + timecnt;
	i=0;
	while( i < timecnt)
	{
	    I4ASSIGN_MACRO( *tm_tztime, tempi);
	    /* Adjust for timezone */
	    if( i == 0)
		temptype = (i4)tm_tztype[i+1];
	    else
		temptype = (i4)tm_tztype[i-1];

	    I4ASSIGN_MACRO( tm_tz_cb->tzinfo[temptype].gmtoff, temptz);
	    /* Get real timezone */
	    tempi += temptz;
	    temptype = (i4)tm_tztype[i];
	    I4ASSIGN_MACRO( tm_tz_cb->tzinfo[temptype].gmtoff, temptz);
	    TMtz_cvtime( tempi, &time_v);
	    SIprintf("\t%04d_%02d_%02d %02d:%02d\t%d\t%s\n", 
		     time_v.tm_year+1900,
		     time_v.tm_mon+1, 
		     time_v.tm_mday,
		     time_v.tm_hour,
		     time_v.tm_min,
		     temptz/60,
		     tm_tz_cb->tzlabel + tm_tz_cb->tzinfo[temptype].abbrind);  
	    tm_tztime += sizeof(i4);
	    i++;
	}
    }
    PCexit(OK);
}