static void map_funny(char *str) { register char *from = str; register char *to = str; /* ** Fix 9005: using wrong test, wasn't mapping Kanji chars, so VMS ** filenames were bad. ** WARNING: this means we won't support Kanji filenames! ** Also, this doesn't solve the problem of 8-bit chars in the ** European character sets. We need a CMlegal_filename_char ** routine. */ /* map any funny bytes to underscores. */ while (*from != EOS) { i4 cnt = CMbytecnt(from); if ( (!CMalpha(from) && !CMdigit(from)) || CMdbl1st(from) ) *to++ = '_'; else *to++ = *from; from += cnt; } *to = EOS; }
/* Name: adu_csnormalize - Normalizes a platform characterset ** string in the alias table or as obtained ** by CM_getcharset. ** Description: ** ** As per the Unicode technical report UTR22. Ref: ** http://www.unicode.org/reports/tr22/ section 1.4, recommended ** method to compare the alias values in an alias table to a character ** set is to normalize the string in following manner. ** ** 1. Delete all characters except a-z, A-Z, and 0-9. ** 2. Map uppercase A-Z to the corresponding lowercase a-z. ** 3. From left to right, delete each 0 that is not preceded by a digit. ** ** For example, the following names should match: "UTF-8", "utf8", ** "u.t.f-008", but not "utf-80" or "ut8". ** ** Input: ** instring - Unnormalized converter name string. ** ** Output: ** instring - Normalized converter name string. ** ** History: ** 23-Jan-2004 (gupsh01) ** Added. */ void adu_csnormalize( char *instring, i4 inlength, char *outstring) { char *iptr = instring; char *endinput = instring + inlength; char *optr = outstring; char nopreceding = '0'; while (iptr < endinput) { if (CMdigit(iptr) || CMalpha(iptr)) { if (CMalpha(iptr)) nopreceding = *iptr; else nopreceding = '0'; CMtolower(iptr,iptr); if (nopreceding != '0'&& *iptr == '0') { *iptr++; continue; } CMcpyinc(iptr, optr); } else iptr++; } *optr = '\0'; }
/* ** Name: check_path_chars - test path characters are supported. ** ** Description: ** Test that the characters in the path are permitted. ** ** Inputs: ** loc Pointer to location structure containing path. ** ** Outputs: ** status More detailed error code for failure. ** ** Returns: ** result OK No invalid characters found. ** FAIL Invalid characters found in path. ** ** History: ** 14-Feb-2005 (fanra01) ** Create to replace call to LOisvalid. ** 03-Jun-2005 (drivi01) ** Replaced Window's portion of check_path_chars ** with LOisvalid. ** 11-Jul-2005 (fanra01) ** Add status output. */ static i4 check_path_chars( LOCATION* loc, STATUS* status ) { i4 result = OK; char dev[MAX_LOC]; char path[MAX_LOC]; char file[MAX_LOC]; char ext[MAX_LOC]; char vers[MAX_LOC]; char *p; # if defined(NT_GENERIC) if (!LOisvalid( loc, &result )) { if (status != NULL) { *status = result; } return FAIL; } # else /* NT_GENERIC */ if (LOdetail( loc, dev, path, file, ext, vers ) != OK) return FAIL; for (p = path; *p != EOS; CMnext(p)) { if (!(CMalpha(p) || CMdigit(p) || CMcmpnocase(p, PATH_SEPARATOR) || '_' || *p == ' ')) return FAIL; } for (p = file; *p != EOS; CMnext(p)) { if (!(CMalpha(p) || CMdigit(p) || *p == '_' || *p == ' ')) return FAIL; } for (p = ext; *p != EOS; CMnext(p)) { if (!(CMalpha(p) || CMdigit(p) || *p == '_' || *p == ' ')) return FAIL; } # endif /* NT_GENERIC */ return(result); }
STATUS MO_class_get(i4 offset, i4 objsize, PTR object, i4 luserbuf, char *userbuf) { MO_CLASS *cp = (MO_CLASS *)object; char *src; if( CMdigit( (char *)cp->node.key ) ) src = cp->twin->node.key; else src = cp->node.key; return( MOstrout( MO_VALUE_TRUNCATED, src, luserbuf, userbuf ) ); }
STATUS CVaptr( char *str, PTR *ptrp ) { SIZE_TYPE num; /* presumed to be 64 bits on 64 bit machine */ PTR ptr; char a; char tmp_buf[3]; num = 0; /* skip leading blanks */ for (; *str == ' '; str++) ; /* at this point everything should be 0-9 */ while (*str) { CMtolower(str, tmp_buf); if (CMdigit(tmp_buf)) { if ( num > ((SIZE_TYPE)~0/10) ) return(CV_OVERFLOW); num = num * 10 + (*str - '0'); } else { return (CV_SYNTAX); } str++; } /* Done with number, better be EOS or all blanks from here */ while (a = *str++) if (a != ' ') /* syntax error */ return (CV_SYNTAX); *ptrp = (PTR)num; return (OK); }
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; }
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; }
/* ** Name: GCwintcp_addr ** Description: ** Takes a node and port name and translates them this into ** a sockaddr structure suitable for appropriate winsock call. ** returns OK or FAIL. puts a character string representation ** into port_name. ** History: ** 03-dec-93 (edg) ** Original. ** 30-jun-2000 (somsa01) ** Update subport number after success. ** 30-aug-2001 (rodjo04) Bug 105650 ** The machine name may have leading digits. We must see if this is ** a valid name before we can assume that this is an IP address. ** 09-feb-2004 (somsa01) ** If the port ID that is passed in seems to be a valid port ** number, use it as is. */ STATUS GCwintcp_addr( char *node, char *port, struct sockaddr_in *ws_addr, char *port_name ) { struct hostent *host_ent; char *p = STindex(port, "+", 0); if ( node == NULL ) { /* ** local listen address, use INADDR_ANY and subport if applicable. */ if (CMdigit(port) && p == NULL) STcopy(port, port_name); else { if ( GCwintcp_port(port, sbprt, port_name) != OK ) return FAIL; if (sbprt && p == NULL) STprintf(port, "%s%d", port, sbprt); sbprt++; } ws_addr->sin_addr.s_addr = INADDR_ANY; } else { /* check for host id, e.g. 128.0.2.1 */ if (CMdigit(node)) { /* Host name might have leading digits or could be the ** IP address. Call gethostbyname() anyway. If it is a name, ** we will get a pointer to the structure. If its an IP (in ** IP format) then a structure will be returned even if the ** IP is not 'alive'. If the IP is not alive, it will fail ** later. */ if (host_ent = gethostbyname(node)) ws_addr->sin_addr.s_addr = *(u_long *) host_ent->h_addr; else { if (!(ws_addr->sin_addr.s_addr = inet_addr(node))) { return FAIL; } } } else { if (!(host_ent = gethostbyname(node))) { return FAIL; } ws_addr->sin_addr.s_addr = *(u_long *) host_ent->h_addr; } if ( GCwintcp_port(port, 0, port_name) != OK ) return FAIL; } ws_addr->sin_port = (u_short)htons( (u_short)atoi(port_name)); ws_addr->sin_family = AF_INET; return OK; }
STATUS MOattach( i4 flags, char *classid, char *instance, PTR idata ) { MO_INSTANCE *ip; MO_CLASS *cp; STATUS stat; stat = OK; if( MO_disabled ) return( stat ); MO_once(); stat = MO_mutex(); if( stat == OK ) /* got mutex */ { do { if( stat != OK ) break; MO_nattach++; # ifdef xDEBUG SIprintf("attach %s:%s object %p\n", classid, instance, idata ); # endif /* check for special error cases */ ip = MO_getinstance( classid, instance ); if( ip != NULL ) { stat = MO_ALREADY_ATTACHED; break; } /* Get class, error if missing */ if( OK != MO_getclass( classid, &cp ) ) { stat = MO_NO_CLASSID; break; } /* Release mutex to prevent deadlock in MO_alloc call */ (VOID) MO_unmutex(); ip = (MO_INSTANCE *)MO_alloc( sizeof(*ip), &stat ); stat = MO_mutex(); if( NULL == ip ) break; ip->classdef = cp; ip->iflags = flags; if( (flags & MO_INSTANCE_VAR) == 0 ) { ip->instance = instance; } else { ip->instance = MO_defstring( instance, &stat ); if( ip->instance == NULL ) { MO_free( (PTR)ip, sizeof(*ip) ); break; } } ip->idata = idata; ip->node.key = (PTR)ip; (VOID) SPenq( &ip->node, MO_instances ); } while( FALSE ); (VOID) MO_unmutex(); /* Attach twin if needed */ if( stat == OK && cp->twin != NULL && !CMdigit( (char *)cp->node.key ) ) stat = MOattach( flags, cp->twin->node.key, instance, idata ); } # if xDEBUG if( stat != OK ) TRdisplay("attach (%s:%s) failed status %d\n", classid, instance, stat ); # endif if( stat == OK ) { if ( (stat = MO_mutex()) == OK) { (VOID) MO_tell_class( cp, instance, (char *)NULL, MO_ATTACH ); MO_unmutex (); } } return( stat ); }
i4 yylex() { bool pattern; bool component; bool keyword; char *keyhead; char yytext[ SI_MAX_TXT_REC + 1 ]; i4 yyleng; /* skip whitespace and comments */ while( CMwhite( yyp ) || *yyp == EOS || *yyp == '-' ) { /* check for comment */ if( *yyp == '-' ) { if( STbcompare( yyp, 2, ERx( "--" ), 2, FALSE ) == 0 ) { while( *yyp != EOS ) CMnext( yyp ); } else break; } if( *yyp == EOS ) { if( SIgetrec( yybuf, sizeof( yybuf ), yyin ) != OK && yywrap() ) { return( 0 ); } else { yyp = yybuf; ++yylineno; } } else CMnext( yyp ); } /* check for a SYMBOL, PATTERN or keyword */ yyleng = 0; pattern = FALSE; keyword = TRUE; keyhead = yyp; while( CMalpha( yyp ) || *yyp == '%' || *yyp == '$' || *yyp == '*' ) { /* check for component of legal SYMBOL or PATTERN */ component = FALSE; /* check for single-character component */ switch( *yyp ) { case '%': pattern = TRUE; case '*': case '$': component = TRUE; ++yyleng; CMnext( yyp ); if( *yyp == '.' ) { ++yyleng; CMnext( yyp ); keyword = FALSE; continue; } else if( CMalpha( yyp ) ) yyerror(); continue; } while( CMalpha( yyp ) || CMdigit( yyp ) || *yyp == '_' || *yyp == '-' ) { ++yyleng; CMnext( yyp ); component = TRUE; } if( component ) { if( *yyp == '.' ) { ++yyleng; CMnext( yyp ); keyword = FALSE; continue; } continue; } } /* check for uneaten '.' */ if( *yyp == '.' ) yyerror(); if( yyleng > 0 ) { /* A keyword, SYMBOL or PATTERN was scanned */ char *p; i4 i; /* put NULL-terminated copy in yytext */ STlcopy( keyhead, yytext, yyleng ); for( p = yytext, i = 0; i <= yyleng; CMnext( p ), i++ ); *p = EOS; /* check for keywords */ if( CMalpha( keyhead) && keyword ) { if( STequal( ERx( "IF" ), yytext ) != 0 ) return( IF ); if( STequal( ERx( "ELSE" ), yytext ) != 0 ) return( ELSE ); if( STequal( ERx( "ELSEIF" ), yytext ) != 0 ) return( ELSEIF ); if( STequal( ERx( "ENDIF" ), yytext ) != 0 ) return( ENDIF ); if( STequal( ERx( "MIN" ), yytext ) != 0 ) return( MIN ); if( STequal( ERx( "MAX" ), yytext ) != 0 ) return( MAX ); if( STequal( ERx( "VALID" ), yytext ) != 0 ) return( VALID ); if( STequal( ERx( "PRIME" ), yytext ) != 0 ) return( PRIME ); if( STequal( ERx( "SIGNED_INT" ), yytext ) != 0 ) return( SIGNED_INT ); if( STequal( ERx( "DECIMAL" ), yytext ) != 0 ) return( DECIMAL ); if( STequal( ERx( "SIZETYPE" ), yytext ) != 0 ) return( SIZETYPE ); if( STequal( ERx( "POWER2" ), yytext ) != 0 ) return( POWER2 ); if( STequal( ERx( "REQUIRES" ), yytext ) != 0 ) return( REQUIRES ); if( STequal( ERx( "UNDEFINED" ), yytext ) != 0 ) return( UNDEFINED ); if( STequal( ERx( "SUM" ), yytext ) != 0 ) { yylval.integer = SUM; return( SUM ); } if( STequal( ERx( "ON" ), yytext ) != 0 ) { yylval.real = 1; return( BOOL_CON ); } if( STequal( ERx( "OFF" ), yytext ) != 0 ) { yylval.real = 0; return( BOOL_CON ); } if( STequal( ERx( "IS" ), yytext ) != 0 ) { yylval.string = STalloc( yytext ); return( COMPARE_OP ); } if( STequal( ERx( "DIRECTORY" ), yytext ) != 0 ) return( DIRECTORY ); if( STequal( ERx( "FILE" ), yytext ) != 0 ) return( FILESPEC ); } /* valid SYMBOL or PATTERN */ yylval.string = STalloc( yytext ); if( pattern ) return( PATTERN ); /* don't accept a single '*' as SYMBOL */ if( yyleng != 1 || *yytext != '*' ) return( SYMBOL ); /* push '*' back onto the input stream */ CMprev( yyp, yybuf ); } /* check for EXEC_TEXT, STR_CON, or EXEC_TEXT_STR */ if( *yyp == '`' || *yyp == '"' ) { int exec_str = 0; char *initstr = yyp; char *p = yyp, *text, *yyprev; if ( *yyp == '"' ) { CMnext( yyp ); if ( *yyp == '`' ) { CMnext( p ); exec_str = 1; } else yyp = p; } for( yyleng = 0, CMnext( yyp ), yyprev = ERx( "" ); *yyp != *p || *yyprev == '\\'; yyprev = ( *yyprev == EOS ) ? yyp : CMnext( yyprev ), CMnext( yyp ), ++yyleng ) { if( *yyp == *p && *yyprev == '\\' ) { /* remove escape character */ char *p1, *p2; for( p1 = p2 = yyprev, CMprev( p1, p ); p1 >= p; CMprev( p1, p ), CMprev( p2, p ) ) { CMcpychar( p1, p2 ); } --yyleng; CMnext( p ); } if( *yyp == EOS ) yyerror(); } CMnext( yyp ); if ( exec_str ) { if ( *yyp == '"' ) CMnext( yyp ); else { /* keep scanning to final '"' */ p = initstr; exec_str = 0; yyleng++; for( ; *yyp != *p || *yyprev == '\\'; yyprev = ( *yyprev == EOS ) ? yyp : CMnext( yyprev ), CMnext( yyp ), ++yyleng ) { if( *yyp == EOS ) yyerror(); } } } text = p; CMnext( text ); STlcopy( text, yytext, yyleng ); yytext[ yyleng ] = EOS; yylval.string = STalloc( yytext ); if( *p == '`' ) { if ( exec_str ) return( EXEC_TEXT_STR ); return( EXEC_TEXT ); } return( STR_CON ); } /* check for NUM_CON */ yyleng = 0; if( *yyp == '-' || CMdigit( yyp ) ) { f8 factor; char *p = yyp; if( *yyp == '-' ) { ++yyleng; factor = -1; CMnext( yyp ); } else factor = 1; if( !CMdigit( yyp ) ) CMprev( yyp, yybuf ); else { if( *yyp == '-' ) { CMnext( yyp ); } else factor = 1; while( CMdigit( yyp ) ) { ++yyleng; CMnext( yyp ); } if( *yyp == '.' ) { ++yyleng; CMnext( yyp ); if( !CMdigit( yyp ) ) yyerror(); while( CMdigit( yyp ) ) { ++yyleng; CMnext( yyp ); } } else if( *yyp == 'K' || *yyp == 'M' ) { ++yyleng; CMnext( yyp ); } STlcopy( p, yytext, yyleng ); yytext[ yyleng ] = EOS; if( yytext[ yyleng - 1 ] == 'K' ) { factor = 1024; yytext[ yyleng - 1 ] = EOS; } else if( yytext[ yyleng - 1 ] == 'M' ) { factor = 1048576; yytext[ yyleng - 1 ] = EOS; } CVaf( yytext, ERx( '.' ), &yylval.real ); yylval.real *= factor; return( NUM_CON ); } } if( STbcompare( yyp, 2, ERx( ">=" ), 2, FALSE ) == 0 ) { yylval.string = STalloc( ERx( ">=" ) ); CMnext( yyp ); CMnext( yyp ); return( COMPARE_OP ); } if( STbcompare( yyp, 2, ERx( "<=" ), 2, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "<=" ) ); CMnext( yyp ); CMnext( yyp ); return( COMPARE_OP ); } /* check for COMPARE_OP */ if( STbcompare( yyp, 1, ERx( "<" ), 1, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "<" ) ); CMnext( yyp ); return( COMPARE_OP ); } if( STbcompare( yyp, 1, ERx( ">" ), 1, FALSE ) == 0 ) { yylval.string = STalloc( ERx( ">" ) ); CMnext( yyp ); return( COMPARE_OP ); } if( STbcompare( yyp, 2, ERx( "==" ), 2, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "==" ) ); CMnext( yyp ); CMnext( yyp ); return( COMPARE_OP ); } /* check for characters which get passed directly */ switch( *yyp ) { char *p; case '(': case ')': case '[': case ']': case '{': case '}': case ':': case ';': case ',': case '=': p = yyp; CMnext( yyp ); return( *p ); case '+': yylval.string = STalloc( ERx( "+" ) ); CMnext( yyp ); return( *yylval.string ); case '-': yylval.string = STalloc( ERx( "-" ) ); CMnext( yyp ); return( *yylval.string ); case '*': yylval.string = STalloc( ERx( "*" ) ); CMnext( yyp ); return( *yylval.string ); case '/': yylval.string = STalloc( ERx( "/" ) ); CMnext( yyp ); return( *yylval.string ); } /* check for LOGIC_OP */ if( STbcompare( yyp, 3, ERx( "&&" ), 3, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "&&" ) ); CMnext( yyp ); CMnext( yyp ); return( LOGIC_OP ); } if( STbcompare( yyp, 3, ERx( "||" ), 3, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "||" ) ); CMnext( yyp ); CMnext( yyp ); return( LOGIC_OP ); } /* anything else is an error */ yyerror(); }
STATUS MOset_monitor( char *classid, PTR mon_data, char *qual_regexp, MO_MONITOR_FUNC *monitor, MO_MONITOR_FUNC **old_monitor ) { MO_MON_BLOCK *mp; /* our monitor block */ MO_MON_BLOCK *fmp; /* first monitor block */ MO_MON_BLOCK *pmp; /* previous monitor block */ MO_CLASS *cp; /* class in question (not classid) */ char *saved_qual = NULL; STATUS ret_val = OK; STATUS mutex_stat; mutex_stat = MO_mutex(); do { if( mutex_stat != OK ) break; /* if we'll need it, save any qual_regexp string */ if( monitor != NULL && qual_regexp != NULL ) { saved_qual = MO_defstring( qual_regexp, &ret_val ); if( saved_qual == NULL ) break; /* FIXME maybe compile it here too? */ } /* locate the class def, we need it everywhere */ if( (ret_val = MO_getclass( classid, &cp )) != OK ) break; /* see if this is a replacement for an existing monitor */ mp = NULL; if( (mp = MO_getmon( cp, mon_data ) ) != NULL ) { /* yes, replace it with new values as appropriate */ *old_monitor = mp->monitor; if( monitor == NULL ) /* delete this monitor */ { MO_delmon( mp ); } else /* replace this one's values */ { mp->monitor = monitor; mp->mon_data = mon_data; /* delete old qual string */ if( mp->qual_regexp != NULL ) MO_delstring( mp->qual_regexp ); mp->qual_regexp = saved_qual; } } else if( monitor == NULL ) /* huh!? */ { ret_val = MO_BAD_MONITOR; break; } else /* make a new one and link it in. */ { *old_monitor = NULL; /* if it's an OID, get the class def instead */ if( CMdigit( (char *)cp->node.key ) && cp->twin != NULL ) cp = cp->twin; /* get a new monitor block */ mp = (MO_MON_BLOCK *)MO_alloc( sizeof( *mp ), &ret_val ); if( mp == NULL ) break; /* fill in the new block, and link in to the tree */ mp->node.key = (PTR)mp; mp->mo_class = cp; mp->monitor = monitor; mp->mon_data = mon_data; mp->qual_regexp = saved_qual; (void) SPenq( &mp->node, MO_monitors ); /* Fill in the class with first monitor for the class. The loop below goes backwards until pmp is null or doesn't have the same class definition. When it exits, fmp is at the first monitor block for the class */ for( fmp = mp; (pmp = (MO_MON_BLOCK *)SPfprev( &fmp->node )) != NULL && pmp->mo_class == cp; fmp = pmp ) continue; fmp->mo_class->monitor = fmp; if( cp->twin ) cp->twin->monitor = fmp; } } while ( FALSE ); if( mutex_stat != OK ) { ret_val = mutex_stat; } else { if( ret_val == OK ) MO_nset_monitor++; else if( saved_qual != NULL ) MO_delstring( saved_qual ); (void) MO_unmutex(); } return( ret_val ); }
/*{ ** Name: RPedit_name - edit an Ingres name ** ** Description: ** Edit an Ingres name as specified. The edited name is placed in a ** global buffer. ** ** Inputs: ** edit_type - edit type ** EDNM_ALPHA - replace special chars with '_'. ** EDNM_DELIMIT - Ingres delimited name. ** EDNM_SLITERAL - SQL single quoted string. ** else - no edit ** name - name to edit ** ** Outputs: ** edited_name - if supplied, this buffer is filled with the edited ** name; if NULL, a global buffer is used and the ** caller should do an STcopy() upon return. ** ** Returns: ** pointer to the edited name **/ char * RPedit_name( i4 edit_type, char *name, char *edited_name) { char tmp_name[DB_MAXNAME*2+3]; char *t = tmp_name; char *en; char *n; if (edited_name != NULL) en = edited_name; else en = Edited_Name_Buf; switch (edit_type) { case EDNM_ALPHA: /* alphanumeric */ for (n = name; *n != EOS; CMnext(n)) { if (CMalpha(n) || (n != name && CMdigit(n))) CMcpychar(n, t); else CMcpychar(ERx("_"), t); CMnext(t); } *t = EOS; break; case EDNM_DELIMIT: /* delimited */ CMcpychar(ERx("\""), t); CMnext(t); for (n = name; *n != EOS; CMnext(n)) { CMcpychar(n, t); if (!CMcmpcase(t, ERx("\""))) { CMnext(t); CMcpychar(ERx("\""), t); } CMnext(t); } CMcpychar(ERx("\""), t); CMnext(t); *t = EOS; break; case EDNM_SLITERAL: /* SQL quoted */ CMcpychar(ERx("'"), t); CMnext(t); for (n = name; *n != EOS; CMnext(n)) { if (!CMcmpcase(n, ERx("'"))) { CMcpychar(ERx("'"), t); CMnext(t); } CMcpychar(n, t); CMnext(t); } CMcpychar(ERx("'"), t); CMnext(t); *t = EOS; break; default: /* no edit */ t = name; break; } STcopy(tmp_name, en); return (en); }