1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-26 15:16:36 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2017-01-04 04:36:47 +08:00
|
|
|
* Copyright 1998-2017 The OpenLDAP Foundation.
|
2003-11-26 15:16:36 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1999-01-24 09:07:52 +08:00
|
|
|
*/
|
|
|
|
|
2000-01-24 07:07:24 +08:00
|
|
|
/*
|
|
|
|
* Locale-specific 1-byte character versions
|
|
|
|
* See utf-8.c for UTF-8 versions
|
|
|
|
*/
|
|
|
|
|
1999-01-24 09:07:52 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1999-06-03 08:37:44 +08:00
|
|
|
#include <ac/stdlib.h>
|
1999-01-24 09:07:52 +08:00
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
1999-08-25 14:44:08 +08:00
|
|
|
#include <ac/ctype.h>
|
1999-01-24 09:07:52 +08:00
|
|
|
|
|
|
|
#include "ldap-int.h"
|
|
|
|
|
1999-01-24 09:32:04 +08:00
|
|
|
|
|
|
|
#if defined ( HAVE_STRSPN )
|
|
|
|
#define int_strspn strspn
|
|
|
|
#else
|
|
|
|
static int int_strspn( const char *str, const char *delim )
|
|
|
|
{
|
|
|
|
int pos;
|
|
|
|
const char *p=delim;
|
|
|
|
|
|
|
|
for( pos=0; (*str) ; pos++,str++) {
|
|
|
|
if (*str!=*p) {
|
|
|
|
for( p=delim; (*p) ; p++ ) {
|
|
|
|
if (*str==*p) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*p=='\0') {
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined( HAVE_STRPBRK )
|
|
|
|
#define int_strpbrk strpbrk
|
|
|
|
#else
|
|
|
|
static char *(int_strpbrk)( const char *str, const char *accept )
|
|
|
|
{
|
|
|
|
const char *p;
|
|
|
|
|
|
|
|
for( ; (*str) ; str++ ) {
|
|
|
|
for( p=accept; (*p) ; p++) {
|
|
|
|
if (*str==*p) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
char *(ldap_pvt_strtok)( char *str, const char *delim, char **pos )
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if (pos==NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str==NULL) {
|
|
|
|
if (*pos==NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
str=*pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* skip any initial delimiters */
|
|
|
|
str += int_strspn( str, delim );
|
|
|
|
if (*str == '\0') {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = int_strpbrk( str, delim );
|
|
|
|
if (p==NULL) {
|
|
|
|
*pos = NULL;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
*p ='\0';
|
|
|
|
*pos = p+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
1999-08-25 14:44:08 +08:00
|
|
|
char *
|
|
|
|
ldap_pvt_str2upper( char *str )
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
/* to upper */
|
2002-06-07 21:27:25 +08:00
|
|
|
if ( str ) {
|
|
|
|
for ( s = str; *s; s++ ) {
|
|
|
|
*s = TOUPPER( (unsigned char) *s );
|
|
|
|
}
|
1999-08-25 14:44:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return( str );
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:45:17 +08:00
|
|
|
struct berval *
|
|
|
|
ldap_pvt_str2upperbv( char *str, struct berval *bv )
|
|
|
|
{
|
|
|
|
char *s = NULL;
|
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( bv != NULL );
|
2002-08-23 16:45:17 +08:00
|
|
|
|
|
|
|
/* to upper */
|
|
|
|
if ( str ) {
|
|
|
|
for ( s = str; *s; s++ ) {
|
|
|
|
*s = TOUPPER( (unsigned char) *s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bv->bv_val = str;
|
|
|
|
bv->bv_len = (ber_len_t)(s - str);
|
|
|
|
|
|
|
|
return( bv );
|
|
|
|
}
|
|
|
|
|
1999-08-25 14:44:08 +08:00
|
|
|
char *
|
|
|
|
ldap_pvt_str2lower( char *str )
|
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
|
|
|
|
/* to lower */
|
2002-06-07 21:27:25 +08:00
|
|
|
if ( str ) {
|
|
|
|
for ( s = str; *s; s++ ) {
|
|
|
|
*s = TOLOWER( (unsigned char) *s );
|
|
|
|
}
|
1999-08-25 14:44:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return( str );
|
|
|
|
}
|
2002-08-23 16:45:17 +08:00
|
|
|
|
|
|
|
struct berval *
|
|
|
|
ldap_pvt_str2lowerbv( char *str, struct berval *bv )
|
|
|
|
{
|
|
|
|
char *s = NULL;
|
|
|
|
|
2005-07-18 14:22:33 +08:00
|
|
|
assert( bv != NULL );
|
2002-08-23 16:45:17 +08:00
|
|
|
|
|
|
|
/* to lower */
|
|
|
|
if ( str ) {
|
|
|
|
for ( s = str; *s; s++ ) {
|
|
|
|
*s = TOLOWER( (unsigned char) *s );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bv->bv_val = str;
|
|
|
|
bv->bv_len = (ber_len_t)(s - str);
|
|
|
|
|
|
|
|
return( bv );
|
|
|
|
}
|