예제 #1
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    dig_fhandle         filehndl;
    const char          *ptr;
    const trap_requests *(*ld_func)( const trap_callbacks * );
    char                trap_name[_MAX_PATH];
    const trap_requests *trap_funcs;

    if( parms == NULL || *parms == '\0' )
        parms = "std";
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr )
        ;
#if !defined( BUILTIN_TRAP_FILE )
    filehndl = DIGPathOpen( parms, ptr - parms, "so", trap_name, sizeof( trap_name ) );
    if( filehndl == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    TrapFile = dlopen( trap_name, RTLD_NOW );
    DIGPathClose( filehndl );
    if( TrapFile == NULL ) {
        puts( dlerror() );
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trap_name );
        return( buff );
    }
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    ld_func = dlsym( TrapFile, "TrapLoad" );
    if( ld_func != NULL ) {
#else
    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
    ld_func = TrapLoad;
#endif
        trap_funcs = ld_func( &TrapCallbacks );
        if( trap_funcs != NULL ) {
            parms = ptr;
            if( *parms != '\0' )
                ++parms;
            *trap_ver = trap_funcs->init_func( parms, buff, trap_ver->remote );
            FiniFunc = trap_funcs->fini_func;
            if( buff[0] == '\0' ) {
                if( TrapVersionOK( *trap_ver ) ) {
                    TrapVer = *trap_ver;
                    ReqFunc = trap_funcs->req_func;
                    return( NULL );
                }
                strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            }
        }
#if !defined( BUILTIN_TRAP_FILE )
    }
#endif
    KillTrap();
    return( buff );
}
예제 #2
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    dig_fhandle         filehndl;
    char                *ptr;
    char                *parm;
    const trap_requests *(*ld_func)( const trap_callbacks * );
    const trap_requests *trap_funcs;

    if( trapbuff == NULL )
        trapbuff = "std";
    for( ptr = trapbuff; *ptr != '\0' && *ptr != ';'; ++ptr )
        ;
    parm = (*ptr != '\0') ? ptr + 1 : ptr;
    filehndl = DIGPathOpen( trapbuff, ptr - trapbuff, "trp", NULL, 0 );
    if( filehndl == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        return( buff );
    }
    TrapCode = ReadInImp( filehndl );
    DIGPathClose( filehndl );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
    if( TrapCode != NULL ) {
#ifdef __WATCOMC__
        if( TrapCode->sig == TRAPSIG ) {
#endif
            strcpy( buff, TC_ERR_BAD_TRAP_FILE );
            ld_func = (void *)TrapCode->init_rtn;
            trap_funcs = ld_func( &TrapCallbacks );
            if( trap_funcs != NULL ) {
                *trap_ver = trap_funcs->init_func( parm, buff, trap_ver->remote );
                FiniFunc = trap_funcs->fini_func;
                if( buff[0] == '\0' ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = trap_funcs->req_func;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_BAD_TRAP_FILE );
                }
            }
#ifdef __WATCOMC__
        }
#endif
        KillTrap();
    }
    return( buff );
}