Пример #1
0
/*
 ** Load all automatic extensions.
 **
 ** If anything goes wrong, set an error in the database connection.
 */
SQLITE_PRIVATE void sqlite3AutoLoadExtensions(sqlite3 *db){
    int i;
    int go = 1;
    int rc;
    int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
    
    wsdAutoextInit;
    if( wsdAutoext.nExt==0 ){
        /* Common case: early out without every having to acquire a mutex */
        return;
    }
    for(i=0; go; i++){
        char *zErrmsg;
#if SQLITE_THREADSAFE
        sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
        sqlite3_mutex_enter(mutex);
        if( i>=wsdAutoext.nExt ){
            xInit = 0;
            go = 0;
        }else{
            xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
            wsdAutoext.aExt[i];
        }
        sqlite3_mutex_leave(mutex);
        zErrmsg = 0;
        if( xInit && (rc = xInit(db, &zErrmsg, &sqlite3Apis))!=0 ){
            sqlite3Error(db, rc,
                         "automatic extension loading failed: %s", zErrmsg);
            go = 0;
        }
        sqlite3_free(zErrmsg);
    }
}
Пример #2
0
/*
** Load all automatic extensions.
*/
int sqlite3AutoLoadExtensions(sqlite3 *db){
  int i;
  int go = 1;
  int rc = SQLITE_OK;
  int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);

  if( autoext.nExt==0 ){
    /* Common case: early out without every having to acquire a mutex */
    return SQLITE_OK;
  }
  for(i=0; go; i++){
    char *zErrmsg = 0;
#ifndef SQLITE_MUTEX_NOOP
    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
    sqlite3_mutex_enter(mutex);
    if( i>=autoext.nExt ){
      xInit = 0;
      go = 0;
    }else{
      xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
              autoext.aExt[i];
    }
    sqlite3_mutex_leave(mutex);
    if( xInit && xInit(db, &zErrmsg, &sqlite3Apis) ){
      sqlite3Error(db, SQLITE_ERROR,
            "automatic extension loading failed: %s", zErrmsg);
      go = 0;
      rc = SQLITE_ERROR;
      sqlite3_free(zErrmsg);
    }
  }
  return rc;
}
Пример #3
0
/*
** Load all automatic extensions.
*/
int sqlite3AutoLoadExtensions(sqlite3 *db){
  int i;
  int go = 1;
  int rc = SQLITE_OK;
  int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);

  if( nAutoExtension==0 ){
    /* Common case: early out without every having to acquire a mutex */
    return SQLITE_OK;
  }
  for(i=0; go; i++){
    char *zErrmsg = 0;
    sqlite3OsEnterMutex();
    if( i>=nAutoExtension ){
      xInit = 0;
      go = 0;
    }else{
      xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
              aAutoExtension[i];
    }
    sqlite3OsLeaveMutex();
    if( xInit && xInit(db, &zErrmsg, &sqlite3_apis) ){
      sqlite3Error(db, SQLITE_ERROR,
            "automatic extension loading failed: %s", zErrmsg);
      go = 0;
      rc = SQLITE_ERROR;
    }
  }
  return rc;
}
Пример #4
0
/*
 ** Attempt to load an SQLite extension library contained in the file
 ** zFile.  The entry point is zProc.  zProc may be 0 in which case a
 ** default entry point name (sqlite3_extension_init) is used.  Use
 ** of the default name is recommended.
 **
 ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
 **
 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
 ** error message text.  The calling function should free this memory
 ** by calling sqlite3DbFree(db, ).
 */
static int sqlite3LoadExtension(
                                sqlite3 *db,          /* Load the extension into this database connection */
                                const char *zFile,    /* Name of the shared library containing extension */
                                const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
                                char **pzErrMsg       /* Put error message here if not 0 */
){
    sqlite3_vfs *pVfs = db->pVfs;
    void *handle;
    int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
    char *zErrmsg = 0;
    const char *zEntry;
    char *zAltEntry = 0;
    void **aHandle;
    int nMsg = 300 + sqlite3Strlen30(zFile);
    int ii;
    
    /* Shared library endings to try if zFile cannot be loaded as written */
    static const char *azEndings[] = {
#if SQLITE_OS_WIN
        "dll"
#elif defined(__APPLE__)
        "dylib"
#else
        "so"
#endif
    };
    
    
    if( pzErrMsg ) *pzErrMsg = 0;
    
    /* Ticket #1863.  To avoid a creating security problems for older
     ** applications that relink against newer versions of SQLite, the
     ** ability to run load_extension is turned off by default.  One
     ** must call sqlite3_enable_load_extension() to turn on extension
     ** loading.  Otherwise you get the following error.
     */
    if( (db->flags & SQLITE_LoadExtension)==0 ){
        if( pzErrMsg ){
            *pzErrMsg = sqlite3_mprintf("not authorized");
        }
        return SQLITE_ERROR;
    }
    
    zEntry = zProc ? zProc : "sqlite3_extension_init";
    
    handle = sqlite3OsDlOpen(pVfs, zFile);
#if SQLITE_OS_UNIX || SQLITE_OS_WIN
    for(ii=0; ii<ArraySize(azEndings) && handle==0; ii++){
        char *zAltFile = sqlite3_mprintf("%s.%s", zFile, azEndings[ii]);
        if( zAltFile==0 ) return SQLITE_NOMEM;
        handle = sqlite3OsDlOpen(pVfs, zAltFile);
        sqlite3_free(zAltFile);
    }
#endif
    if( handle==0 ){
        if( pzErrMsg ){
            *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
            if( zErrmsg ){
                sqlite3_snprintf(nMsg, zErrmsg,
                                 "unable to open shared library [%s]", zFile);
                sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
            }
        }
        return SQLITE_ERROR;
    }
    xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
    sqlite3OsDlSym(pVfs, handle, zEntry);
    
    /* If no entry point was specified and the default legacy
     ** entry point name "sqlite3_extension_init" was not found, then
     ** construct an entry point name "sqlite3_X_init" where the X is
     ** replaced by the lowercase value of every ASCII alphabetic
     ** character in the filename after the last "/" upto the first ".",
     ** and eliding the first three characters if they are "lib".
     ** Examples:
     **
     **    /usr/local/lib/libExample5.4.3.so ==>  sqlite3_example_init
     **    C:/lib/mathfuncs.dll              ==>  sqlite3_mathfuncs_init
     */
    if( xInit==0 && zProc==0 ){
        int iFile, iEntry, c;
        int ncFile = sqlite3Strlen30(zFile);
        zAltEntry = sqlite3_malloc(ncFile+30);
        if( zAltEntry==0 ){
            sqlite3OsDlClose(pVfs, handle);
            return SQLITE_NOMEM;
        }
        memcpy(zAltEntry, "sqlite3_", 8);
        for(iFile=ncFile-1; iFile>=0 && zFile[iFile]!='/'; iFile--){}
        iFile++;
        if( sqlite3_strnicmp(zFile+iFile, "lib", 3)==0 ) iFile += 3;
        for(iEntry=8; (c = zFile[iFile])!=0 && c!='.'; iFile++){
            if( sqlite3Isalpha(c) ){
                zAltEntry[iEntry++] = (char)sqlite3UpperToLower[(unsigned)c];
            }
        }
        memcpy(zAltEntry+iEntry, "_init", 6);
        zEntry = zAltEntry;
        xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
        sqlite3OsDlSym(pVfs, handle, zEntry);
    }
    if( xInit==0 ){
        if( pzErrMsg ){
            nMsg += sqlite3Strlen30(zEntry);
            *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
            if( zErrmsg ){
                sqlite3_snprintf(nMsg, zErrmsg,
                                 "no entry point [%s] in shared library [%s]", zEntry, zFile);
                sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
            }
        }
        sqlite3OsDlClose(pVfs, handle);
        sqlite3_free(zAltEntry);
        return SQLITE_ERROR;
    }
    sqlite3_free(zAltEntry);
    if( xInit(db, &zErrmsg, &sqlite3Apis) ){
        if( pzErrMsg ){
            *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
        }
        sqlite3_free(zErrmsg);
        sqlite3OsDlClose(pVfs, handle);
        return SQLITE_ERROR;
    }
    
    /* Append the new shared library handle to the db->aExtension array. */
    aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
    if( aHandle==0 ){
        return SQLITE_NOMEM;
    }
    if( db->nExtension>0 ){
        memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
    }
    sqlite3DbFree(db, db->aExtension);
    db->aExtension = aHandle;
    
    db->aExtension[db->nExtension++] = handle;
    return SQLITE_OK;
}
Пример #5
0
/*
** Attempt to load an SQLite extension library contained in the file
** zFile.  The entry point is zProc.  zProc may be 0 in which case a
** default entry point name (sqlite3_extension_init) is used.  Use
** of the default name is recommended.
**
** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
**
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 
** error message text.  The calling function should free this memory
** by calling sqlite3DbFree(db, ).
*/
static int sqlite3LoadExtension(
  sqlite3 *db,          /* Load the extension into this database connection */
  const char *zFile,    /* Name of the shared library containing extension */
  const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
  char **pzErrMsg       /* Put error message here if not 0 */
){
  sqlite3_vfs *pVfs = db->pVfs;
  void *handle;
  int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
  char *zErrmsg = 0;
  void **aHandle;
  int nMsg = 300 + sqlite3Strlen30(zFile);

  if( pzErrMsg ) *pzErrMsg = 0;

  /* Ticket #1863.  To avoid a creating security problems for older
  ** applications that relink against newer versions of SQLite, the
  ** ability to run load_extension is turned off by default.  One
  ** must call sqlite3_enable_load_extension() to turn on extension
  ** loading.  Otherwise you get the following error.
  */
  if( (db->flags & SQLITE_LoadExtension)==0 ){
    if( pzErrMsg ){
      *pzErrMsg = sqlite3_mprintf("not authorized");
    }
    return SQLITE_ERROR;
  }

  if( zProc==0 ){
    zProc = "sqlite3_extension_init";
  }

  handle = sqlite3OsDlOpen(pVfs, zFile);
  if( handle==0 ){
    if( pzErrMsg ){
      *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
      if( zErrmsg ){
        sqlite3_snprintf(nMsg, zErrmsg, 
            "unable to open shared library [%s]", zFile);
        sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
      }
    }
    return SQLITE_ERROR;
  }
  xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
                   sqlite3OsDlSym(pVfs, handle, zProc);
  if( xInit==0 ){
    if( pzErrMsg ){
      nMsg += sqlite3Strlen30(zProc);
      *pzErrMsg = zErrmsg = sqlite3_malloc(nMsg);
      if( zErrmsg ){
        sqlite3_snprintf(nMsg, zErrmsg,
            "no entry point [%s] in shared library [%s]", zProc,zFile);
        sqlite3OsDlError(pVfs, nMsg-1, zErrmsg);
      }
      sqlite3OsDlClose(pVfs, handle);
    }
    return SQLITE_ERROR;
  }else if( xInit(db, &zErrmsg, &sqlite3Apis) ){
    if( pzErrMsg ){
      *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
    }
    sqlite3_free(zErrmsg);
    sqlite3OsDlClose(pVfs, handle);
    return SQLITE_ERROR;
  }

  /* Append the new shared library handle to the db->aExtension array. */
  aHandle = sqlite3DbMallocZero(db, sizeof(handle)*(db->nExtension+1));
  if( aHandle==0 ){
    return SQLITE_NOMEM;
  }
  if( db->nExtension>0 ){
    memcpy(aHandle, db->aExtension, sizeof(handle)*db->nExtension);
  }
  sqlite3DbFree(db, db->aExtension);
  db->aExtension = aHandle;

  db->aExtension[db->nExtension++] = handle;
  return SQLITE_OK;
}
Пример #6
0
bool  NEWGPU_init(void)
{
	gpuReset();
  xInit();
	return (0);
}
Пример #7
0
/*
** Attempt to load an SQLite extension library contained in the file
** zFile.  The entry point is zProc.  zProc may be 0 in which case a
** default entry point name (sqlite3_extension_init) is used.  Use
** of the default name is recommended.
**
** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong.
**
** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with 
** error message text.  The calling function should free this memory
** by calling sqlite3_free().
*/
int sqlite3_load_extension(
  sqlite3 *db,          /* Load the extension into this database connection */
  const char *zFile,    /* Name of the shared library containing extension */
  const char *zProc,    /* Entry point.  Use "sqlite3_extension_init" if 0 */
  char **pzErrMsg       /* Put error message here if not 0 */
){
#ifdef SQLITE_LIBRARY_TYPE
  SQLITE_LIBRARY_TYPE handle;
  int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
  char *zErrmsg = 0;
  SQLITE_LIBRARY_TYPE *aHandle;

  /* Ticket #1863.  To avoid a creating security problems for older
  ** applications that relink against newer versions of SQLite, the
  ** ability to run load_extension is turned off by default.  One
  ** must call sqlite3_enable_load_extension() to turn on extension
  ** loading.  Otherwise you get the following error.
  */
  if( (db->flags & SQLITE_LoadExtension)==0 ){
    if( pzErrMsg ){
      *pzErrMsg = sqlite3_mprintf("not authorized");
    }
    return SQLITE_ERROR;
  }

  if( zProc==0 ){
    zProc = "sqlite3_extension_init";
  }

  handle = SQLITE_OPEN_LIBRARY(zFile);
  if( handle==0 ){
    if( pzErrMsg ){
      *pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile);
    }
    return SQLITE_ERROR;
  }
  xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
                   SQLITE_FIND_SYMBOL(handle, zProc);
  if( xInit==0 ){
    if( pzErrMsg ){
       *pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]",
                                   zProc, zFile);
    }
    SQLITE_CLOSE_LIBRARY(handle);
    return SQLITE_ERROR;
  }else if( xInit(db, &zErrmsg, &sqlite3_apis) ){
    if( pzErrMsg ){
      *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
    }
    sqlite3_free(zErrmsg);
    SQLITE_CLOSE_LIBRARY(handle);
    return SQLITE_ERROR;
  }

  /* Append the new shared library handle to the db->aExtension array. */
  db->nExtension++;
  aHandle = sqliteMalloc(sizeof(handle)*db->nExtension);
  if( aHandle==0 ){
    return SQLITE_NOMEM;
  }
  if( db->nExtension>0 ){
    memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1));
  }
  sqliteFree(db->aExtension);
  db->aExtension = aHandle;

  ((SQLITE_LIBRARY_TYPE*)db->aExtension)[db->nExtension-1] = handle;
  return SQLITE_OK;
#else
  if( pzErrMsg ){
    *pzErrMsg = sqlite3_mprintf("extension loading is disabled");
  }
  return SQLITE_ERROR;
#endif
}