int update_resource(auparse_state_t *au, const char *uuid, uid_t uid, time_t time, const char *name, int success, const char *reason, const char *res_type, const char *res) { if (!is_resource(res) || !success) return 0; list_node_t *it; struct event *start = NULL; /* Find the last start event for the uuid */ for (it = events->tail; it; it = it->prev) { start = it->data; if (start->type == ET_RES && start->success && start->uuid && strcmp(uuid, start->uuid) == 0 && strcmp(res_type, start->res_type) == 0 && strcmp(res, start->res) == 0) break; } if (it == NULL) { if (debug) { fprintf(stderr, "Couldn't find the correlated resource" " record to update for %s.\n", res_type); } return 0; } start->end = time; add_proof(start, au); return 0; }
void M2MTLVDeserializer::deserialize_resources(uint8_t *tlv, uint32_t tlv_size, M2MResourceList &list) { if (!is_resource(tlv) && !is_multiple_resource(tlv)) { return ; } deserialize_resources(tlv, tlv_size, 0, list ); }
void scan_merged(unsigned char *addr, size_t len, struct psd_header *h) { size_t i, j = 0; unsigned ps_ptr_bytes = 2 << h->version; h->lmistart = h->lmilen = 0; // first search for a valid image resource block (these precede layer/mask info) for(i = 0; i < len;) { j = is_resource(addr, len, i); if(j && j < len-4){ VERBOSE("scavenge: possible resource id=%d @ %lu\n", peek2B(addr+i+4), (unsigned long)i); i = j; // found an apparently valid resource; skip over it // is it followed by another resource? if(memcmp("8BIM", addr+j, 4)) break; // no - stop looking }else ++i; } if(!j) alwayswarn("Did not find any plausible image resources; probably cannot locate merged image data.\n"); for(i = j; i < len; ++i) { psd_bytes_t lmilen = h->version == 2 ? peek8B(addr+i) : peek4B(addr+i), layerlen = h->version == 2 ? peek8B(addr+i+ps_ptr_bytes) : peek4B(addr+i+ps_ptr_bytes); if(lmilen > 0 && (i+lmilen) < len && layerlen == 0) { // sanity check compression type int comptype = peek2Bu(addr + i + lmilen); if(comptype == 0 || comptype == 1) { h->lmistart = i+ps_ptr_bytes; h->lmilen = lmilen; VERBOSE("scavenge: possible empty LMI @ %lld\n", h->lmistart); UNQUIET( "May be able to recover merged image if you can provide correct values\n\ for --mergedrows, --mergedcols, --mergedchan, --depth and --mode.\n"); break; // take first one } }
int add_resource(auparse_state_t *au, const char *uuid, uid_t uid, time_t time, const char *name, int success, const char *reason, const char *res_type, const char *res) { if (!is_resource(res)) return 0; struct event *event = event_alloc(); if (event == NULL) return 1; event->type = ET_RES; event->uuid = copy_str(uuid); event->name = copy_str(name); event->success = success; event->reason = copy_str(reason); event->res_type = copy_str(res_type); event->res = copy_str(res); event->uid = uid; event->start = time; add_proof(event, au); /* Get cgroup specific fields. */ if (strcmp("cgroup", res_type) == 0) { event->cgroup_class = copy_str(auparse_find_field(au, "class")); if (event->cgroup_class) { const char *detail = NULL; if (strcmp("path", event->cgroup_class) == 0) { if (auparse_find_field(au, "path")) detail = auparse_interpret_field(au); } else if (strcmp("major", event->cgroup_class) == 0) { detail = auparse_find_field(au, "category"); } event->cgroup_detail = copy_str(detail); } event->cgroup_acl = copy_str(auparse_find_field(au, "acl")); } if (list_append(events, event) == NULL) { event_free(event); return 1; } return 0; }
bool M2MTLVDeserializer::is_resource(uint8_t *tlv) { return is_resource(tlv, 0); }
void FileTypes::RefsReceived(BMessage *message) { bool traverseLinks = (modifiers() & B_SHIFT_KEY) == 0; // filter out applications and entries we can't open int32 index = 0; entry_ref ref; while (message->FindRef("refs", index++, &ref) == B_OK) { BEntry entry; BFile file; status_t status = entry.SetTo(&ref, traverseLinks); if (status == B_OK) status = file.SetTo(&entry, B_READ_ONLY); if (status != B_OK) { // file cannot be opened char buffer[1024]; snprintf(buffer, sizeof(buffer), B_TRANSLATE("Could not open \"%s\":\n" "%s"), ref.name, strerror(status)); (new BAlert(B_TRANSLATE("FileTypes request"), buffer, B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); message->RemoveData("refs", --index); continue; } if (!is_application(file) && !is_resource(file)) { if (entry.GetRef(&ref) == B_OK) message->ReplaceRef("refs", index - 1, &ref); continue; } // remove application from list message->RemoveData("refs", --index); // There are some refs left that want to be handled by the type window BPoint point(100.0f + kCascadeOffset * fTypeWindowCount, 110.0f + kCascadeOffset * fTypeWindowCount); BWindow* window = new ApplicationTypeWindow(point, entry); window->Show(); fTypeWindowCount++; fWindowCount++; } if (message->FindRef("refs", &ref) != B_OK) return; // There are some refs left that want to be handled by the type window BPoint point(100.0f + kCascadeOffset * fTypeWindowCount, 110.0f + kCascadeOffset * fTypeWindowCount); BWindow* window = new FileTypeWindow(point, *message); window->Show(); fTypeWindowCount++; fWindowCount++; }
SERD_API SerdStatus serd_writer_write_statement(SerdWriter* writer, SerdStatementFlags flags, const SerdNode* graph, const SerdNode* subject, const SerdNode* predicate, const SerdNode* object, const SerdNode* datatype, const SerdNode* lang) { if (!subject || !predicate || !object || !subject->buf || !predicate->buf || !object->buf || !is_resource(subject) || !is_resource(predicate)) { return SERD_ERR_BAD_ARG; } #define TRY(write_result) \ if (!write_result) { \ return SERD_ERR_UNKNOWN; \ } switch (writer->syntax) { case SERD_NTRIPLES: TRY(write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags)); sink(" ", 1, writer); TRY(write_node(writer, predicate, NULL, NULL, FIELD_PREDICATE, flags)); sink(" ", 1, writer); TRY(write_node(writer, object, datatype, lang, FIELD_OBJECT, flags)); sink(" .\n", 3, writer); return SERD_SUCCESS; default: break; } if ((flags & SERD_LIST_CONT)) { if (write_list_obj(writer, flags, predicate, object, datatype, lang)) { // Reached end of list if (--writer->list_depth == 0 && writer->list_subj.type) { reset_context(writer, true); writer->context.subject = writer->list_subj; writer->list_subj = SERD_NODE_NULL; } return SERD_SUCCESS; } } else if (serd_node_equals(subject, &writer->context.subject)) { if (serd_node_equals(predicate, &writer->context.predicate)) { // Abbreviate S P if (!(flags & SERD_ANON_O_BEGIN)) { ++writer->indent; } write_sep(writer, SEP_END_O); write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); if (!(flags & SERD_ANON_O_BEGIN)) { --writer->indent; } } else { // Abbreviate S Sep sep = writer->context.predicate.type ? SEP_END_P : SEP_S_P; write_sep(writer, sep); write_pred(writer, flags, predicate); write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); } } else { // No abbreviation if (writer->context.subject.type) { assert(writer->indent > 0); --writer->indent; if (serd_stack_is_empty(&writer->anon_stack)) { write_sep(writer, SEP_END_S); } } else if (!writer->empty) { write_sep(writer, SEP_S_P); } if (!(flags & SERD_ANON_CONT)) { write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags); ++writer->indent; write_sep(writer, SEP_S_P); } else { ++writer->indent; } reset_context(writer, true); copy_node(&writer->context.subject, subject); if (!(flags & SERD_LIST_S_BEGIN)) { write_pred(writer, flags, predicate); } write_node(writer, object, datatype, lang, FIELD_OBJECT, flags); } if (flags & (SERD_ANON_S_BEGIN|SERD_ANON_O_BEGIN)) { WriteContext* ctx = (WriteContext*)serd_stack_push( &writer->anon_stack, sizeof(WriteContext)); *ctx = writer->context; WriteContext new_context = { serd_node_copy(graph), serd_node_copy(subject), SERD_NODE_NULL }; if ((flags & SERD_ANON_S_BEGIN)) { new_context.predicate = serd_node_copy(predicate); } writer->context = new_context; } else { copy_node(&writer->context.graph, graph); copy_node(&writer->context.subject, subject); copy_node(&writer->context.predicate, predicate); } return SERD_SUCCESS; }