1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/* Copyright (c) MediaArea.net SARL. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license that can
* be found in the License.html file in the root of the source tree.
*/
//---------------------------------------------------------------------------
#ifdef __BORLANDC__
#pragma hdrstop
#endif
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include "Http.h"
#include <sstream>
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
namespace MediaConch {
//***************************************************************************
// Http
//***************************************************************************
int Http::current_daemon_id = -1;
//***************************************************************************
// Constructor/Destructor
//***************************************************************************
//---------------------------------------------------------------------------
Http::Http() : address("0.0.0.0"), port(80)
{
}
//---------------------------------------------------------------------------
Http::~Http()
{
}
//***************************************************************************
// send_request generator
//***************************************************************************
//---------------------------------------------------------------------------
#define SEND_REQUEST_GET(NAME, DEF) \
int Http::send_request(RESTAPI::NAME& req, std::string& err) \
{ \
std::string query; \
if (rest.serialize_##DEF##_req(req, query, err) < 0) \
return -1; \
\
std::stringstream uri; \
uri << "/" << RESTAPI::API_VERSION << "/"#DEF << query; \
std::string uri_str = uri.str(); \
\
return send_request_get(uri_str, err); \
}
//---------------------------------------------------------------------------
#define SEND_REQUEST_POST(NAME, DEF) \
int Http::send_request(RESTAPI::NAME& req, std::string& err) \
{ \
std::string cmd; \
if (rest.serialize_##DEF##_req(req, cmd, err) < 0) \
return -1; \
\
std::stringstream uri; \
uri << "/" << RESTAPI::API_VERSION << "/"#DEF; \
std::string uri_str = uri.str(); \
\
return send_request_post(uri_str, cmd, err); \
}
//---------------------------------------------------------------------------
#define SEND_REQUEST_PUT(NAME, DEF) \
int Http::send_request(RESTAPI::NAME& req, std::string& err) \
{ \
std::string cmd; \
if (rest.serialize_##DEF##_req(req, cmd, err) < 0) \
return -1; \
\
std::stringstream uri; \
uri << "/" << RESTAPI::API_VERSION << "/"#DEF; \
std::string uri_str = uri.str(); \
\
return send_request_put(uri_str, cmd, err); \
}
//---------------------------------------------------------------------------
#define SEND_REQUEST_DELETE(NAME, DEF) \
int Http::send_request(RESTAPI::NAME& req, std::string& err) \
{ \
std::string query; \
if (rest.serialize_##DEF##_req(req, query, err) < 0) \
return -1; \
\
std::stringstream uri; \
uri << "/" << RESTAPI::API_VERSION << "/"#DEF << query; \
std::string uri_str = uri.str(); \
\
return send_request_delete(uri_str, err); \
}
//***************************************************************************
// MediaConch
//***************************************************************************
SEND_REQUEST_GET(MediaConch_Get_Plugins_Req, mediaconch_get_plugins);
SEND_REQUEST_POST(MediaConch_Watch_Folder_Req, mediaconch_watch_folder);
SEND_REQUEST_GET(MediaConch_List_Watch_Folders_Req, mediaconch_list_watch_folders);
SEND_REQUEST_POST(MediaConch_Edit_Watch_Folder_Req, mediaconch_edit_watch_folder);
SEND_REQUEST_POST(MediaConch_Remove_Watch_Folder_Req, mediaconch_remove_watch_folder);
//***************************************************************************
// Checker
//***************************************************************************
SEND_REQUEST_POST(Checker_Analyze_Req, checker_analyze);
SEND_REQUEST_GET(Checker_Status_Req, checker_status);
SEND_REQUEST_POST(Checker_Report_Req, checker_report);
SEND_REQUEST_DELETE(Checker_Clear_Req, checker_clear);
SEND_REQUEST_POST(Checker_Stop_Req, checker_stop);
SEND_REQUEST_GET(Checker_List_Req, checker_list);
SEND_REQUEST_POST(Checker_Validate_Req, checker_validate);
SEND_REQUEST_POST(Checker_File_From_Id_Req, checker_file_from_id);
SEND_REQUEST_POST(Checker_Id_From_Filename_Req, checker_id_from_filename);
SEND_REQUEST_POST(Checker_File_Information_Req, checker_file_information);
SEND_REQUEST_GET(Checker_List_MediaInfo_Outputs_Req, checker_list_mediainfo_outputs);
SEND_REQUEST_GET(Default_Values_For_Type_Req, default_values_for_type);
//***************************************************************************
// Policy
//***************************************************************************
SEND_REQUEST_GET(XSLT_Policy_Create_Req, xslt_policy_create);
SEND_REQUEST_POST(Policy_Import_Req, policy_import);
SEND_REQUEST_GET(Policy_Remove_Req, policy_remove);
SEND_REQUEST_GET(Policy_Dump_Req, policy_dump);
SEND_REQUEST_GET(Policy_Save_Req, policy_save);
SEND_REQUEST_GET(Policy_Duplicate_Req, policy_duplicate);
SEND_REQUEST_GET(Policy_Move_Req, policy_move);
SEND_REQUEST_POST(Policy_Change_Info_Req, policy_change_info);
SEND_REQUEST_POST(Policy_Change_Type_Req, policy_change_type);
SEND_REQUEST_POST(Policy_Change_Is_Public_Req, policy_change_is_public);
SEND_REQUEST_GET(Policy_Get_Req, policy_get);
SEND_REQUEST_GET(Policy_Get_Name_Req, policy_get_name);
SEND_REQUEST_GET(Policy_Get_Policies_Count_Req, policy_get_policies_count);
SEND_REQUEST_GET(Policy_Clear_Policies_Req, policy_clear_policies);
SEND_REQUEST_GET(Policy_Get_Policies_Req, policy_get_policies);
SEND_REQUEST_GET(Policy_Get_Public_Policies_Req, policy_get_public_policies);
SEND_REQUEST_GET(Policy_Get_Policies_Names_List_Req, policy_get_policies_names_list);
SEND_REQUEST_GET(XSLT_Policy_Create_From_File_Req, xslt_policy_create_from_file);
SEND_REQUEST_GET(XSLT_Policy_Rule_Create_Req, xslt_policy_rule_create);
SEND_REQUEST_GET(XSLT_Policy_Rule_Get_Req, xslt_policy_rule_get);
SEND_REQUEST_POST(XSLT_Policy_Rule_Edit_Req, xslt_policy_rule_edit);
SEND_REQUEST_GET(XSLT_Policy_Rule_Duplicate_Req, xslt_policy_rule_duplicate);
SEND_REQUEST_GET(XSLT_Policy_Rule_Move_Req, xslt_policy_rule_move);
SEND_REQUEST_GET(XSLT_Policy_Rule_Delete_Req, xslt_policy_rule_delete);
//---------------------------------------------------------------------------
void Http::set_port(int port)
{
this->port = port;
}
//---------------------------------------------------------------------------
void Http::set_address(std::string& address)
{
this->address = address;
}
}
|