#include <wrt-commons/custom-handler-dao-rw/custom_handler_dao.h>
#include <wrt-commons/custom-handler-dao-ro/CustomHandlerDatabase.h>
#include <orm_generator_custom_handler.h>
+#include <wrt-commons/custom-handler-dao-ro/custom_handler_dao_read_only.h>
using namespace DPL::DB::ORM;
using namespace DPL::DB::ORM::custom_handler;
row.Set_base_url(handler.base_url);
row.Set_url(handler.url);
row.Set_title(handler.title);
- row.Set_user_allowed(handler.user_allowed);
+ row.Set_user_allowed(handler.user_decision);
}
} // namespace
LogDebug("Registering content handler " << handler.target << " " <<
handler.base_url);
Try {
+ if (handler.user_decision & Agreed) {
+ //need to disable all previous, agreed entries
+ CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
+ select->Where(And(Equals<ContentHandlers::target>(handler.target),
+ Or(Equals<ContentHandlers::user_allowed>(Agreed),
+ Equals<ContentHandlers::user_allowed>(AgreedPermanently))
+ ));
+ ContentHandlers::Select::RowList rows = select->GetRowList();
+ if (rows.size() > 1) {
+ //more than one activ content handler - not good. Remove all.
+ //this should never happen
+ LogError("Database data incoherent.");
+ CUSTOM_HANDLER_DB_DELETE(deleteContent, ContentHandlers);
+ deleteContent->Where(And(Equals<ContentHandlers::target>(handler.target),
+ Or(Equals<ContentHandlers::user_allowed>(Agreed),
+ Equals<ContentHandlers::user_allowed>(AgreedPermanently))));
+ deleteContent->Execute();
+ //all content handlers removed. New one can be inserted
+ } else if (!rows.empty()) {
+ //one active handler. Can be updaed
+ LogDebug("Activ content handler exist. Update");
+ CUSTOM_HANDLER_DB_UPDATE(update, ContentHandlers);
+ update->Where(And(Equals<ContentHandlers::target>(handler.target),
+ Or(Equals<ContentHandlers::user_allowed>(Agreed),
+ Equals<ContentHandlers::user_allowed>(AgreedPermanently))
+ ));
+ ContentHandlers::Row rowToUpdate = rows.front();
+
+ if (handler.user_decision & DecisionSaved) {
+ //do not ask about previous one
+ rowToUpdate.Set_user_allowed(DeclinedPermanently);
+ } else {
+ //ask for next time
+ rowToUpdate.Set_user_allowed(Declined);
+ }
+ update->Values(rowToUpdate);
+ update->Execute();
+ }
+ }
+ LogDebug("Inserting new content handler");
ContentHandlers::Row row;
fillRow(row, handler, m_pkgName);
-
- // TODO remove previous if necessary
+ if (getContentHandler(handler.target, handler.url, handler.base_url)) {
+ LogDebug("Content handler exist. Update its state");
+ CUSTOM_HANDLER_DB_UPDATE(updateRow, ContentHandlers);
+ updateRow->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
+ And(Equals<ContentHandlers::target>(handler.target),
+ And(Equals<ContentHandlers::url>(handler.url),
+ Equals<ContentHandlers::base_url>(handler.base_url)))));
+ updateRow->Values(row);
+ updateRow->Execute();
+ LogDebug("updated");
+ return;
+ }
CUSTOM_HANDLER_DB_INSERT(insert, ContentHandlers);
insert->Values(row);
insert->Execute();
+ LogDebug("insterted");
}
Catch(DPL::DB::SqlConnection::Exception::Base){
ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
LogDebug("Registering protocol handler " << handler.target << " " <<
handler.base_url);
Try {
+
+ if (handler.user_decision & Agreed) {
+ //need to disable all previous, agreed entries
+ CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
+ select->Where(And(Equals<ProtocolHandlers::target>(handler.target),
+ Or(Equals<ProtocolHandlers::user_allowed>(Agreed),
+ Equals<ProtocolHandlers::user_allowed>(AgreedPermanently))
+ ));
+ ProtocolHandlers::Select::RowList rows = select->GetRowList();
+ if (rows.size() > 1) {
+ //more than one activ protocol handler - not good. Remove all.
+ //this should never happen
+ LogError("Database data incoherent.");
+ CUSTOM_HANDLER_DB_DELETE(deleteProtocol, ProtocolHandlers);
+ deleteProtocol->Where(And(Equals<ProtocolHandlers::target>(handler.target),
+ Or(Equals<ProtocolHandlers::user_allowed>(Agreed),
+ Equals<ProtocolHandlers::user_allowed>(AgreedPermanently))));
+ deleteProtocol->Execute();
+ //all protocol handlers removed. New one can be inserted
+ } else if (!rows.empty()) {
+ //one active handler. Can be updaed
+ CUSTOM_HANDLER_DB_UPDATE(update, ProtocolHandlers);
+ update->Where(And(Equals<ProtocolHandlers::target>(handler.target),
+ Or(Equals<ProtocolHandlers::user_allowed>(Agreed),
+ Equals<ProtocolHandlers::user_allowed>(AgreedPermanently))
+ ));
+ ProtocolHandlers::Row rowToUpdate = rows.front();
+
+ if (handler.user_decision & DecisionSaved) {
+ //do not ask about previous one
+ rowToUpdate.Set_user_allowed(DeclinedPermanently);
+ } else {
+ //ask for next time
+ rowToUpdate.Set_user_allowed(Declined);
+ }
+ update->Values(rowToUpdate);
+ update->Execute();
+ }
+ }
+ LogDebug("Inserting new protocol handler");
ProtocolHandlers::Row row;
fillRow(row, handler, m_pkgName);
-
- // TODO remove previous if necessary
+ if (getProtocolHandler(handler.target, handler.url, handler.base_url)) {
+ LogDebug("Protocol handler exist. Update its state");
+ CUSTOM_HANDLER_DB_UPDATE(updateRow, ProtocolHandlers);
+ updateRow->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
+ And(Equals<ProtocolHandlers::target>(handler.target),
+ And(Equals<ProtocolHandlers::url>(handler.url),
+ Equals<ProtocolHandlers::base_url>(handler.base_url)))));
+ updateRow->Values(row);
+ updateRow->Execute();
+ LogDebug("updated");
+ return;
+ }
CUSTOM_HANDLER_DB_INSERT(insert, ProtocolHandlers);
insert->Values(row);
insert->Execute();
+ LogDebug("insterted");
}
Catch(DPL::DB::SqlConnection::Exception::Base){
ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
}
+void CustomHandlerDAO::unregisterContentHandler(const DPL::String& target,
+ const DPL::String& url,
+ const DPL::String& baseURL)
+{
+ LogDebug("Removing content handler " << target << " " << url);
+ Try {
+ CUSTOM_HANDLER_DB_DELETE(deleteFrom, ContentHandlers);
+ deleteFrom->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
+ And(Equals<ContentHandlers::target>(target),
+ And(Equals<ContentHandlers::url>(url),
+ Equals<ContentHandlers::base_url>(baseURL)))));
+ deleteFrom->Execute();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
+ "Failed to remove content handler");
+ }
+}
+
+void CustomHandlerDAO::unregisterProtocolHandler(const DPL::String& target,
+ const DPL::String& url,
+ const DPL::String& baseURL)
+{
+ LogDebug("Removing protocol handler " << target << " " << url);
+ Try {
+ CUSTOM_HANDLER_DB_DELETE(deleteFrom, ProtocolHandlers);
+ deleteFrom->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
+ And(Equals<ProtocolHandlers::target>(target),
+ And(Equals<ProtocolHandlers::url>(url),
+ Equals<ProtocolHandlers::base_url>(baseURL)))));
+ deleteFrom->Execute();
+ }
+ Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(CustomHandlerDAO::Exception::DatabaseError,
+ "Failed to remove content handler");
+ }
+
+}
+
} // namespace CustomHandlerDB
handler->base_url = row.front().Get_base_url();
handler->url = row.front().Get_url();
handler->title = row.front().Get_title();
- handler->user_allowed = row.front().Get_user_allowed();
+ handler->user_allowed = static_cast<bool>(row.front().Get_user_allowed());
+ handler->user_decision =
+ static_cast<HandlerState>(row.front().Get_user_allowed());
}
return handler;
}
}
}
+CustomHandlerPtr CustomHandlerDAOReadOnly::getActivProtocolHandler(
+ const DPL::String& protocol)
+{
+ LogDebug("Getting active protocol handler");
+ Try{
+ CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
+
+ select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
+ Equals<ProtocolHandlers::target>(protocol)));
+
+ std::list<ProtocolHandlers::Row> list = select->GetRowList();
+ CustomHandlerPtr handler;
+
+ FOREACH(it, list) {
+ if (it->Get_user_allowed() & Agreed) {
+ handler.reset(new CustomHandler());
+ handler->base_url = it->Get_base_url();
+ handler->target = it->Get_target();
+ handler->title = it->Get_title();
+ handler->url = it->Get_url();
+ handler->user_allowed =
+ static_cast<bool>(it->Get_user_allowed());
+ handler->user_decision =
+ static_cast<HandlerState>(it->Get_user_allowed());
+ }
+ }
+ return handler;
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
+ "Failed to get protocol handler");
+ }
+}
+
+CustomHandlerPtr CustomHandlerDAOReadOnly::getProtocolHandler(
+ const DPL::String& protocol,
+ const DPL::String& url,
+ const DPL::String& baseURL)
+{
+ LogDebug("Check if protocol is registered");
+ Try{
+ CUSTOM_HANDLER_DB_SELECT(select, ProtocolHandlers);
+
+ select->Where(And(Equals<ProtocolHandlers::app_id>(m_pkgName),
+ And(Equals<ProtocolHandlers::target>(protocol),
+ And(Equals<ProtocolHandlers::url>(url),
+ Equals<ProtocolHandlers::base_url>(baseURL)
+ )
+ )
+ )
+ );
+
+ std::list<ProtocolHandlers::Row> list = select->GetRowList();
+ return getSingleHandler(list);
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
+ "Failed to get content handler");
+ }
+}
+
+
+CustomHandlerPtr CustomHandlerDAOReadOnly::getActivContentHandler(
+ const DPL::String& content)
+{
+ LogDebug("Getting active content handler");
+ Try{
+ CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
+
+ select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
+ Equals<ContentHandlers::target>(content)));
+
+ std::list<ContentHandlers::Row> list = select->GetRowList();
+ CustomHandlerPtr handler;
+
+ FOREACH(it, list) {
+ if (it->Get_user_allowed() & Agreed) {
+ handler.reset(new CustomHandler());
+ handler->base_url = it->Get_base_url();
+ handler->target = it->Get_target();
+ handler->title = it->Get_title();
+ handler->url = it->Get_url();
+ handler->user_allowed =
+ static_cast<bool>(it->Get_user_allowed());
+ handler->user_decision =
+ static_cast<HandlerState>(it->Get_user_allowed());
+ }
+ }
+ return handler;
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
+ "Failed to get protocol handler");
+ }
+}
+
+CustomHandlerPtr CustomHandlerDAOReadOnly::getContentHandler(
+ const DPL::String& content,
+ const DPL::String& url,
+ const DPL::String& baseURL)
+{
+ LogDebug("Check if content is registered");
+ Try{
+ CUSTOM_HANDLER_DB_SELECT(select, ContentHandlers);
+
+ select->Where(And(Equals<ContentHandlers::app_id>(m_pkgName),
+ And(Equals<ContentHandlers::target>(content),
+ And(Equals<ContentHandlers::url>(url),
+ Equals<ContentHandlers::base_url>(baseURL)))));
+
+ std::list<ContentHandlers::Row> list = select->GetRowList();
+ return getSingleHandler(list);
+ } Catch(DPL::DB::SqlConnection::Exception::Base) {
+ ReThrowMsg(CustomHandlerDAOReadOnly::Exception::DatabaseError,
+ "Failed to get content handler");
+ }
+}
+
CustomHandlerPtr CustomHandlerDAOReadOnly::getAllowedProtocolHandler(
const DPL::String& protocol)
{
* @brief This file contains the declaration of
* common data types for custom handler database.
*/
-#ifndef SHARE_COMMON_DAO_TYPES_H_
-#define SHARE_COMMON_DAO_TYPES_H_
+#ifndef SRC_MODULES_CUSTOM_HANDLERS_DAO_COMMON_DAO_TYPES_H_
+#define SRC_MODULES_CUSTOM_HANDLERS_DAO_COMMON_DAO_TYPES_H_
#include <list>
#include <memory>
*
* Describes custom handler for protocol and content.
*/
+enum HandlerState {
+ Agreed = 0x01, //user agreed to use protocol only,
+ //but want to ask in next occurence
+ Declined = 0x02, //user declined to use protocol,
+ //but want to ask in next occurence
+ //in fact it is used when user wants to cover saved agreed
+ //decision by agreeing to another one without save.
+ DecisionSaved = 0x04, //user dont want to ask again
+ AgreedPermanently = Agreed | DecisionSaved,
+ DeclinedPermanently = Declined | DecisionSaved
+};
+
struct CustomHandler
{
DPL::String target; // protocol/content ("mailto"/"application/x-soup")
DPL::String url; // url used for protocol/content handling
DPL::String title; // user friendly handler name
bool user_allowed; // true if user has allowed the handler
+ HandlerState user_decision;
};
typedef std::shared_ptr<CustomHandler> CustomHandlerPtr;
+typedef std::list <CustomHandlerPtr> CustomHandlersList;
} // namespace CustomHandlerDB
-#endif /* SHARE_COMMON_DAO_TYPES_H_ */
+#endif /* SRC_MODULES_CUSTOM_HANDLERS_DAO_COMMON_DAO_TYPES_H_ */
*/
CustomHandlerPtr getProtocolHandler(const DPL::String& protocol,
const DPL::String& url);
+ CustomHandlerPtr getProtocolHandler(const DPL::String& protocol,
+ const DPL::String& url,
+ const DPL::String& baseURL);
+
+ /**
+ * Returns protocol handler that is agreed or agreed and saved and match tizenID
+ */
+ CustomHandlerPtr getActivProtocolHandler(const DPL::String& protocol);
+
+
/**
* Returns content handler
*/
CustomHandlerPtr getContentHandler(const DPL::String& content,
const DPL::String& url);
+ CustomHandlerPtr getContentHandler(const DPL::String& protocol,
+ const DPL::String& url,
+ const DPL::String& baseURL);
+
+ /**
+ * Returns content handler that is agreed or agreed and saved and match tizenID
+ */
+ CustomHandlerPtr getActivContentHandler(const DPL::String& content);
/**
* Returns allowed handler for given protocol
*/
void unregisterProtocolHandler(const DPL::String& target,
const DPL::String& url);
+
+ void unregisterContentHandler(const DPL::String& target,
+ const DPL::String& url,
+ const DPL::String& baseURL);
+
+ void unregisterProtocolHandler(const DPL::String& target,
+ const DPL::String& url,
+ const DPL::String& baseURL);
};
} // namespace CustomHandlerDB
COLUMN_NOT_NULL(user_allowed, INT,)
TABLE_CONSTRAINTS(
- PRIMARY KEY (app_id, target, url)
+ PRIMARY KEY (app_id, target, base_url, url)
)
CREATE_TABLE_END()
COLUMN_NOT_NULL(user_allowed, INT,)
TABLE_CONSTRAINTS(
- PRIMARY KEY (app_id, target, url)
+ PRIMARY KEY (app_id, target, base_url, url)
)
CREATE_TABLE_END()
(leftExpression, rightExpression);
}
+template<typename LeftExpression, typename RightExpression>
+BinaryExpression<RelationTypes::Or, LeftExpression, RightExpression>
+ Or(const LeftExpression& leftExpression, const RightExpression& rightExpression)
+{
+ return BinaryExpression<RelationTypes::Or, LeftExpression, RightExpression>
+ (leftExpression, rightExpression);
+}
+
template<typename ArgumentType>
class __attribute__ ((visibility("hidden"))) ExpressionWithArgument : public Expression {
protected: