void bdb_list_snapshot_records(JCR *jcr, SNAPSHOT_DBR *sdbr,
DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void bdb_list_files(JCR *jcr, FILE_DBR *fr, DB_RESULT_HANDLER *sendit, void *ctx);
+ void bdb_list_metadata_owner_records(JCR *jcr, META_DBR *meta_r, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
void bdb_list_metadata_records(JCR *jcr, META_DBR *meta_r, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type);
/* sql_update.c */
bool bdb_update_job_start_record(JCR *jcr, JOB_DBR *jr);
bsnprintf(errmsg, sizeof(errmsg), _("Type is not set"));
return false;
}
-
- if (!Owner[0]) {
- bsnprintf(errmsg, sizeof(errmsg), _("Owner is not set"));
- return false;
- }
-
if (!Tenant[0]) {
bsnprintf(errmsg, sizeof(errmsg), _("Tenant not set"));
return false;
pm_strcat(where, ") ");
}
+ if (ClientName[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), ClientName, strlen(ClientName));
+ Mmsg(tmp, " Client.Name='%s'", esc.c_str());
+ append_filter(where, tmp.c_str());
+ }
+
if (ConversationId[0] != 0) {
db_escape_string(jcr, jcr->db, esc.c_str(), ConversationId, strlen(ConversationId));
Mmsg(tmp, " MetaEmail.EmailConversationId = '%s'", esc.c_str());
if (Owner[0]) {
db_escape_string(jcr, jcr->db, esc.c_str(), Owner, strlen(Owner));
- Mmsg(tmp, " Meta%s.%sOwner = '%s'", Type, Type, esc.c_str());
+ if (strchr(Owner, '%')) {
+ Mmsg(tmp, " Meta%s.%sOwner ILIKE '%s'", Type, Type, esc.c_str());
+ } else {
+ Mmsg(tmp, " Meta%s.%sOwner = '%s'", Type, Type, esc.c_str());
+ }
append_filter(where, tmp.c_str());
}
bdb_unlock();
}
+/* List Owner in the metadata table */
+void BDB::bdb_list_metadata_owner_records(JCR *jcr, META_DBR *meta_r, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+{
+ POOL_MEM esc(PM_MESSAGE), tmp(PM_MESSAGE), where(PM_MESSAGE), join(PM_MESSAGE);
+
+ bdb_lock();
+ meta_r->create_db_filter(jcr, this, where.handle());
+ const char *where_filter = get_acls(DB_ACL_BIT(DB_ACL_JOB) |
+ DB_ACL_BIT(DB_ACL_CLIENT), strcmp(where.c_str(), "") == 0);
+
+ const char *join_filter = (*where_filter && meta_r->ClientName[0] == 0) ?
+ get_acl_join_filter(DB_ACL_BIT(DB_ACL_CLIENT)) : "";
+
+ if (meta_r->ClientName[0] != 0) {
+ Mmsg(join, " JOIN Job ON (Job.JobId = Meta%s.JobId) JOIN Client USING (ClientId) ", meta_r->Type);
+
+ } else if (*where_filter) { // We add manually the Job join filter part
+ Mmsg(join, " JOIN Job ON (Job.JobId = Meta%s.JobId) ", meta_r->Type);
+ }
+
+ if (where_filter && *where_filter) {
+ pm_strcat(where, where_filter);
+ }
+
+ if (join_filter && *join_filter) {
+ pm_strcat(join, join_filter);
+ }
+
+ if (meta_r->limit > 0) {
+ Mmsg(tmp, " LIMIT %d ", meta_r->limit);
+ pm_strcat(where, tmp.c_str());
+ }
+
+ if (meta_r->offset > 0) {
+ Mmsg(tmp, " OFFSET %ld ", meta_r->offset);
+ pm_strcat(where, tmp.c_str());
+ }
+
+ switch (type) {
+ case JSON_LIST:
+ case VERT_LIST:
+ case HORZ_LIST:
+ Mmsg(cmd,
+ "SELECT DISTINCT %sOwner "
+ "FROM Meta%s %s %s",
+ meta_r->Type, meta_r->Type, join.c_str(), where.c_str());
+ break;
+ default:
+ break;
+ }
+ Dmsg1(DT_SQL|50, "%s\n", cmd);
+ if (!QueryDB(jcr, cmd)) {
+ Jmsg(jcr, M_ERROR, 0, _("Query %s failed!\n"), cmd);
+ bdb_unlock();
+ return;
+ }
+ if (strcmp(meta_r->Type, "Email") == 0) {
+ Mmsg(esc, "metadataemail");
+ } else {
+ Mmsg(esc, "metaattachment");
+ }
+
+ list_result(jcr, this, esc.c_str(), sendit, ctx, type);
+
+ sql_free_result();
+ bdb_unlock();
+}
+
/*
* List plugin objects (search is based on object provided)
*/
void BDB::bdb_list_metadata_records(JCR *jcr, META_DBR *meta_r, DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
{
+ if (!meta_r->Owner[0] || strchr(meta_r->Owner, '%')) {
+ /* List Owners */
+ bdb_list_metadata_owner_records(jcr, meta_r, sendit, ctx, type);
+ return;
+ }
+
POOL_MEM esc(PM_MESSAGE), tmp(PM_MESSAGE), where(PM_MESSAGE), join(PM_MESSAGE);
bdb_lock();
//TODO add ACL part
get_acl_join_filter(DB_ACL_BIT(DB_ACL_CLIENT)) : "";
if (meta_r->ClientName[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), meta_r->ClientName, strlen(meta_r->ClientName));
- Mmsg(tmp, " Client.Name='%s'", esc.c_str());
- append_filter(where.handle(), tmp.c_str());
Mmsg(join, " JOIN Job ON (Job.JobId = Meta%s.JobId) JOIN Client USING (ClientId) ", meta_r->Type);
} else if (*where_filter) { // We add manually the Job join filter part
"\tevents [type=<str> | limit=<int> | order=<asc|desc> | days=<int> | start=<time-specification> | end=<time-specification> |\n"
"\t\t source=<str> | code=<str> | type=<str> ]\n"
"\tobjects [jobid=<jobid> client=<cli> type=<str> | category=<str> | status=<S> | limit=<int> | order=<asc|desc> ]\n"
- "\tmetadata type=<email|attachment> tenant=<str> owner=<str>\n"
+ "\tmetadata type=<email|attachment> tenant=<str> [owner=<str>]\n"
"\t [jobid=<jobids> client=<cc> order=<Asc|desc> limit=<nn> orderby=<time> offset=<nn>]\n"
"\t [from=<str> to=<str> cc=<str> tags=<str> subject=<str> bodypreview=<str> all=<str>\n"
"\t minsize=<int> maxsize=<int> importance=<str> isread=<0|1> isdraft=<0|1> categories=<str>\n"
* list objects [type=objecttype job_id=id clientname=n,status=S] - list plugin objects
* list pluginrestoreconf jobid=x,y,z [id=k]
* list filemedia jobid=x fileindex=z
- * list metadata type=[email|attachment] owner=xxx tenant=xxx jobid=<x,w,z> from=<str>
+ * list metadata type=[email|attachment] tenant=xxx owner=xxx jobid=<x,w,z> client=<cli>
+ * from=<str>
* to=<str> cc=<str> tags=<str>
* subject=<str> bodypreview=<str> all=<str> minsize=<int> maxsize=<int>
* importance=<str> isread=<0|1> isdraft=<0|1>
META_DBR meta_r;
for (j=i+1; j<ua->argc; j++) {
- if (strcasecmp(ua->argk[j], NT_("jobid")) == 0 && ua->argv[j]) {
+ if (!ua->argv[j]) {
+ ua->error_msg(_("Invalid %s argument. Expecting value\n"), ua->argk[j]);
+ return 1;
+ } else if (strcasecmp(ua->argk[j], NT_("jobid")) == 0) {
if (is_a_number_list(ua->argv[j]) && acl_access_jobid_ok(ua, ua->argv[j])) {
meta_r.JobIds = ua->argv[j];
} else {
} else if (strcasecmp(ua->argk[j], NT_("hasattachment")) == 0) {
meta_r.HasAttachment = str_to_uint64(ua->argv[j]);
- } else if (strcasecmp(ua->argk[j], NT_("offset")) == 0 && ua->argv[j]) {
+ } else if (strcasecmp(ua->argk[j], NT_("offset")) == 0) {
meta_r.offset = atoi(ua->argv[j]);
- } else if (strcasecmp(ua->argk[j], NT_("limit")) == 0 && ua->argv[j]) {
+ } else if (strcasecmp(ua->argk[j], NT_("limit")) == 0) {
meta_r.limit = atoi(ua->argv[j]);
- } else if (strcasecmp(ua->argk[j], NT_("orderby")) == 0 && ua->argv[j]) {
+ } else if (strcasecmp(ua->argk[j], NT_("orderby")) == 0) {
meta_r.orderby = bstrcasecmp(ua->argv[j], "Time") == 1;
- } else if (strcasecmp(ua->argk[j], NT_("order")) == 0 && ua->argv[j]) {
+ } else if (strcasecmp(ua->argk[j], NT_("order")) == 0) {
/* Other order are tested before */
meta_r.order = bstrcasecmp(ua->argv[j], "DESC");
}