*/
/*
- * This is just a example pop-up that shows how to use a new C-API in wrt-security.
+ * This is just a example pop-up that shows how to use a new C-API in
+ * wrt-security.
* This pop-up should be re-implemented by members of NGWAP.
*/
#include "popup-runner.h"
namespace { // anonymous
-
const char *POPUP_EXEC = "/usr/bin/wrt-popup-ace-runtime";
-void _ace_params_serializer (const ace_param_list_t* ace_param_list, Wrt::Popup::BinaryStream *stream){
-
+void _ace_params_serializer (const ace_param_list_t* ace_param_list,
+ Wrt::Popup::BinaryStream *stream)
+{
LogDebug("_ace_params_serializer");
- if(NULL == ace_param_list || NULL == stream){
+ if (NULL == ace_param_list || NULL == stream) {
LogError("*ace_param_list or *stream is NULL; return");
return;
}
LogDebug("Param count : " << ace_param_list->count);
// serialize ace_param_list->count;
- size_t count = static_cast <size_t> (ace_param_list->count);
+ size_t count = static_cast <size_t>(ace_param_list->count);
DPL::Serialization::Serialize(*stream, count);
- for(size_t i=0; i < count; ++i){
+ for (size_t i = 0; i < count; ++i) {
std::string name(ace_param_list->items[i].name);
DPL::Serialization::Serialize(*stream, name);
DPL::Serialization::Serialize(*stream, value);
}
}
-
} // anonymous namespace
namespace Wrt {
namespace Popup {
-
// BinaryStream class implementation
-void BinaryStream::Read(size_t num, void * bytes) {
+void BinaryStream::Read(size_t num, void * bytes)
+{
size_t max_size = m_data.size();
for (size_t i = 0; i < num; ++i) {
- if( i + m_readPosition >= max_size){
+ if (i + m_readPosition >= max_size) {
return;
}
- static_cast <unsigned char*> (bytes)[i] = m_data[i + m_readPosition];
+ static_cast <unsigned char*>(bytes)[i] = m_data[i + m_readPosition];
}
m_readPosition += num;
}
-void BinaryStream::Write(size_t num, const void * bytes) {
+void BinaryStream::Write(size_t num, const void * bytes)
+{
for (size_t i = 0; i < num; ++i) {
- m_data.push_back(static_cast <const unsigned char*> (bytes)[i]);
+ m_data.push_back(static_cast <const unsigned char*>(bytes)[i]);
}
}
-BinaryStream::BinaryStream() {
+BinaryStream::BinaryStream()
+{
m_readPosition = 0;
}
-BinaryStream::~BinaryStream() {
-}
+BinaryStream::~BinaryStream() {}
-const unsigned char* BinaryStream::char_pointer() const {
+const unsigned char* BinaryStream::char_pointer() const
+{
return &m_data[0];
}
-size_t BinaryStream::size() const {
+size_t BinaryStream::size() const
+{
return m_data.size();
}
// BinaryStream
ace_return_t run_popup(
- ace_popup_t popup_type,
- const ace_resource_t resource_name,
- const ace_session_id_t session_id,
- const ace_param_list_t* ace_param_list,
- ace_widget_handle_t handle,
- ace_bool_t* validation_result)
+ ace_popup_t popup_type,
+ const ace_resource_t resource_name,
+ const ace_session_id_t session_id,
+ const ace_param_list_t* ace_param_list,
+ ace_widget_handle_t handle,
+ ace_bool_t* validation_result)
{
- if ( NULL == resource_name ||
- NULL == session_id ||
- NULL == ace_param_list ||
- NULL == validation_result )
+ if (NULL == resource_name ||
+ NULL == session_id ||
+ NULL == ace_param_list ||
+ NULL == validation_result)
{
LogError("run_popup : ACE_INVALID_ARGUMENTS");
return ACE_INVALID_ARGUMENTS;
LogDebug("session_id : " << session_id);
LogDebug("widget handle : " << handle);
- int popup_type_int = static_cast <int> (popup_type);
- char *resource_name_char = static_cast <char *> (resource_name);
- char *session_id_char = static_cast <char *> (session_id);
- int handle_int = static_cast <int> (handle);
+ int popup_type_int = static_cast <int>(popup_type);
+ char *resource_name_char = static_cast <char *>(resource_name);
+ char *session_id_char = static_cast <char *>(session_id);
+ int handle_int = static_cast <int>(handle);
// serialization
Wrt::Popup::BinaryStream stream;
DPL::Serialization::Serialize(stream, handle_int);
- _ace_params_serializer (ace_param_list, &stream);
+ _ace_params_serializer(ace_param_list, &stream);
- int fd_send_to_child[2];
- int fd_send_to_parent[2];
+ int fd_send_to_child[2];
+ int fd_send_to_parent[2];
pid_t childpid;
- if(0 != pipe(fd_send_to_child)){
+ if (0 != pipe(fd_send_to_child)) {
LogError("Cannot create pipes!");
return ACE_INTERNAL_ERROR;
}
- if(0 != pipe(fd_send_to_parent)){
+ if (0 != pipe(fd_send_to_parent)) {
LogError("Cannot create pipes!");
return ACE_INTERNAL_ERROR;
}
return ACE_ACE_UNKNOWN_ERROR;
}
- if(childpid == 0) { // Child process
+ if (childpid == 0) { // Child process
LogDebug("Child");
// read data from parent
std::stringstream pipe_in_buff;
std::stringstream pipe_out_buff;
- pipe_in_buff << fd_send_to_parent[1];
+ pipe_in_buff << fd_send_to_parent[1];
pipe_out_buff << fd_send_to_child[0];
- std::string pipe_in = pipe_in_buff.str();
+ std::string pipe_in = pipe_in_buff.str();
std::string pipe_out = pipe_out_buff.str();
- LogDebug("Passed file descriptors: " << fd_send_to_child[0] << ", "<< fd_send_to_parent[1]);
+ LogDebug(
+ "Passed file descriptors: " << fd_send_to_child[0] << ", " <<
+ fd_send_to_parent[1]);
- if (execl(POPUP_EXEC, POPUP_EXEC, pipe_out.c_str(), pipe_in.c_str(), NULL) < 0){
+ if (execl(POPUP_EXEC, POPUP_EXEC, pipe_out.c_str(), pipe_in.c_str(),
+ NULL) < 0)
+ {
LogError("execlp FAILED");
}
LogError("This should not happened!!!");
-
} // end of child process - from now you can use DEBUG LOGS
else { // Parent process
LogDebug("Parent");
- int buff_size = 1024;
+ int buff_size = 1024;
char result[buff_size];
// send data to child
close(fd_send_to_child[0]);
//writing to child
LogDebug("Sending message to popup-bin process");
- if(-1 == TEMP_FAILURE_RETRY(write(fd_send_to_child[1], stream.char_pointer(), stream.size()))){
+ if (-1 ==
+ TEMP_FAILURE_RETRY(write(fd_send_to_child[1], stream.char_pointer(),
+ stream.size())))
+ {
LogError("Write to pipe failed!");
return ACE_INTERNAL_ERROR;
}
int status;
wait(&status);
LogDebug("STATUS EXIT ON POPUP (CHILD): " << status);
- switch (status){
-
+ switch (status) {
case ACE_OK:
LogDebug("ACE_OK");
break;
case ACE_INVALID_ARGUMENTS:
LogDebug("ACE_INVALID_ARGUMENTS");
close(fd_send_to_parent[0]);
- return static_cast <ace_return_t> (status);
+ return static_cast <ace_return_t>(status);
break;
case ACE_INTERNAL_ERROR:
LogDebug("ACE_INTERNAL_ERROR");
close(fd_send_to_parent[0]);
- return static_cast <ace_return_t> (status);
+ return static_cast <ace_return_t>(status);
break;
case ACE_ACE_UNKNOWN_ERROR:
LogDebug("ACE_ACE_UNKNOWN_ERROR");
close(fd_send_to_parent[0]);
- return static_cast <ace_return_t> (status);
+ return static_cast <ace_return_t>(status);
break;
default:
LogDebug("UNKNOWN_ERROR");
close(fd_send_to_parent[0]);
status = (int) ACE_ACE_UNKNOWN_ERROR;
- return static_cast <ace_return_t> (status);
+ return static_cast <ace_return_t>(status);
break;
}
close(fd_send_to_parent[0]); // cleanup
int validation_result_int;
- if(0 < count){
+ if (0 < count) {
BinaryStream stream_in;
stream_in.Write(count, result);
LogDebug("RESULT FROM POPUP (CHILD) : [ " << count << " ]");
DPL::Deserialization::Deserialize(stream_in, validation_result_int);
- *validation_result = static_cast <ace_bool_t> (validation_result_int);
+ *validation_result = static_cast <ace_bool_t>(validation_result_int);
LogDebug("validation_result :");
- switch (*validation_result){
+ switch (*validation_result) {
case ACE_FALSE:
LogDebug("ACE_FALSE");
break;
LogDebug("UNKNOWN - DEFAULT");
break;
}
- }
- else {
+ } else {
LogDebug("count = " << count);
LogDebug("UNKNOWN_ERROR");
return ACE_ACE_UNKNOWN_ERROR;
LogError("This should not happend!!!");
return ACE_ACE_UNKNOWN_ERROR;
}
-
} // Popup
} // Wrt