Schplurtzeries
Le wiki de schplurtz
Dokuwiki

Différences

Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.

Lien vers cette vue

schplurtziel:sqlite3-ipv4-ext [2011/06/20 21:56]
127.0.0.1 modification externe
schplurtziel:sqlite3-ipv4-ext [2018/04/16 19:51] (Version actuelle)
ztrulphcs [Can I use the patch for other versions ?]
Ligne 1: Ligne 1:
 ====== sqlite ipv4 extension ====== ====== sqlite ipv4 extension ======
  
-date this document was last edited : 2011-06-19+date this document was last edited : Mon Apr 16 2018
  
 date the C source was last edited : 2011-06-19 date the C source was last edited : 2011-06-19
  
-you should find the latest version of this file here : http://schplurtz.free.fr/wiki/schplurtziel/sqlite3-ipv4-ext+You should find the latest version of this file here : http://schplurtz.free.fr/wiki/schplurtziel/sqlite3-ipv4-ext
  
 ===== What is it ? ===== ===== What is it ? =====
  
-This is an **extension** for sqlite3 that adds two simple functions named ''isinnet'' and ''isinrange'' to the set of SQL functions. those functions deal with IP v4 addresses.+This is an **extension** for [[http://www.sqlite.org/|sqlite3]] that adds two simple functions named ''isinnet'' and ''isinrange'' to the set of SQL functions. those functions deal with IP v4 addresses.
  
 With the ''isinnet'' function, you can test if an ip address is within a network, or even if two ips are in the same subnet, just by using SQL commands like these : With the ''isinnet'' function, you can test if an ip address is within a network, or even if two ips are in the same subnet, just by using SQL commands like these :
Ligne 79: Ligne 79:
 </file> </file>
  
-You can also test if an address is within a certain range. A range is defined by a start address and a stop address. Note that the start address may be //smaller// or //greater// than the stop address.+With the ''isinrange'' function, you can also test if an address is within a certain range. A range is defined by a start address and a stop address. Note that the start address may be //smaller// or //greater// than the stop address.
  
 <file sql try-range.sql> <file sql try-range.sql>
Ligne 164: Ligne 164:
 ===== what version of sqlite is it for ? ===== ===== what version of sqlite is it for ? =====
  
-This extension was first written for sqlite 3.5.9, and it works for me with sqlite3 to 3.7.6.3 (current sqlite3 version on Sun Jun 12 2011).+This extension was first written for sqlite 3.5.9, and it works for me with sqlite3 3.23.(current [[https://brew.sh/|brew]] sqlite3 version as of Mon Apr 16 2018).
  
 Now, there are 2 things in the archive file : Now, there are 2 things in the archive file :
  
-  - a dynamic extension that you can load fom within your programs or from within the CLI sqlite3 itself (if it has been compile with the load extension enabled).+  - a dynamic extension that you can load from within your programs or from within the CLI sqlite3 itself (if it has been compiled with the <<load extension>> feature enabled).
     * It should work with **any** sqlite3 version that supports loadable extensions.     * It should work with **any** sqlite3 version that supports loadable extensions.
-  - some patches for sqlite source files. When the patch is applied, the functions ''isinnet'' and ''isinrange'' are  added to the core functions that sqlite understands. I don't update these patches very often because don't really need them (the loadable extension suits my need). So, there are only a few patches available. To use this, you will have to download the entire sqlite source archive and completely rebuild it. But once it is done, there is no need to load an extension. The patch are against the so called //amalgamation// source code.+  - some patches for sqlite source files. When the patch is applied, the functions ''isinnet'' and ''isinrange'' are  added to the core functions that sqlite understands. I don't update these patches very often because don't really need them (the loadable extension suits my need). So, there are only a few patches available. To use this, you will have to download the entire sqlite source archive and completely rebuild it. But once it is done, there is no need to load an extension. The patches are against the autoconf //amalgamation// source code.
  
 Please, note that in either case, this little extension is only distributed as source code. You will have to compile it. Please, note that in either case, this little extension is only distributed as source code. You will have to compile it.
Ligne 178: Ligne 178:
   - ip addresses are simply stored as strings   - ip addresses are simply stored as strings
   - netmasks are stored as strings, too   - netmasks are stored as strings, too
-  - netmask, if specified as a number of bits, may be stored as strings OR integer+  - netmask, if specified as a number of bits, may be stored as strings OR integer (sqlite does not really care anyway).
   - each time the function ''isinnet'' or ''isinrange'' is called it tries to parse the ips and netmask, into 32 bits numbers   - each time the function ''isinnet'' or ''isinrange'' is called it tries to parse the ips and netmask, into 32 bits numbers
   - If there is an error : numbers are too big, or the format is not correct, then the functions return NULL   - If there is an error : numbers are too big, or the format is not correct, then the functions return NULL
   - Otherwise   - Otherwise
     * ''isinnet'' returns 1 if (address & mask) = (network & mask),\\ it returns 0 (zero) if not.      * ''isinnet'' returns 1 if (address & mask) = (network & mask),\\ it returns 0 (zero) if not. 
-    * ''isinrange'' returns 1 if (start <= address && address <= stop ) or (stop <= address && address <= start),\\ it returns 0 (zero) if not. +    * ''isinrange'' %%returns 1 if (start <= address && address <= stop ) or (stop <= address && address <= start),%%\\ it returns 0 (zero) if not. 
  
 since isinnet computes (address & mask) = (network & mask), it is possible to check if two addresses are in the same subnet with this function. since isinnet computes (address & mask) = (network & mask), it is possible to check if two addresses are in the same subnet with this function.
Ligne 211: Ligne 211:
 </file> </file>
  
-The latter is of course a bad idea, but it should work (not tested)+The latter is of course a bad idea, but it should work (not tested).
  
 the first two are the fastest because they require less parsing than the others. the first two are the fastest because they require less parsing than the others.
Ligne 227: Ligne 227:
 ==== Makefile.MacOSX ==== ==== Makefile.MacOSX ====
  
-This is a makefile for building the dynamic extension under MacOSX (tested under 10.5 and 10.6)+This is a makefile for building the dynamic extension under MacOSX (tested under 10.5 and 10.6 10.9 and recently 10.13.4)
  
-Fisrt edit this file and set the INCLUDE=-I/... line to a directory that contains the file ''sqlite3ext.h''+Fisrt edit this file and set the INCLUDE=-I/... line to a directory that contains the file ''sqlite3ext.h''. For example, if you installed sqlite3 via [[https://brew.sh/|brew]], the line could read ''INCLUDE = -I/usr/local/opt/sqlite/include''
  
 Then, run Then, run
Ligne 235: Ligne 235:
   make -f Makefile.MacOSX   make -f Makefile.MacOSX
  
-and you should obtain a file named libsqliteipv4.dylib. This file is the extension you are going to load.+and you should obtain a file named libsqliteipv4.dylib. This file is the extension you are going to load. Feel free to copy this file wherever you see fit.
  
 ==== Makefile.linux ==== ==== Makefile.linux ====
Ligne 254: Ligne 254:
 This is the source file of the extension. This is the source file of the extension.
  
-==== ipv4-sqlite-3.7.6.3-amalgamation.patch ====+==== ipv4-sqlite-3.7.10.0-amalgamation.patch ====
  
-This is a patch for the file sqlite-autoconf-3070603/sqlite3.c of sqlite-3.7.6.3. Once applied, it allows to build sqlite with the ''isinnet'' and ''isinrange'' functions. There is then no need to load an extension. If you want to incorporate SQLite code into a wider program, then the functions ''isinnet'' and ''isinrange'' will also go into you wider program, provided you ''#define SQLITE_IPV4_EXT_FUNC 1'' somewhere in your source.+^This file outdated and probably completely unusable ^ 
 + 
 +This is a patch for the file sqlite-autoconf-3071000/sqlite3.c of sqlite-3.7.10.0. Once applied, it allows to build sqlite with the ''isinnet'' and ''isinrange'' functions. There is then no need to load an extension. If you want to incorporate SQLite code into a wider program, then the functions ''isinnet'' and ''isinrange'' will also go into you wider program, provided you ''#define SQLITE_IPV4_EXT_FUNC 1'' somewhere in your source.
  
 Here are the steps you must follow to build sqlite with builtin ''isinnet'' and ''isinrange'' SQL functions. Here are the steps you must follow to build sqlite with builtin ''isinnet'' and ''isinrange'' SQL functions.
-  * download sqlite-autoconf-3070603.tar.gz from http://sqlite.org/download.html +  * download sqlite-autoconf-3071000.tar.gz from http://sqlite.org/download.html 
-  * untar the archive with something like <code bash>gzip -cd sqlite-autoconf-3070603.tar.gz | tar xf -</code> +  * untar the archive with something like <code bash>gzip -cd sqlite-autoconf-3071000.tar.gz | tar xf -</code> 
-  * put the patch file in the newly created directory ''sqlite-autoconf-3070603'' +  * put the patch file in the newly created directory ''sqlite-autoconf-3071000'' 
-  * then cd into the ''sqlite-autoconf-3070603'' directory and apply the patch.<code bash> +  * then cd into the ''sqlite-autoconf-3071000'' directory and apply the patch.<code bash> 
-cd sqlite-autoconf-3070603 +cd sqlite-autoconf-3071000 
-patch -p1 <ipv4-sqlite-3.7.6.3-amalgamation.patch+patch -p1 <ipv4-sqlite-3.7.10.0-amalgamation.patch
 </code> </code>
   * Configure using ''-DSQLITE_IPV4_EXT_FUNC=1'', make, and install the software as you would normally. for example: <code bash>   * Configure using ''-DSQLITE_IPV4_EXT_FUNC=1'', make, and install the software as you would normally. for example: <code bash>
Ligne 278: Ligne 280:
 sudo make install sudo make install
 </code> </code>
 +
 +
 +==== ipv4-sqlite-3.7.6.3-amalgamation.patch ====
 +
 +^This file more outdated and probably completely unusable ^
 +
 +This is a patch for the file sqlite3.c of sqlite-3.7.6.3. Once applied, it allows to build sqlite with the ''isinnet'' and ''isinrange'' functions...
 +
 +See description for version 3.7.10.0 for details and substitute 3.7.10.0 with 3.7.6.3 .
 +
  
 ==== ipv4-sqlite-3.6.23.1-amalgamation.patch ==== ==== ipv4-sqlite-3.6.23.1-amalgamation.patch ====
  
 +^This file really outdated and probably definitely completely unusable ^
  
 This is a patch for the file sqlite3.c of sqlite-3.6.23.1. Once applied, it allows to build sqlite with the ''isinnet'' and ''isinrange'' functions... This is a patch for the file sqlite3.c of sqlite-3.6.23.1. Once applied, it allows to build sqlite with the ''isinnet'' and ''isinrange'' functions...
  
-See description for version 3.7.6.for details and substitute 3.7.6.with 3.6.23.1 .+See description for version 3.7.10.for details and substitute 3.7.10.with 3.6.23.1 .
  
 ==== sqlite3-ipv4-ext.txt ==== ==== sqlite3-ipv4-ext.txt ====
Ligne 316: Ligne 329:
 ==== Can I use the patch for other versions ? ==== ==== Can I use the patch for other versions ? ====
  
-Yes, probably.+Yes, probably. Well in fact, this true back in 2012. nowadays (2018) this is probably wrong. but giveit a try, you may be lucky.
  
 Since the extension is such a simple and small change to sqlite, it is reasonable to try to patch a version with a patch made for another version. Since the extension is such a simple and small change to sqlite, it is reasonable to try to patch a version with a patch made for another version.