Main Page   Modules   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

d_xpath_f.c File Reference

Experimental XPath driver. More...

#include "../config.h"
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
#include "buf.h"
#include "dbapi.h"

Include dependency graph for d_xpath_f.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  DBConnection_XPath
 The XPath-specific database connection structure. More...


Defines

#define XMLFILE   "XML File"
 Text for filename input field.

#define FLD_COUNT   4
 Number of emulated table fields.


Enumerations

enum  { FLD_TYPE = 0, FLD_NAME, FLD_ATTRIB, FLD_CONTENT }
 The predefined columns for the emulated database. More...


Functions

void * xpath_query (DBConnection *dbc, char *xpstr)
 Run a query against the XML file.

DBConnectionxpath_dbconnection_free (DBConnection *c)
 Free the connection structure.

char * xpath_error ()
 Return the last xpath error string.

char * xp_DBget_field_value_type (xmlNodePtr node)
 Return the text description of the field type field.

char * xp_DBget_field_value_attrib (xmlNodePtr node)
 Return the text description of the field attributes.

char * xp_DBget_field_value_content (xmlNodePtr node)
 Return the text description of the field content field.

void xp_DBurl_to_form (Form *frm, char *url)
 Copy the login variables from a text URL to a form.

char * xp_DBform_to_url (Form *frm)
DBConnectionxpath_dbconnection_new ()
 Allocate a new XPath DBConnection.

void dbconnection_xpath_set_filename (DBConnection *dbc, char *fn)
 Set the filename for the connection.

void xpath_set_error (DBConnection_XPath *dbc, char *s)
 Set the current error string.

int dbconnection_xpath_open_doc (DBConnection *dbc, char *fn)
 Open a connection to an XML document.

DBConnectorregister_XPath (void(*error_dialog)(char *, char *))
 Register the XPath driver with the application.


Variables

enum { ... }  FldTypes
 The predefined columns for the emulated database.


Detailed Description

Experimental XPath driver.

Author:
Lionel ULMER , Darryl Luff
The idea is to be able to use a minimal SQL syntax to query XML files. The XPath standard defines a syntax for querying files, and the XPath syntax is supported by libxml. At the moment the interface passes the query you enter directly to libxml, so the syntax is pure XPath. I will continue to use this until I finalise how the data is presented. The idea is that the results show up in a table.
XPath Connections
When you open the connection dialog, you see an XPath tab listed with the other database tabs. When you select this tab, it has a single input field. This field is for the filename of the XML file to open. You can use the 'Browse' button to find it. When you fill in the filename and click Connect, GtkSQL will initialise the Tables list with the emulated database table.
Emulated XPath Tables
Currently, when you open an XML file, you see a single table. This table of course doesn't exist in the XML file. It is not currently used for anything because you can't currently run SQL queries against it. But it doesn show the fields that will be returned in the result table when you run an XPath query.
The fields listed in the table are:
XPath Query Results
For testing, I'm using the XML report from the Nessus security scanner. This generates an XML file that starts like this:
 <report version="1.3">
  <info>
   <nessusd>
    <version>1.2.7</version>
    <libnasl>1.2.7</libnasl>
    <libnessus>1.2.7</libnessus>
    <thread>fork</thread>
   </nessusd>
   <host>
    <name>localhost</name>
    <osvers>2.4.18-18.8.0</osvers>
   </host>
  (followed by the actuall report results).
 
When I load this file, and run the XPath query "//report/info/host/ *", I get these results:

Type Name Attributes Content NODE name Not Implemented localhost NODE osname Not implemented Linux NODE osvers Not implemented 2.4.18-18.8.0

Obviously the 'Attributes' part is not implemented yet! What would be a good SQL syntax for this? Something like "Select * from //report/info/ *" seems the best I think. This needs more work.

Another option is to have more than one emulated table, each table could present the output slightly differently.

URL Syntax
The xpath url is of the format: xpath://filename So to refer to the file /tmp/report.xml, the url would be xpath:///tmp/report.xml Note the three '/'s, two from the 'xpath://' path, and one from '/tmp...'.
Todo:
-Decide on a query syntax for expressing XPath queries in SQL.

-Implement a basic SQL SELECT parser.

Definition in file d_xpath_f.c.


Enumeration Type Documentation

anonymous enum
 

The predefined columns for the emulated database.

Enumeration values:
FLD_TYPE  The record type.
FLD_NAME  Record name.
FLD_ATTRIB  Record attributes.
FLD_CONTENT  Record contents.

Definition at line 111 of file d_xpath_f.c.


Function Documentation

int dbconnection_xpath_open_doc DBConnection   dbc,
char *    fn
 

Open a connection to an XML document.

Parameters:
dbc  Thc database connection.
fn  Filename to open.
Returns:
Connection status.

Definition at line 816 of file d_xpath_f.c.

References dbconnection_xpath_set_filename(), DBConnection_XPath::doc, db_conn::pvt, and xpath_set_error().

void dbconnection_xpath_set_filename DBConnection   dbc,
char *    fn
 

Set the filename for the connection.

Parameters:
dbc  The connection.
fn  Filename to set.

Definition at line 781 of file d_xpath_f.c.

References DBConnection_XPath::filename, and db_conn::pvt.

Referenced by dbconnection_xpath_open_doc().

DBConnector* register_XPath void(*    error_dialog)(char *, char *)
 

Register the XPath driver with the application.

Parameters:
error_dialog  The error callback.
Returns:
The XPath driver DBConnector.

Definition at line 892 of file d_xpath_f.c.

References _dbconnector::app_error_dialog, _dbconnector::db_connect_callback, _dbconnector::db_frm, dbconnector_new(), _dbconnector::dbtype, fld_set_relevance(), fld_set_tip(), fld_set_type(), _dbconnector::form_to_url, FR_REQUIRED, frm_add_field(), frm_new(), frm_set_title(), FT_FILENAME, _dbconnector::url_to_form, XMLFILE, xp_DBform_to_url(), and xp_DBurl_to_form().

char* xp_DBform_to_url Form   frm
 

Parameters:
frm  The form to copy to.
Returns:
The buffer containing the URL.

Definition at line 648 of file d_xpath_f.c.

References _a_buf::b_dat, buf_check(), buf_strcat(), frm_get_value_by_name(), and XMLFILE.

Referenced by register_XPath().

char* xp_DBget_field_value_attrib xmlNodePtr    node
 

Return the text description of the field attributes.

Parameters:
node  The libxml node to process.
Returns:
The attributes as a string.

Definition at line 389 of file d_xpath_f.c.

References _a_buf::b_dat, buf_check(), buf_strcat(), and buf_strcpy().

char* xp_DBget_field_value_content xmlNodePtr    node
 

Return the text description of the field content field.

Parameters:
node  The libxml node to process.
Returns:
The content as a string.

Definition at line 432 of file d_xpath_f.c.

References _a_buf::b_dat, buf_strcat(), buf_strcpy(), and trimtext().

char* xp_DBget_field_value_type xmlNodePtr    node
 

Return the text description of the field type field.

Parameters:
node  The libxml node to process.
Returns:
The type as a string.

Definition at line 329 of file d_xpath_f.c.

void xp_DBurl_to_form Form   frm,
char *    url
 

Copy the login variables from a text URL to a form.

URL format is "xpath://filename"

Parameters:
frm  The form to copy to.
url  The database URL to copy from.

Definition at line 538 of file d_xpath_f.c.

References frm_clear_fields(), frm_set_value_by_name(), and XMLFILE.

Referenced by register_XPath().

DBConnection* xpath_dbconnection_free DBConnection   c
 

Free the connection structure.

Parameters:
c  The connection to free.
Returns:
Always returns a NULL pointer.

Definition at line 180 of file d_xpath_f.c.

References DBConnection_XPath::filename, keywords_remove_all(), and db_conn::pvt.

DBConnection* xpath_dbconnection_new  
 

Allocate a new XPath DBConnection.

Returns:
The allocated connection.

Definition at line 740 of file d_xpath_f.c.

References add_keyword(), db_conn::DBclear_result, db_conn::DBdisconnect, db_conn::DBexecute_query, db_conn::DBfree_table_def, db_conn::DBget_db_name, db_conn::DBget_error_message, db_conn::DBget_field_name, db_conn::DBget_field_number, db_conn::DBget_field_value, db_conn::DBget_query_status, db_conn::DBget_record_number, db_conn::DBget_table, db_conn::DBget_table_def, db_conn::DBget_table_num, db_conn::keylist, KEYWORD_SQL, db_conn::pvt, and db_conn::pvtlen.

char* xpath_error  
 

Return the last xpath error string.

Returns:
The error string.

Definition at line 196 of file d_xpath_f.c.

void* xpath_query DBConnection   dbc,
char *    xpstr
 

Run a query against the XML file.

Parameters:
dbc  The connection.
xpstr  The query string. This is in the XPath query format.

Definition at line 142 of file d_xpath_f.c.

References DBConnection_XPath::doc, db_conn::pvt, DBConnection_XPath::result, and DBConnection_XPath::status.

void xpath_set_error DBConnection_XPath   dbc,
char *    s
 

Set the current error string.

Parameters:
dbc  The XPath connection.
s  The error string.

Definition at line 801 of file d_xpath_f.c.

References DBConnection_XPath::errmsg.

Referenced by dbconnection_xpath_open_doc().


Generated on Sun May 9 19:19:20 2004 for GtkSQL by doxygen1.2.18