Skip to content

Commit 81d4875

Browse files
authored
feat: Added expire and issued timestamps in attachment (#1065)
1 parent 12df0ab commit 81d4875

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

include/dpp/message.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,20 @@ struct DPP_EXPORT attachment {
11721172
* @return true if remixed
11731173
*/
11741174
bool is_remix() const;
1175+
1176+
/**
1177+
* @brief Returns expiration timestamp for attachment's URL
1178+
*
1179+
* @return timestamp of URL expiration
1180+
*/
1181+
time_t get_expire_time() const;
1182+
1183+
/**
1184+
* @brief Returns creation timestamp for attachment's URL
1185+
*
1186+
* @return timestamp of URL creation
1187+
*/
1188+
time_t get_issued_time() const;
11751189
};
11761190

11771191
/**

src/dpp/message.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -882,6 +882,38 @@ bool attachment::is_remix() const {
882882
return flags & a_is_remix;
883883
}
884884

885+
time_t attachment::get_expire_time() const {
886+
size_t attr_position = url.find('?');
887+
/* If no attributes were sent in url, we do not need to parse more */
888+
if(url.npos == attr_position){
889+
return 0;
890+
}
891+
std::string attributes = url.substr(attr_position + 1);
892+
std::vector<std::string> attr_list = utility::tokenize(attributes, "&");
893+
auto ex_attr = std::find_if(attr_list.begin(), attr_list.end(), [](const std::string& s){return s.substr(0, 3) == "ex=";});
894+
if(attr_list.end() == ex_attr){
895+
return 0;
896+
}
897+
/* Erase 'ex=' prefix before parsing */
898+
return std::stol(ex_attr->substr(3), nullptr, 16);
899+
}
900+
901+
time_t attachment::get_issued_time() const {
902+
size_t attr_position = url.find('?');
903+
/* No attributes were sent in url, so we do not need to parse more */
904+
if(url.npos == attr_position){
905+
return 0;
906+
}
907+
std::string attributes = url.substr(attr_position + 1);
908+
std::vector<std::string> attr_list = utility::tokenize(attributes, "&");
909+
auto is_attr = std::find_if(attr_list.begin(), attr_list.end(), [](const std::string& s){return s.substr(0, 3) == "is=";});
910+
if(attr_list.end() == is_attr){
911+
return 0;
912+
}
913+
/* Erase 'is=' prefix before parsing */
914+
return std::stol(is_attr->substr(3), nullptr, 16);
915+
}
916+
885917
json message::to_json(bool with_id, bool is_interaction_response) const {
886918
/* This is the basics. once it works, expand on it. */
887919
json j({

0 commit comments

Comments
 (0)