From 517622f2e51756078a6ec0fbf338db317ed2a01e Mon Sep 17 00:00:00 2001 From: Joni Kokko Date: Mon, 19 Jan 2009 09:49:58 +0200 Subject: [PATCH] Created function which returns configuration_id by file_hash and file_name --- database/php/irreco_webdb_database.php | 24 ++++++++++++++++++ database/php/irreco_webdb_server.php | 18 ++++++++++++++ irreco/src/webdb/irreco_webdb_client.c | 45 ++++++++++++++++++++++++++++++++++ irreco/src/webdb/irreco_webdb_client.h | 5 ++++ 4 files changed, 92 insertions(+) diff --git a/database/php/irreco_webdb_database.php b/database/php/irreco_webdb_database.php index e715cbf8..c2b0b6f8 100644 --- a/database/php/irreco_webdb_database.php +++ b/database/php/irreco_webdb_database.php @@ -584,6 +584,30 @@ class IrrecoWebdbDatabase } /** + * Get configuration_id by name and date. + * + * Returns configuration_id or 0 if configuration does not exists. + * @param string file_hash sha1-hash of file_data + * @param string file_name Name for File + * @return int + */ + function getConfigIdByFilehashAndFilename($file_hash, $file_name) + { + $result = $this->query( + 'SELECT id AS id FROM configuration '. + 'WHERE file_hash = '. + $this->db->quote($file_hash, 'text').' '. + 'AND file_name = '. + $this->db->quote($file_name, 'text')); + $rows = $result->fetchAll(); + $id = 0; + if ($rows != NULL) { + $id = intval($rows[0]->id); + } + return $id; + } + + /** * Get file data by hash and name * * @return array diff --git a/database/php/irreco_webdb_server.php b/database/php/irreco_webdb_server.php index 2dbdcbe6..585b4390 100644 --- a/database/php/irreco_webdb_server.php +++ b/database/php/irreco_webdb_server.php @@ -478,6 +478,24 @@ class IrrecoWebdbServer return $array; } + /** + * Get configuration_id by name and date. + * + * Returns configuration_id or 0 if configuration does not exists. + * @param string file_hash sha1-hash of file_data + * @param string file_name Name for File + * @return int + */ + function getConfigIdByFilehashAndFilename($file_hash, $file_name) + { + IrrecoLog::$server->log( + 'XML-RPC getConfigIdByFilehashAndFilename'); + $id = $this->database->getConfigIdByFilehashAndFilename( + $file_hash, $file_name); + + IrrecoLog::$server->log("Configuration_id: ". $id); + return $id; + } /** * Get File diff --git a/irreco/src/webdb/irreco_webdb_client.c b/irreco/src/webdb/irreco_webdb_client.c index 8fb2ca1b..5243b4bb 100644 --- a/irreco/src/webdb/irreco_webdb_client.c +++ b/irreco/src/webdb/irreco_webdb_client.c @@ -820,6 +820,51 @@ gboolean irreco_webdb_client_get_configuration(IrrecoWebdbClient *self, IRRECO_RETURN_BOOL(rvalue); } +gint irreco_webdb_client_get_config_id_by_file_hash_and_file_name( + IrrecoWebdbClient *self, + const gchar *file_hash, + const gchar *file_name) +{ + SoupXmlrpcMessage *msg; + SoupXmlrpcResponse *response; + SoupXmlrpcValue *value; + glong id = 0; + + IRRECO_ENTER + + msg = soup_xmlrpc_message_new(IRRECO_WEBDB_URL); + soup_xmlrpc_message_start_call(msg, "getConfigIdByFilehashAndFilename"); + soup_xmlrpc_message_start_param (msg); + soup_xmlrpc_message_write_string(msg, file_hash); + soup_xmlrpc_message_write_string(msg, file_name); + soup_xmlrpc_message_end_param(msg); + soup_xmlrpc_message_end_call (msg); + + irreco_webdb_client_reset_env(self); + + response = (SoupXmlrpcResponse*)do_xmlrpc(msg, + SOUP_XMLRPC_VALUE_TYPE_INT, + self); + + /* Check response exists */ + if(!response) { + IRRECO_DEBUG(" No response, failed at do_xmlrpc\n"); + goto end; + } + + value = soup_xmlrpc_response_get_value(response); + + /* Try to get integer out of value */ + if(!soup_xmlrpc_value_get_int(value, &id)) { + id = 0; + } + + end: + g_object_unref (response); + IRRECO_RETURN_INT(id); + +} + gboolean irreco_webdb_client_get_file(IrrecoWebdbClient *self, const gchar *file_hash, const gchar *file_name, diff --git a/irreco/src/webdb/irreco_webdb_client.h b/irreco/src/webdb/irreco_webdb_client.h index 5a4d077f..ce568881 100644 --- a/irreco/src/webdb/irreco_webdb_client.h +++ b/irreco/src/webdb/irreco_webdb_client.h @@ -134,6 +134,11 @@ gboolean irreco_webdb_client_get_configuration(IrrecoWebdbClient *self, gint id, IrrecoWebdbConf **configuration); +gint irreco_webdb_client_get_config_id_by_file_hash_and_file_name( + IrrecoWebdbClient *self, + const gchar *file_hash, + const gchar *file_name); + gboolean irreco_webdb_client_get_file(IrrecoWebdbClient *self, const gchar *file_hash, const gchar *file_name, -- 2.11.4.GIT