Example #1
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    dig_fhandle     filehndl;
    const char      *ptr;
    trap_init_func  *init_func;
#ifdef USE_FILENAME_VERSION
    char            filename[256];
    char            *p;
#endif

    if( parms == NULL || *parms == '\0' )
        parms = "std";
#ifdef USE_FILENAME_VERSION
    for( ptr = parms, p = filename; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        *p++ = *ptr;
    }
    *p++ = ( USE_FILENAME_VERSION / 10 ) + '0';
    *p++ = ( USE_FILENAME_VERSION % 10 ) + '0';
    *p = '\0';
    filehndl = DIGPathOpen( filename, p - filename, "trp", NULL, 0 );
#else
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        ;
    }
    filehndl = DIGPathOpen( parms, ptr - parms, "trp", NULL, 0 );
#endif
    if( filehndl == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    parms = ptr;
    ptr = ReadInTrap( DIGGetSystemHandle( filehndl ) );
    DIGPathClose( filehndl );
    if( ptr != NULL ) {
        strcpy( buff, ptr );
    } else {
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        if( TrapCode->signature == TRAP_SIGNATURE ) {
            init_func = MK_FP( FP_SEG( TrapCode ), TrapCode->init_off );
            if( *parms != '\0' )
                ++parms;
            *trap_ver = init_func( parms, buff, trap_ver->remote );
            if( buff[0] == '\0' ) {
                if( TrapVersionOK( *trap_ver ) ) {
                    TrapVer = *trap_ver;
                    FiniFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->fini_off );
                    ReqFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->req_off );
                    return( NULL );
                }
                strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            }
        }
    }
    KillTrap();
    return( buff );
}
Example #2
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 );
}
Example #3
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    char                *err;
    char                *parm;
    char                *end;
    dig_fhandle         dh;
    trap_file_header    __far *head;


    if( trapbuff == NULL ) {
        trapbuff = DEFAULT_TRP_NAME;
    }
    end = strchr( trapbuff, PARM_SEPARATOR );
    if( end == NULL ) {
        end = &trapbuff[strlen( trapbuff )];
        parm = end;
    } else {
        parm = end + 1;
    }
    dh = DIGPathOpen( trapbuff, end - trapbuff, DEFAULT_TRP_EXT, NULL, 0 );
    if( dh == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
        return( buff );
    }
    err = ReadInTrap( DIGGetSystemHandle( dh ) );
    DIGPathClose( dh );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, trapbuff );
    if( err == NULL ) {
        if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) {
            strcpy( buff, err );
        } else {
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            head = MK_PM( TrapMem.segm.rm, 0 );
            if( head->sig == TRAP_SIGNATURE ) {
                PMData->initfunc.s.offset = head->init;
                PMData->reqfunc.s.offset  = head->req;
                PMData->finifunc.s.offset = head->fini;
                PMData->initfunc.s.segment = TrapMem.segm.rm;
                PMData->reqfunc.s.segment  = TrapMem.segm.rm;
                PMData->finifunc.s.segment = TrapMem.segm.rm;
                if( CallTrapInit( parm, buff, trap_ver ) ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = DoTrapAccess;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
                }
            }
        }
    }
    KillTrap();
    return( buff );
}
Example #4
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                *err;
    const char          *end;
    dig_fhandle         dh;
    trap_file_header    __far *head;


    if( parms == NULL || *parms == '\0' ) {
        parms = DEFAULT_TRP_NAME;
    }
    for( end = parms; *end != '\0' && *end != TRAP_PARM_SEPARATOR; ++end )
        ;
    dh = DIGPathOpen( parms, end - parms, DEFAULT_TRP_EXT, NULL, 0 );
    if( dh == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    err = ReadInTrap( DIGGetSystemHandle( dh ) );
    DIGPathClose( dh );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
    if( err == NULL ) {
        if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) {
            strcpy( buff, err );
        } else {
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            head = MK_PM( TrapMem.segm.rm, 0 );
            if( head->sig == TRAP_SIGNATURE ) {
                PMData->initfunc.s.offset = head->init;
                PMData->reqfunc.s.offset  = head->req;
                PMData->finifunc.s.offset = head->fini;
                PMData->initfunc.s.segment = TrapMem.segm.rm;
                PMData->reqfunc.s.segment  = TrapMem.segm.rm;
                PMData->finifunc.s.segment = TrapMem.segm.rm;
                parms = end;
                if( *parms != '\0' )
                    ++parms;
                if( CallTrapInit( parms, buff, trap_ver ) ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = DoTrapAccess;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
                }
            }
        }
    }
    KillTrap();
    return( buff );
}
Example #5
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 );
}
Example #6
0
char *LoadTrap( char *trapbuff, char *buff, trap_version *trap_ver )
{
    dig_fhandle     filehndl;
    char            *ptr;
    char            *parm;
    trap_init_func  *init_func;

    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 );
    }
    ptr = ReadInTrap( DIGGetSystemHandle( filehndl ) );
    DIGPathClose( filehndl );
    if( ptr != NULL ) {
        strcpy( buff, ptr );
    } else {
        strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
        if( TrapCode->signature == TRAP_SIGNATURE ) {
            init_func = MK_FP( FP_SEG( TrapCode ), TrapCode->init_off );
            *trap_ver = init_func( parm, buff, trap_ver->remote );
            if( buff[0] == '\0' ) {
                if( TrapVersionOK( *trap_ver ) ) {
                    TrapVer = *trap_ver;
                    FiniFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->fini_off );
                    ReqFunc = MK_FP( FP_SEG( TrapCode ), TrapCode->req_off );
                    return( NULL );
                }
                strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            }
        }
    }
    KillTrap();
    return( buff );
}
Example #7
0
char *LoadTrap( const char *parms, char *buff, trap_version *trap_ver )
{
    char                *err;
    const char          *ptr;
    dig_fhandle         dh;
    trap_file_header    __far *head;
#ifdef USE_FILENAME_VERSION
    char                filename[256];
    char                *p;
#endif

    if( parms == NULL || *parms == '\0' ) {
        parms = DEFAULT_TRP_NAME;
    }
#ifdef USE_FILENAME_VERSION
    for( ptr = parms, p = filename; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        *p++ = *ptr;
    }
    *p++ = ( USE_FILENAME_VERSION / 10 ) + '0';
    *p++ = ( USE_FILENAME_VERSION % 10 ) + '0';
    *p = '\0';
    dh = DIGPathOpen( filename, p - filename, DEFAULT_TRP_EXT, NULL, 0 );
#else
    for( ptr = parms; *ptr != '\0' && *ptr != TRAP_PARM_SEPARATOR; ++ptr ) {
        ;
    }
    dh = DIGPathOpen( parms, ptr - parms, DEFAULT_TRP_EXT, NULL, 0 );
#endif
    if( dh == DIG_NIL_HANDLE ) {
        sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
        return( buff );
    }
    err = ReadInTrap( DIGGetSystemHandle( dh ) );
    DIGPathClose( dh );
    sprintf( buff, TC_ERR_CANT_LOAD_TRAP, parms );
    if( err == NULL ) {
        if( (err = SetTrapHandler()) != NULL || (err = CopyEnv()) != NULL ) {
            strcpy( buff, err );
        } else {
            strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
            head = MK_PM( TrapMem.segm.rm, 0 );
            if( head->sig == TRAP_SIGNATURE ) {
                PMData->initfunc.s.offset = head->init;
                PMData->reqfunc.s.offset  = head->req;
                PMData->finifunc.s.offset = head->fini;
                PMData->initfunc.s.segment = TrapMem.segm.rm;
                PMData->reqfunc.s.segment  = TrapMem.segm.rm;
                PMData->finifunc.s.segment = TrapMem.segm.rm;
                parms = ptr;
                if( *parms != '\0' )
                    ++parms;
                if( CallTrapInit( parms, buff, trap_ver ) ) {
                    if( TrapVersionOK( *trap_ver ) ) {
                        TrapVer = *trap_ver;
                        ReqFunc = DoTrapAccess;
                        return( NULL );
                    }
                    strcpy( buff, TC_ERR_WRONG_TRAP_VERSION );
                }
            }
        }
    }
    KillTrap();
    return( buff );
}