elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Rompecabezas de Bitcoin, Medio millón USD en premios


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar  (Leído 2,965 veces)
~

Desconectado Desconectado

Mensajes: 85


Ver Perfil WWW
SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar
« en: 4 Abril 2016, 21:07 pm »

filesopen Espera_aleatoria_minima Espera_aleatoria_maxima Nombre_base_de_datos Numero_de_fila_de_configuracion

Aquí tengo un programa de consola que escribí, que abre automáticamente y al azar archivos locales o URLs tomadas de una base de datos SQLite3 la cual maneja por sí misma usando la librería de Amalgamación de SQLite3.

Está completamente escrita en C y funciona bajo Windows (aunque tal vez pueda funcionar bajo Wine).

Aquí está el binario compilado:
FILESOPEN.EXE

Aquí se puede ver y aprender a escribir un programa en C básico para manejar una base de datos SQLite3:
>> Grabación de Texto para el Visor Aleatorio de Archivos y URLs <<

La estructura documentada y el uso de la base de datos está contenido en dicha grabación de la escritura del código.

Se puede hacer una prueba del funcionamiento con la siguiente base de datos que contiene más de 2 millones de nombres de dominio provenientes de la lista diaria de 1 millón de sitios más importantes de Alexa:
domains_alexaranks.db

Para correr el programa, solo se necesita el siguiente comando:
Código:
filesopen 1 1 domains_alexaranks.db 1



Aquí está el código principal (compilado bajo MinGW):
Código
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include "SQLite3-Amalgamation-3.12.0/sqlite3.h"
  5. #include "SQLite3-Amalgamation-3.12.0/sqlite3.c"
  6. #include "SQLite3-Amalgamation-3.12.0/sqlite3ext.h"
  7. #include <windows.h>
  8.  
  9. const char sqlite3_version[] = SQLITE_VERSION;
  10.  
  11. //Set default values for the number of table rows and for the current column
  12. //this last one will be selected at random:
  13. ///
  14. int SQLite3_Row_Ctr=1;
  15. int SQLite3_Current_Row=1;
  16.  
  17. sqlite3      *SQLite3_DB_Obj;
  18. sqlite3_stmt *SQLite3_State;
  19. int           SQLite3_DB_Res_Handle;
  20. char         *SQL_String;
  21. char         *SQLite3_ErrorMsg=NULL;
  22. char         *SQLite3_zTail_String;
  23.  
  24.  
  25.  
  26. //These are the default minimum and maximum number of minutes to wait
  27. //before trying to open other file/directory entry:
  28. ///
  29. int minwait=1;
  30. int maxwait=1;
  31.  
  32.  
  33. long minmax_rand(long min, long max)
  34. {
  35. return rand()%((max+1) - min) + min;
  36. }
  37.  
  38.  
  39. char *config_tablename;
  40. char *config_datarowname;
  41. char *config_idrowname;
  42. char *config_fileprotocol;
  43.  
  44. static int SQLite3_Callback_config(void *NotUsed, int argc, char **argv, char **azColName)
  45. {
  46. config_tablename=malloc(512);
  47. config_datarowname=malloc(512);
  48. config_idrowname=malloc(512);
  49. config_fileprotocol=malloc(512);
  50.  
  51. sprintf(config_tablename,"%s",argv[0]);
  52. sprintf(config_datarowname,"%s",argv[1]);
  53. sprintf(config_idrowname,"%s",argv[2]);
  54. sprintf(config_fileprotocol,"%s",argv[3]);
  55.  
  56.  
  57. printf("Getting database configuration...\n");
  58. printf("tablename=%s\ndatarowname=%s\nidrowname=%s\nfileprotocol=%s\n\n", config_tablename, config_datarowname, config_idrowname, config_fileprotocol);
  59.  
  60.  
  61. return 0;
  62. }
  63.  
  64.  
  65. static int SQLite3_Callback(void *NotUsed, int argc, char **argv, char **azColName)
  66. {
  67. int x=0;
  68. int requiredSize=0;
  69. int   openstrlen=0; char *cmd=NULL;
  70. char *cmd2=NULL;
  71. char *openstr="open";
  72. char *openstrW;
  73. char *explorerstr="C:\\WINDOWS\\explorer.exe";
  74. char *explorerstrW;
  75.  
  76. int   execres=0;
  77.  
  78. openstrW=malloc(131072);
  79. explorerstrW=malloc(131072);
  80. cmd=malloc(131072);
  81. cmd2=malloc(131072);
  82.  
  83. MultiByteToWideChar(
  84.                     (UINT)CP_UTF8,
  85.                     (DWORD)0,
  86.                     (LPCSTR)explorerstr,
  87.                     (int)-1,
  88.                     (LPWSTR)explorerstrW,
  89.                     (int)131072
  90.                    );
  91.  
  92. MultiByteToWideChar(
  93.                     (UINT)CP_UTF8,
  94.                     (DWORD)0,
  95.                     (LPCSTR)openstr,
  96.                     (int)-1,
  97.                     (LPWSTR)openstrW,
  98.                     (int)131072
  99.                    );
  100.  
  101.  
  102.  
  103.  
  104. for(x=0; x<argc; x++)
  105. {
  106.  snprintf(cmd,131072,"\"%s%s\"",config_fileprotocol,argv[x]);
  107.  
  108. /*
  109. int MultiByteToWideChar(
  110.   _In_      UINT   CodePage,
  111.   _In_      DWORD  dwFlags,
  112.   _In_      LPCSTR lpMultiByteStr,
  113.   _In_      int    cbMultiByte,
  114.   _Out_opt_ LPWSTR lpWideCharStr,
  115.   _In_      int    cchWideChar
  116. );
  117. */
  118.  MultiByteToWideChar(
  119.                      (UINT)CP_UTF8,
  120.                      (DWORD)0,
  121.                      (LPCSTR)cmd,
  122.                      (int)-1,
  123.                      (LPWSTR)cmd2,
  124.                      (int)131072
  125.                     );
  126.  
  127.  printf("%ld: %s\n\n", SQLite3_Current_Row, cmd);
  128.  
  129. /*
  130. HINSTANCE ShellExecute(
  131.   _In_opt_ HWND    hwnd,
  132.   _In_opt_ LPCTSTR lpOperation,
  133.   _In_     LPCTSTR lpFile,
  134.   _In_opt_ LPCTSTR lpParameters,
  135.   _In_opt_ LPCTSTR lpDirectory,
  136.   _In_     INT     nShowCmd
  137. );
  138.  
  139. */
  140.  
  141.  execres=(int)ShellExecuteW(
  142.                (HWND)0,
  143.                (LPCWSTR)openstrW,
  144.                (LPCWSTR)explorerstrW,
  145.                (LPCWSTR)cmd2,
  146.                (LPCWSTR)NULL,
  147.                (INT)SW_SHOWNORMAL
  148.               );
  149.  
  150.  
  151.  switch(execres)
  152.  {
  153.   case 0:
  154.   printf("exec: 0");
  155.   break;
  156.  
  157.   case ERROR_BAD_FORMAT:
  158.    printf("exec: ERROR_BAD_FORMAT");
  159.   break;
  160.  
  161.   case SE_ERR_ACCESSDENIED:
  162.    printf("exec: SE_ERR_ACCESSDENIED");
  163.   break;
  164.  
  165.   case SE_ERR_ASSOCINCOMPLETE:
  166.    printf("exec: SE_ERR_ASSOCINCOMPLETE");
  167.   break;
  168.  
  169.   case SE_ERR_DDEBUSY:
  170.    printf("exec: SE_ERR_DDEBUSY");
  171.   break;
  172.  
  173.   case SE_ERR_DDEFAIL:
  174.    printf("exec: SE_ERR_DDEFAIL");
  175.   break;
  176.  
  177.   case SE_ERR_DDETIMEOUT:
  178.    printf("exec: SE_ERR_DDETIMEOUT");
  179.   break;
  180.  
  181.   case SE_ERR_DLLNOTFOUND:
  182.    printf("exec: SE_ERR_DLLNOTFOUND");
  183.   break;
  184.  
  185.   case SE_ERR_FNF:
  186.    printf("exec: SE_ERR_FNF");
  187.   break;
  188.  
  189.   case SE_ERR_NOASSOC:
  190.    printf("exec: SE_ERR_NOASSOC");
  191.   break;
  192.  
  193.   case SE_ERR_OOM:
  194.    printf("exec: SE_ERR_OOM");
  195.   break;
  196.  
  197.   case SE_ERR_SHARE:
  198.    printf("exec: SE_ERR_SHARE");
  199.   break;
  200.  }
  201.  
  202.  
  203.  sleep(60*(int)minmax_rand(minwait,maxwait));
  204. }
  205.  
  206. free(cmd);
  207. free(cmd2);
  208. free(openstrW);
  209. free(explorerstrW);
  210.  
  211.  
  212. return 0;
  213. }
  214.  
  215.  
  216. static int SQLite3_Callback2(void *NotUsed, int argc, char **argv, char **azColName)
  217. {
  218. SQLite3_Row_Ctr=atol(argv[0]);
  219. return SQLite3_Row_Ctr;
  220. }
  221.  
  222.  
  223.  
  224. void clear_state()
  225. {
  226. //NOTE: This is for the good practice of not leaving
  227. //      freeing of resources or other default operations
  228. //      at their default state but accelerate and ensure
  229. //      the global sanity of the environment and the program
  230. //      by specifying every operation exactly as we want it:
  231. ///
  232. sqlite3_finalize(SQLite3_State);
  233. sqlite3_close(SQLite3_DB_Obj);
  234. free(SQL_String);
  235.  
  236. }
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243. int main(int argc, char *argv[])
  244. {
  245. atexit(clear_state);
  246. SQL_String=malloc(4096);
  247.  
  248.  
  249.  
  250. if(argc>=5)
  251. {
  252.  if(!(minwait=atoi(argv[1])))minwait=1;
  253.  if(!(maxwait=atoi(argv[2])))maxwait=1;
  254. }
  255.  else
  256.  {
  257.   printf("Usage: filesopen min_minutes max_minutes SQLITE3_Database_Path Database_Config_ID\n\n");
  258.   return -2;
  259.  }
  260.  
  261.  
  262. //Open the database and see if it was successful. If not, just exit the program:
  263. ///
  264.  SQLite3_DB_Res_Handle=sqlite3_open(argv[3], &SQLite3_DB_Obj);
  265.  
  266.  if(SQLite3_DB_Res_Handle!=SQLITE_OK)
  267.  {
  268.   printf("Error opening database\n\n");
  269.   return -1;
  270.  }
  271.  
  272.  
  273.  //Get the configuration of the database to use the proper table and field names,
  274.  //as well as basic formatting for the data:
  275.  ///
  276.   snprintf(SQL_String, 4096, "SELECT tablename,datarowname,idrowname,fileprotocol FROM config WHERE configid=%s LIMIT 1", argv[4]);
  277.   SQLite3_DB_Res_Handle=sqlite3_exec(
  278.                                      SQLite3_DB_Obj,
  279.                                      SQL_String,
  280.                                      SQLite3_Callback_config,
  281.                                      SQLite3_zTail_String,
  282.                                      &SQLite3_ErrorMsg
  283.                                     );
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290.  
  291. //Get all columns for the first time to count them.
  292. //Its callback will return the count in SQLite3_Row_Ctr:
  293. ///
  294.  snprintf(SQL_String, 4096, "SELECT COALESCE(MAX(%s)+1, 0) FROM %s", config_idrowname, config_tablename);
  295.  SQLite3_DB_Res_Handle=sqlite3_exec(
  296.                                     SQLite3_DB_Obj,
  297.                                     SQL_String,
  298.                                     SQLite3_Callback2,
  299.                                     SQLite3_zTail_String,
  300.                                     &SQLite3_ErrorMsg
  301.                                    );
  302.  
  303. printf("Cycling through %ld files...\n", SQLite3_Row_Ctr);
  304.  
  305.  
  306. while(1)
  307. {
  308.  //Go to next row (selected randomly):
  309.  ///
  310.   SQLite3_Current_Row=minmax_rand(1, SQLite3_Row_Ctr);
  311.  
  312.  
  313.  //Get random files to open:
  314.  ///
  315.   snprintf(SQL_String, 4096, "SELECT %s FROM %s WHERE %s=%ld LIMIT 1", config_datarowname, config_tablename, config_idrowname, SQLite3_Current_Row);
  316.   SQLite3_DB_Res_Handle=sqlite3_exec(
  317.                                      SQLite3_DB_Obj,
  318.                                      SQL_String,
  319.                                      SQLite3_Callback,
  320.                                      SQLite3_zTail_String,
  321.                                      &SQLite3_ErrorMsg
  322.                                     );
  323.  
  324.  
  325.  //If there was a database error or fault, just end:
  326.  ///
  327.   if(SQLite3_ErrorMsg)return 0;
  328. }
  329.  
  330.  
  331. return 0;
  332. }
  333.  
  334.  


En línea

Donar con PayPal para que siga trabajando:
https://www.ebay.com/usr/udocproject3

Streams en vivo de programación:
PC 1 - PC 2

http://www.youtube.com/@AltComp126/streams
fary


Desconectado Desconectado

Mensajes: 1.061



Ver Perfil WWW
Re: SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar
« Respuesta #1 en: 5 Abril 2016, 09:33 am »

Es bueno tener esta serie de ejemplos,  gracias:)


En línea

Un byte a la izquierda.
HardForo

Desconectado Desconectado

Mensajes: 219


HardForo.com


Ver Perfil WWW
Re: SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar
« Respuesta #2 en: 15 Abril 2016, 02:01 am »

Bueno, lo he probado y no me ha funcionado  :-\

Código
  1. g++ -o SQLite3-Amalgamation_example SQLite3-Amalgamation_example.c
  2.  

Me genera todo este choclo de errores:

Citar
In file included from SQLite3-Amalgamation_example.c:5:0:

c:\mingw\include\sqlite3.c: In function 'void strftimeFunc(sqlite3_context*, int, sqlite3_value**)':
c:\mingw\include\sqlite3.c:17689:40: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     z = sqlite3DbMallocRawNN(db, (int)n);
                                        ^
c:\mingw\include\sqlite3.c: In function 'void* sqlite3MemMalloc(int)':
c:\mingw\include\sqlite3.c:18592:7: error: invalid conversion from 'void*' to 'sqlite3_int64* {aka long long int*}' [-
ermissive]
   p = SQLITE_MALLOC( nByte+8 );
       ^
c:\mingw\include\sqlite3.c: In function 'void* sqlite3MemRealloc(void*, int)':
c:\mingw\include\sqlite3.c:18665:7: error: invalid conversion from 'void*' to 'sqlite3_int64* {aka long long int*}' [-
ermissive]
   p = SQLITE_REALLOC(p, nByte+8 );
       ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'sqlite3_mutex* winMutexAlloc(int)':
c:\mingw\include\sqlite3.c:21842:41: error: invalid conversion from 'void*' to 'sqlite3_mutex*' [-fpermissive]
       p = sqlite3MallocZero( sizeof(*p) );
                                         ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3DbStrDup(sqlite3*, const char*)':
c:\mingw\include\sqlite3.c:22757:39: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zNew = sqlite3DbMallocRaw(db, (int)n);
                                       ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3DbStrNDup(sqlite3*, const char*, u64)':
c:\mingw\include\sqlite3.c:22770:38: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zNew = sqlite3DbMallocRawNN(db, n+1);
                                      ^
c:\mingw\include\sqlite3.c: In function 'void sqlite3VXPrintf(StrAccum*, const char*, va_list)':
c:\mingw\include\sqlite3.c:23266:47: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
           zOut = zExtra = sqlite3Malloc( nOut );
                                               ^
c:\mingw\include\sqlite3.c:23377:71: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
               = sqlite3Malloc( MAX(e2,0)+(i64)precision+(i64)width+15 );
                                                                       ^
c:\mingw\include\sqlite3.c:23525:29: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
         if( isnull ) escarg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
                             ^
c:\mingw\include\sqlite3.c:23533:45: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
           bufpt = zExtra = sqlite3Malloc( n );
                                             ^
c:\mingw\include\sqlite3.c:23568:48: error: cannot convert 'SrcList::SrcList_item*' to 'SrcList_item*' in initializati

         struct SrcList_item *pItem = &pSrc->a[k];
                                                ^
c:\mingw\include\sqlite3.c:23571:18: error: invalid use of incomplete type 'struct SrcList_item'
         if( pItem->zDatabase ){
                  ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:14473:59: error: forward declaration of 'struct SrcList_item'
 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
                                                           ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:23572:49: error: invalid use of incomplete type 'struct SrcList_item'
           sqlite3StrAccumAppendAll(pAccum, pItem->zDatabase);
                                                 ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:14473:59: error: forward declaration of 'struct SrcList_item'
 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
                                                           ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:23575:47: error: invalid use of incomplete type 'struct SrcList_item'
         sqlite3StrAccumAppendAll(pAccum, pItem->zName);
                                               ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:14473:59: error: forward declaration of 'struct SrcList_item'
 SQLITE_PRIVATE int sqlite3IndexedByLookup(Parse *, struct SrcList_item *);
                                                           ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'int sqlite3StrAccumEnlarge(StrAccum*, int)':
c:\mingw\include\sqlite3.c:23638:53: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
       zNew = sqlite3DbRealloc(p->db, zOld, p->nAlloc);
                                                     ^
c:\mingw\include\sqlite3.c:23640:47: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
       zNew = sqlite3_realloc64(zOld, p->nAlloc);
                                               ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3StrAccumFinish(StrAccum*)':
c:\mingw\include\sqlite3.c:23722:55: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
       p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
                                                       ^
c:\mingw\include\sqlite3.c: In function 'void sqlite3_randomness(int, void*)':
c:\mingw\include\sqlite3.c:24479:25: error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]
   unsigned char *zBuf = pBuf;
                         ^
c:\mingw\include\sqlite3.c: In function 'int sqlite3ThreadCreate(SQLiteThread**, void* (*)(void*), void*)':
c:\mingw\include\sqlite3.c:24737:31: error: invalid conversion from 'void*' to 'SQLiteThread*' [-fpermissive]
   p = sqlite3Malloc(sizeof(*p));
                               ^
c:\mingw\include\sqlite3.c: In function 'int sqlite3VdbeMemTranslate(Mem*, u8)':
c:\mingw\include\sqlite3.c:25132:42: error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]
   zOut = sqlite3DbMallocRaw(pMem->db, len);
                                          ^
c:\mingw\include\sqlite3.c: In function 'char* sqlite3Utf16to8(sqlite3*, const void*, int, u8)':
c:\mingw\include\sqlite3.c:25299:56: error: invalid conversion from 'const void*' to 'const char*' [-fpermissive]
   sqlite3VdbeMemSetStr(&m, z, nByte, enc, SQLITE_STATIC);
                                                        ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c:16306:20: note: initializing argument 2 of 'int sqlite3VdbeMemSetStr(Mem*, const char*, int
u8, void (*)(void*))'
 SQLITE_PRIVATE int sqlite3VdbeMemSetStr(Mem*, const char*, int, u8, void(*)(void*));
                    ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'int sqlite3Utf16ByteLen(const void*, int)':
c:\mingw\include\sqlite3.c:25318:28: error: invalid conversion from 'const void*' to 'const unsigned char*' [-fpermiss
e]
   unsigned char const *z = zIn;
                            ^
c:\mingw\include\sqlite3.c: In function 'void insertElement(Hash*, _ht*, HashElem*)':
c:\mingw\include\sqlite3.c:26935:19: error: invalid use of incomplete type 'struct _ht'
     pHead = pEntry->count ? pEntry->chain : 0;
                   ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:26935:35: error: invalid use of incomplete type 'struct _ht'
     pHead = pEntry->count ? pEntry->chain : 0;
                                   ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:26936:11: error: invalid use of incomplete type 'struct _ht'
     pEntry->count++;
           ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:26937:11: error: invalid use of incomplete type 'struct _ht'
     pEntry->chain = pNew;
           ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'int rehash(Hash*, unsigned int)':
c:\mingw\include\sqlite3.c:26967:33: error: invalid application of 'sizeof' to incomplete type '_ht'
   if( new_size*sizeof(struct _ht)>SQLITE_MALLOC_SOFT_LIMIT ){
                                 ^
c:\mingw\include\sqlite3.c:26968:58: error: invalid application of 'sizeof' to incomplete type '_ht'
     new_size = SQLITE_MALLOC_SOFT_LIMIT/sizeof(struct _ht);
                                                          ^
c:\mingw\include\sqlite3.c:26982:67: error: invalid application of 'sizeof' to incomplete type '_ht'
   new_ht = (struct _ht *)sqlite3Malloc( new_size*sizeof(struct _ht) );
                                                                   ^
c:\mingw\include\sqlite3.c:26987:10: error: cannot convert '_ht*' to 'Hash::_ht*' in assignment
   pH->ht = new_ht;
          ^
c:\mingw\include\sqlite3.c:26988:70: error: invalid application of 'sizeof' to incomplete type '_ht'
   pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
                                                                      ^
c:\mingw\include\sqlite3.c:26989:47: error: invalid application of 'sizeof' to incomplete type '_ht'
   memset(new_ht, 0, new_size*sizeof(struct _ht));
                                               ^
c:\mingw\include\sqlite3.c:26993:32: error: invalid use of incomplete type 'struct _ht'
     insertElement(pH, &new_ht[h], elem);
                                ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'HashElem* findElementWithHash(const Hash*, const char*, unsigned int*)':
c:\mingw\include\sqlite3.c:27014:12: error: cannot convert 'Hash::_ht*' to '_ht*' in assignment
     pEntry = &pH->ht[h];
            ^
c:\mingw\include\sqlite3.c:27015:18: error: invalid use of incomplete type 'struct _ht'
     elem = pEntry->chain;
                  ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:27016:19: error: invalid use of incomplete type 'struct _ht'
     count = pEntry->count;
                   ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'void removeElementGivenHash(Hash*, HashElem*, unsigned int)':
c:\mingw\include\sqlite3.c:27051:12: error: cannot convert 'Hash::_ht*' to '_ht*' in assignment
     pEntry = &pH->ht[h];
            ^
c:\mingw\include\sqlite3.c:27052:15: error: invalid use of incomplete type 'struct _ht'
     if( pEntry->chain==elem ){
               ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:27053:13: error: invalid use of incomplete type 'struct _ht'
       pEntry->chain = elem->next;
             ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c:27055:11: error: invalid use of incomplete type 'struct _ht'
     pEntry->count--;
           ^
c:\mingw\include\sqlite3.c:26930:10: error: forward declaration of 'struct _ht'
   struct _ht *pEntry,    /* The entry into which pNew is inserted */
          ^
c:\mingw\include\sqlite3.c: In function 'void* sqlite3HashInsert(Hash*, const char*, void*)':
c:\mingw\include\sqlite3.c:27125:54: error: cannot convert 'Hash::_ht*' to '_ht*' for argument '2' to 'void insertElem
t(Hash*, _ht*, HashElem*)'
   insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);
                                                      ^
c:\mingw\include\sqlite3.c: In function 'WCHAR* winUtf8ToUnicode(const char*)':
c:\mingw\include\sqlite3.c:36937:69: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
   zWideFilename = sqlite3MallocZero( nChar*sizeof(zWideFilename[0]) );
                                                                     ^
c:\mingw\include\sqlite3.c: In function 'char* winUnicodeToUtf8(LPCWSTR)':
c:\mingw\include\sqlite3.c:36962:40: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zFilename = sqlite3MallocZero( nByte );
                                        ^
c:\mingw\include\sqlite3.c: In function 'WCHAR* winMbcsToUnicode(const char*)':
c:\mingw\include\sqlite3.c:36992:69: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
   zMbcsFilename = sqlite3MallocZero( nByte*sizeof(zMbcsFilename[0]) );
                                                                     ^
c:\mingw\include\sqlite3.c: In function 'char* winUnicodeToMbcs(LPCWSTR)':
c:\mingw\include\sqlite3.c:37021:40: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zFilename = sqlite3MallocZero( nByte );
                                        ^
c:\mingw\include\sqlite3.c: In function 'int winOpenSharedMemory(winFile*)':
c:\mingw\include\sqlite3.c:38920:37: error: invalid conversion from 'void*' to 'winShm*' [-fpermissive]
   p = sqlite3MallocZero( sizeof(*p) );
                                     ^
c:\mingw\include\sqlite3.c:38923:60: error: invalid conversion from 'void*' to 'winShmNode*' [-fpermissive]
   pNew = sqlite3MallocZero( sizeof(*pShmNode) + nName + 17 );
                                                            ^
c:\mingw\include\sqlite3.c: In function 'int winShmMap(sqlite3_file*, int, int, int, volatile void**)':
c:\mingw\include\sqlite3.c:39255:54: error: invalid use of incomplete type 'struct winShmMap(sqlite3_file*, int, int,
t, volatile void**)::ShmRegion'
         pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
                                                      ^
c:\mingw\include\sqlite3.c:39220:12: error: forward declaration of 'struct winShmMap(sqlite3_file*, int, int, int, vol
ile void**)::ShmRegion'
     struct ShmRegion *apNew;           /* New aRegion[] array */
            ^
c:\mingw\include\sqlite3.c:39255:55: error: invalid application of 'sizeof' to incomplete type 'winShmMap(sqlite3_file
 int, int, int, volatile void**)::ShmRegion'
         pShmNode->aRegion, (iRegion+1)*sizeof(apNew[0])
                                                       ^
c:\mingw\include\sqlite3.c:39261:23: error: cannot convert 'winShmMap(sqlite3_file*, int, int, int, volatile void**)::
mRegion*' to 'winShmNode::ShmRegion*' in assignment
     pShmNode->aRegion = apNew;
                       ^
c:\mingw\include\sqlite3.c: In function 'int winGetTempname(sqlite3_vfs*, char**)':
c:\mingw\include\sqlite3.c:39685:34: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zBuf = sqlite3MallocZero( nBuf );
                                  ^
c:\mingw\include\sqlite3.c:39794:62: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
     LPWSTR zWidePath = sqlite3MallocZero( nMax*sizeof(WCHAR) );
                                                              ^
c:\mingw\include\sqlite3.c:39822:47: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     char *zMbcsPath = sqlite3MallocZero( nMax );
                                               ^
c:\mingw\include\sqlite3.c: In function 'int winDelete(sqlite3_vfs*, const char*, int)':
c:\mingw\include\sqlite3.c:40254:45: error: invalid conversion from 'void*' to 'LPCWSTR {aka const wchar_t*}' [-fpermi
ive]
       attr = osGetFileAttributesW(zConverted);
                                             ^
c:\mingw\include\sqlite3.c:40270:36: error: invalid conversion from 'void*' to 'LPCWSTR {aka const wchar_t*}' [-fpermi
ive]
       if ( osDeleteFileW(zConverted) ){
                                    ^
c:\mingw\include\sqlite3.c:40283:45: error: invalid conversion from 'void*' to 'LPCSTR {aka const char*}' [-fpermissiv

       attr = osGetFileAttributesA(zConverted);
                                             ^
c:\mingw\include\sqlite3.c:40298:36: error: invalid conversion from 'void*' to 'LPCSTR {aka const char*}' [-fpermissiv

       if ( osDeleteFileA(zConverted) ){
                                    ^
c:\mingw\include\sqlite3.c: In function 'int winFullPathname(sqlite3_vfs*, const char*, int, char*)':
c:\mingw\include\sqlite3.c:40573:55: error: invalid conversion from 'void*' to 'LPWSTR {aka wchar_t*}' [-fpermissive]
     zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
                                                       ^
c:\mingw\include\sqlite3.c:40599:55: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     zTemp = sqlite3MallocZero( nByte*sizeof(zTemp[0]) );
                                                       ^
c:\mingw\include\sqlite3.c: In function 'void (* winDlSym(sqlite3_vfs*, void*, const char*))()':
c:\mingw\include\sqlite3.c:40679:44: error: invalid conversion from 'HANDLE {aka void*}' to 'HMODULE {aka HINSTANCE__*
 [-fpermissive]
   proc = osGetProcAddressA((HANDLE)pH, zSym);
                                            ^
c:\mingw\include\sqlite3.c: In function 'void winDlClose(sqlite3_vfs*, void*)':
c:\mingw\include\sqlite3.c:40686:32: error: invalid conversion from 'HANDLE {aka void*}' to 'HMODULE {aka HINSTANCE__*
 [-fpermissive]
   osFreeLibrary((HANDLE)pHandle);
                                ^
c:\mingw\include\sqlite3.c: In function 'Bitvec* sqlite3BitvecCreate(u32)':
c:\mingw\include\sqlite3.c:41105:37: error: invalid conversion from 'void*' to 'Bitvec*' [-fpermissive]
   p = sqlite3MallocZero( sizeof(*p) );
                                     ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'int sqlite3BitvecSet(Bitvec*, u32)':
c:\mingw\include\sqlite3.c:41200:21: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissiv

     u32 *aiValues = sqlite3StackAllocRaw(0, sizeof(p->u.aHash));
                     ^
In file included from SQLite3-Amalgamation_example.c:5:0:
c:\mingw\include\sqlite3.c: In function 'void sqlite3BitvecClear(Bitvec*, u32, void*)':
c:\mingw\include\sqlite3.c:41243:21: error: invalid conversion from 'void*' to 'u32* {aka unsigned int*}' [-fpermissiv

     u32 *aiValues = pBuf;
                     ^
c:\mingw\include\sqlite3.c: In function 'int sqlite3BitvecBuiltinTest(int, int*)':
c:\mingw\include\sqlite3.c:41334:40: error: invalid conversion from 'void*' to 'unsigned char*' [-fpermissive]
   pV = sqlite3MallocZero( (sz+7)/8 + 1 );
                                        ^
c:\mingw\include\sqlite3.c: In function 'int pcache1InitBulk(PCache1*)':
c:\mingw\include\sqlite3.c:42379:9: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zBulk = pCache->pBulk = sqlite3Malloc( szBulk );
         ^
c:\mingw\include\sqlite3.c: In function 'RowSet* sqlite3RowSetInit(sqlite3*, void*, unsigned int)':
c:\mingw\include\sqlite3.c:43475:5: error: invalid conversion from 'void*' to 'RowSet*' [-fpermissive]
   p = pSpace;
     ^
c:\mingw\include\sqlite3.c: In function 'RowSetEntry* rowSetEntryAlloc(RowSet*)':
c:\mingw\include\sqlite3.c:43519:53: error: invalid conversion from 'void*' to 'RowSetChunk*' [-fpermissive]
     pNew = sqlite3DbMallocRawNN(p->db, sizeof(*pNew));
                                                     ^
c:\mingw\include\sqlite3.c: In function 'int pager_delmaster(Pager*, const char*)':
c:\mingw\include\sqlite3.c:46467:65: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
   zMasterJournal = sqlite3Malloc(nMasterJournal + nMasterPtr + 1);
                                                                 ^
c:\mingw\include\sqlite3.c: In function 'int readDbPage(PgHdr*, u32)':
c:\mingw\include\sqlite3.c:46908:68: error: invalid conversion from 'void*' to 'u8* {aka unsigned char*}' [-fpermissiv

     rc = sqlite3WalReadFrame(pPager->pWal, iFrame, pgsz, pPg->pData);
                                                                    ^
c:\mingw\include\sqlite3.c:43946:20: note: initializing argument 4 of 'int sqlite3WalReadFrame(Wal*, u32, int, u8*)'
 SQLITE_PRIVATE int sqlite3WalReadFrame(Wal *, u32, int, u8 *);

Aun asi no puedo:

Código
  1. g++ -Wall -Werror -pedantic -std=c++11 -pthread -o SQLite3-Amalgamati
  2. on_example SQLite3-Amalgamation_example.c -Wall -Werror -pedantic -std=c++11 -pthread
En línea

HardForo:  foro de Hardware y programación

Se buscan Mods y colaboradores *
MAFUS


Desconectado Desconectado

Mensajes: 1.603



Ver Perfil
Re: SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar
« Respuesta #3 en: 15 Abril 2016, 07:26 am »

Esto es porque lo quieres compilar con C++. C, no se queja tanto por la igualdad en tipos de datos, C++ es muy estricto en eso.
malloc, calloc, realloc devuelven void*. C al ver esto se fija en el tipo de dato del lvalue y si puede hacer la conversión, la hace; en cámbio C++ no hace ese paso y entiende que el programador, al no hacer el cast explícito, se ha equivocado.
Código:
int *p = malloc (sizeof (int));
Funciona en C pero en C++ necesita
Código:
int *p = (int*) malloc (sizeof(int));
En línea

HardForo

Desconectado Desconectado

Mensajes: 219


HardForo.com


Ver Perfil WWW
Re: SQLite3 Amalgamation y C: Visor de Archivos y URLs al Azar
« Respuesta #4 en: 15 Abril 2016, 14:57 pm »

@MAFUS:  me sirvió mucho la explicación  ;-)

Me la pasaba haciendo castings y supuestamente estaba jugando en C y ahora SI pude compilar sin errores el archivo, muchas gracias, me has salvado otra vez!

« Última modificación: 15 Abril 2016, 15:06 pm por boctulus » En línea

HardForo:  foro de Hardware y programación

Se buscan Mods y colaboradores *
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Azar -Nombres batch al azar -please ayuda
Scripting
usuario oculto 4 4,081 Último mensaje 16 Diciembre 2008, 19:44 pm
por SmartGenius
SQLite3
Programación Visual Basic
cobein 3 3,449 Último mensaje 13 Octubre 2009, 23:02 pm
por Karcrack
Un estudio demuestra que los acortadores de URLs pueden exponer tus archivos....
Noticias
wolfbcn 0 918 Último mensaje 15 Abril 2016, 18:11 pm
por wolfbcn
visor archivos
Software
freddy98 6 1,307 Último mensaje 25 Mayo 2016, 17:28 pm
por freddy98
Visor archivos emails .eml
Dudas Generales
OssoH 3 2,420 Último mensaje 28 Enero 2022, 15:23 pm
por Songoku
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines