int __parse_connection_string_w( struct con_struct *con_str,
    SQLWCHAR *str, int str_len )
{
struct con_pair *cp;
char *local_str, *ptr;
int len;
int got_dsn = 0;    /* if we have a DSN then ignore any DRIVER or FILEDSN */
int got_driver = 0;    /* if we have a DRIVER or FILEDSN then ignore any DSN */

    con_str -> count = 0;
    con_str -> list = NULL;

    if ( str_len == SQL_NTS )
    {
        len =  wide_strlen( str ) + 1;
        local_str = malloc( len );
    }
    else
    {
        len = str_len + 1;
        local_str = malloc( len );
    }

    unicode_to_ansi_copy( local_str, len - 1, str, len - 1, NULL );

    if ( !local_str || strlen( local_str ) == 0 ||
        ( strlen( local_str ) == 1 && *local_str == ';' ))
    {
        /* connection-string ::= empty-string [;] */
        free( local_str );

        __append_pair( con_str, "DSN", "DEFAULT" );
        return 0;
    }

    ptr = local_str;

    while(( cp = __get_pair( &ptr )) != NULL )
    {
        if ( strcasecmp( cp -> keyword, "DSN" ) == 0 )
        {
            if ( got_driver )
                continue;

            got_dsn = 1;
        }
        else if ( strcasecmp( cp -> keyword, "DRIVER" ) == 0 ||
            strcmp( cp -> keyword, "FILEDSN" ) == 0 )
        {
            if ( got_dsn )
                continue;

            got_driver = 1;
        }

        __append_pair( con_str, cp -> keyword, cp -> attribute );
        free( cp -> keyword );
        free( cp -> attribute );
        free( cp );
    }

    /* if no dsn or DRIVER, then set DSN=DEFAULT */
    if ( !got_driver && !got_dsn )
    {
        __append_pair( con_str, "DSN", "DEFAULT" );
    }

    free( local_str );

    return 0;
}
Exemple #2
0
int __parse_connection_string_ex( struct con_struct *con_str,
    char *str, int str_len, int exclude )
{
struct con_pair *cp;
char *local_str, *ptr;
int got_dsn = 0;    /* if we have a DSN then ignore any DRIVER or FILEDSN */
int got_driver = 0;    /* if we have a DRIVER or FILEDSN then ignore any DSN */

    con_str -> count = 0;
    con_str -> list = NULL;

    if ( str_len != SQL_NTS )
    {
        local_str = malloc( str_len + 1 );
        memcpy( local_str, str, str_len );
        local_str[ str_len ] = '\0';
    }
    else
    {
        local_str = str;
    }

    if ( !local_str || strlen( local_str ) == 0 ||
        ( strlen( local_str ) == 1 && *local_str == ';' ))
    {
        /* connection-string ::= empty-string [;] */
        if ( str_len != SQL_NTS )
            free( local_str );

        __append_pair( con_str, "DSN", "DEFAULT" );
        return 0;
    }

    ptr = local_str;

    while(( cp = __get_pair( &ptr )) != NULL )
    {
        if ( strcasecmp( cp -> keyword, "DSN" ) == 0 )
        {
            if ( got_driver && exclude )
                continue;

            got_dsn = 1;
        }
        else if ( strcasecmp( cp -> keyword, "DRIVER" ) == 0 ||
            strcmp( cp -> keyword, "FILEDSN" ) == 0 )
        {
            if ( got_dsn && exclude )
                continue;

            got_driver = 1;
        }

        __append_pair( con_str, cp -> keyword, cp -> attribute );
        free( cp -> keyword );
        free( cp -> attribute );
        free( cp );
    }

    /* if no dsn or DRIVER, then set DSN=DEFAULT */
    if ( !got_driver && !got_dsn )
    {
        __append_pair( con_str, "DSN", "DEFAULT" );
    }

    if ( str_len != SQL_NTS )
        free( local_str );

    return 0;
}