minor cleanup

This commit is contained in:
Pierangelo Masarati 2006-01-06 16:20:24 +00:00
parent 60ccde8f14
commit b1fb7f824d
3 changed files with 33 additions and 32 deletions

View File

@ -1511,3 +1511,34 @@ tool_write_ldif( int type, char *name, char *value, ber_len_t vallen )
return( 0 );
}
int
tool_is_oid( const char *s )
{
int first = 1;
if ( !isdigit( s[ 0 ] ) ) {
return 0;
}
for ( ; s[ 0 ]; s++ ) {
if ( s[ 0 ] == '.' ) {
if ( s[ 1 ] == '\0' ) {
return 0;
}
first = 1;
continue;
}
if ( !isdigit( s[ 0 ] ) ) {
return 0;
}
if ( first == 1 && s[ 0 ] == '0' && s[ 1 ] != '.' ) {
return 0;
}
first = 0;
}
return 1;
}

View File

@ -93,6 +93,7 @@ void tool_perror LDAP_P((
char **refs ));
void tool_print_ctrls LDAP_P(( LDAP *ld, LDAPControl **ctrls ));
int tool_write_ldif LDAP_P(( int type, char *name, char *value, ber_len_t vallen ));
int tool_is_oid LDAP_P(( const char *s ));
LDAP_END_DECL

View File

@ -237,37 +237,6 @@ ctrl_add( void )
return 0;
}
static int
is_oid( const char *s )
{
int first = 1;
if ( !isdigit( s[ 0 ] ) ) {
return 0;
}
for ( ; s[ 0 ]; s++ ) {
if ( s[ 0 ] == '.' ) {
if ( s[ 1 ] == '\0' ) {
return 0;
}
first = 1;
continue;
}
if ( !isdigit( s[ 0 ] ) ) {
return 0;
}
if ( first == 1 && s[ 0 ] == '0' && s[ 1 ] != '.' ) {
return 0;
}
first = 0;
}
return 1;
}
static int parse_page_control(
LDAP *ld,
LDAPMessage *result,
@ -498,7 +467,7 @@ handle_private_option( int i )
}
if ( crit ) ldapsync *= -1;
} else if ( is_oid( control ) ) {
} else if ( tool_is_oid( control ) ) {
if ( ctrl_add() ) {
exit( EXIT_FAILURE );
}