void TReplicantTray::RunAddOnQuery(BVolume* volume, const char* predicate) { // Since the new BFS supports querying for attributes without // an index, we only run the query if the index exists (for // newly mounted devices only - the Deskbar will automatically // create an index for every device mounted at startup). index_info info; if (!volume->KnowsQuery() || fs_stat_index(volume->Device(), kStatusPredicate, &info) != 0) return; // run a new query on a specific volume and make it live BQuery query; query.SetVolume(volume); query.SetPredicate(predicate); query.Fetch(); int32 id; BEntry entry; while (query.GetNextEntry(&entry) == B_OK) { // scan any entries returned // attempt to load them as add-ons // collisions are handled in LoadAddOn LoadAddOn(&entry, &id); } }
void LiveQuery::_PerformQuery(BQuery& query) { status_t status = query.Fetch(); if (status != B_OK) { fprintf(stderr, "%s: bad query expression\n", kProgramName); return; } int32 count = 0; BEntry entry; BPath path; while (query.GetNextEntry(&entry) == B_OK) { if (sFilesOnly && !entry.IsFile()) continue; if (entry.GetPath(&path) != B_OK) { fprintf(stderr, "%s: could not get path for entry\n", kProgramName); continue; } printf("%s\n", sEscapeMetaChars ? BString().CharacterEscape( path.Path(), " ()?*&\"'[]^\\~|;!<>*$\t", '\\').String() : path.Path()); count++; } printf("FOUND %ld entries\n", count); }
void MailDaemonApp::ReadyToRun() { InstallDeskbarIcon(); _InitAccounts(); _UpdateAutoCheck(fSettingsFile.AutoCheckInterval()); BVolume volume; BVolumeRoster roster; fNewMessages = 0; while (roster.GetNextVolume(&volume) == B_OK) { //{char name[255];volume.GetName(name);printf("Volume: %s\n",name);} BQuery* query = new BQuery; query->SetTarget(this); query->SetVolume(&volume); query->PushAttr(B_MAIL_ATTR_STATUS); query->PushString("New"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-email"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-partial-email"); query->PushOp(B_EQ); query->PushOp(B_OR); query->PushOp(B_AND); query->Fetch(); BEntry entry; while (query->GetNextEntry(&entry) == B_OK) fNewMessages++; fQueries.AddItem(query); } BString string; MDR_DIALECT_CHOICE( if (fNewMessages > 0) string << fNewMessages; else string << "No"; if (fNewMessages != 1) string << " new messages."; else string << " new message.";, if (fNewMessages > 0)
int32 add_query_menu_items(BMenu* menu, const char* attribute, uint32 what, const char* format, bool popup) { BVolume volume; BVolumeRoster().GetBootVolume(&volume); BQuery query; query.SetVolume(&volume); query.PushAttr(attribute); query.PushString("*"); query.PushOp(B_EQ); query.Fetch(); int32 index = 0; BEntry entry; while (query.GetNextEntry(&entry) == B_OK) { BFile file(&entry, B_READ_ONLY); if (file.InitCheck() == B_OK) { BMessage* message = new BMessage(what); entry_ref ref; entry.GetRef(&ref); message->AddRef("ref", &ref); BString value; if (file.ReadAttrString(attribute, &value) < B_OK) continue; message->AddString("attribute", value.String()); BString name; if (format != NULL) name.SetToFormat(format, value.String()); else name = value; if (index < 9 && !popup) menu->AddItem(new BMenuItem(name, message, '1' + index)); else menu->AddItem(new BMenuItem(name, message)); index++; } } return index; }
BPopUpMenu* TPrefsWindow::_BuildSignatureMenu(char* sig) { char name[B_FILE_NAME_LENGTH]; BEntry entry; BFile file; BMenuItem* item; BMessage* msg; BQuery query; BVolume vol; BVolumeRoster volume; BPopUpMenu* menu = new BPopUpMenu(""); msg = new BMessage(P_SIG); msg->AddString("signature", B_TRANSLATE("None")); menu->AddItem(item = new BMenuItem(B_TRANSLATE("None"), msg)); if (!strcmp(sig, B_TRANSLATE("None"))) item->SetMarked(true); msg = new BMessage(P_SIG); msg->AddString("signature", B_TRANSLATE("Random")); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Random"), msg)); if (!strcmp(sig, B_TRANSLATE("Random"))) item->SetMarked(true); menu->AddSeparatorItem(); volume.GetBootVolume(&vol); query.SetVolume(&vol); query.SetPredicate("_signature = *"); query.Fetch(); while (query.GetNextEntry(&entry) == B_NO_ERROR) { file.SetTo(&entry, O_RDONLY); if (file.InitCheck() == B_NO_ERROR) { msg = new BMessage(P_SIG); file.ReadAttr("_signature", B_STRING_TYPE, 0, name, sizeof(name)); msg->AddString("signature", name); menu->AddItem(item = new BMenuItem(name, msg)); if (!strcmp(sig, name)) item->SetMarked(true); } } return menu; }
void DeskbarView::_RefreshMailQuery() { for (int32 i = 0; i < fNewMailQueries.CountItems(); i++) delete ((BQuery *)(fNewMailQueries.ItemAt(i))); fNewMailQueries.MakeEmpty(); BVolumeRoster volumes; BVolume volume; fNewMessages = 0; while (volumes.GetNextVolume(&volume) == B_OK) { BQuery *newMailQuery = new BQuery; newMailQuery->SetTarget(this); newMailQuery->SetVolume(&volume); newMailQuery->PushAttr(B_MAIL_ATTR_READ); newMailQuery->PushInt32(B_UNREAD); newMailQuery->PushOp(B_EQ); newMailQuery->PushAttr("BEOS:TYPE"); newMailQuery->PushString("text/x-email"); newMailQuery->PushOp(B_EQ); newMailQuery->PushAttr("BEOS:TYPE"); newMailQuery->PushString("text/x-partial-email"); newMailQuery->PushOp(B_EQ); newMailQuery->PushOp(B_OR); newMailQuery->PushOp(B_AND); newMailQuery->Fetch(); BEntry entry; while (newMailQuery->GetNextEntry(&entry) == B_OK) { if (entry.InitCheck() == B_OK) { entry_ref ref; entry.GetRef(&ref); if (!_EntryInTrash(&ref)) fNewMessages++; } } fNewMailQueries.AddItem(newMailQuery); } fStatus = (fNewMessages > 0) ? kStatusNewMail : kStatusNoMail; Invalidate(); }
bool TStatusWindow::_Exists(const char* status) { BVolume volume; BVolumeRoster().GetBootVolume(&volume); BQuery query; query.SetVolume(&volume); query.PushAttr(INDEX_STATUS); query.PushString(status); query.PushOp(B_EQ); query.Fetch(); BEntry entry; if (query.GetNextEntry(&entry) == B_NO_ERROR) return true; return false; }
uint32 FetchQuery(query_op op, const char* selection, vector<BString>& results, bool caseSensitive = false) { BQuery query; query.PushAttr("BEOS:TYPE"); query.PushString("application/x-vnd.Be-doc_bookmark"); query.PushOp(B_EQ); query.PushAttr("name"); query.PushString(selection, caseSensitive); query.PushOp(op); query.PushOp(B_AND); BVolume vol; BVolumeRoster roster; roster.GetBootVolume(&vol); query.SetVolume(&vol); if (B_NO_INIT == query.Fetch()) return 0; BEntry entry; BPath path; int32 counter = 0; while (query.GetNextEntry(&entry) != B_ENTRY_NOT_FOUND) { if (entry.InitCheck() == B_OK) { entry.GetPath(&path); if (path.InitCheck() == B_OK) { results.push_back(path.Path()); counter++; } } } return counter; }
int main(int argc, char** argv) { if (argc < 2) { fprintf(stderr, "usage: %s <message-code>\n", __progname); return -1; } int32 number = atol(argv[1]); BQuery query; query.SetPredicate("name=ServerProtocol.h"); // search on current volume only dev_t device = dev_for_path("."); BVolume volume(device); query.SetVolume(&volume); query.Fetch(); status_t status; BEntry entry; while ((status = query.GetNextEntry(&entry)) == B_OK) { BPath path(&entry); puts(path.Path()); if (strstr(path.Path(), "headers/private/app/ServerProtocol.h") != NULL) { print_code(path, number); break; } } if (status != B_OK) { fprintf(stderr, "%s: could not find ServerProtocol.h", __progname); return -1; } return 0; }
bool duplicates_exist (const char * signature) { BVolumeRoster roster; BVolume volume; BQuery query; BString query_string = "BEOS:APP_SIG="; BEntry entry; mode_t permissions; uid_t owner; gid_t group; int32 query_hits = 0; query_string += signature; while (roster.GetNextVolume(& volume) == B_OK) { if (volume.KnowsQuery()) { PRINT(("volume.KnowsQuery()\n")); char volname [B_FILE_NAME_LENGTH]; volume.GetName(volname); PRINT(("volume: %s\n", volname)); query.Clear(); if (query.SetVolume(& volume) == B_OK) { PRINT(("query.SetVolume(& volume) == B_OK\n")); if (query.SetPredicate(query_string.String()) == B_OK) { PRINT(("query.SetPredicate(%s) == B_OK\n", query_string.String())); if (query.Fetch() == B_OK) { PRINT(("query.Fetch() == B_OK\n")); while (query.GetNextEntry(& entry) == B_OK) { PRINT(("query.GetNextEntry(& entry) == B_OK\n")); entry.GetPermissions(& permissions); entry.GetOwner(& owner); entry.GetGroup(& group); BPath path (& entry); // if (access(path.Path(), X_OK)) if (((owner == getuid()) && (permissions & S_IXUSR)) || ((group == getgid()) && (permissions & S_IXGRP)) || (permissions & S_IXOTH)) { PRINT(("path is executable: %s\n", path.Path())); query_hits++; } else { PRINT(("path is NOT executable: %s\n", path.Path())); } } } } } } fflush(stdout); } if (query_hits > 1) return true; else return false; }
void PersonView::BuildGroupMenu() { if (fGroups == NULL) return; BMenuItem* item; while ((item = fGroups->ItemAt(0)) != NULL) { fGroups->RemoveItem(item); delete item; } int32 count = 0; BVolumeRoster volumeRoster; BVolume volume; while (volumeRoster.GetNextVolume(&volume) == B_OK) { BQuery query; query.SetVolume(&volume); char buffer[256]; snprintf(buffer, sizeof(buffer), "%s=*", fCategoryAttribute.String()); query.SetPredicate(buffer); query.Fetch(); BEntry entry; while (query.GetNextEntry(&entry) == B_OK) { BFile file(&entry, B_READ_ONLY); attr_info info; if (file.InitCheck() == B_OK && file.GetAttrInfo(fCategoryAttribute, &info) == B_OK && info.size > 1) { if (info.size > (off_t)sizeof(buffer)) info.size = sizeof(buffer); if (file.ReadAttr(fCategoryAttribute.String(), B_STRING_TYPE, 0, buffer, info.size) < 0) { continue; } const char *text = buffer; while (true) { char* offset = strstr(text, ","); if (offset != NULL) offset[0] = '\0'; if (!fGroups->FindItem(text)) { int32 index = 0; while ((item = fGroups->ItemAt(index)) != NULL) { if (strcmp(text, item->Label()) < 0) break; index++; } BMessage* message = new BMessage(M_GROUP_MENU); message->AddString("group", text); fGroups->AddItem(new BMenuItem(text, message), index); count++; } if (offset) { text = offset + 1; while (*text == ' ') text++; } else break; } } } } if (count == 0) { fGroups->AddItem(item = new BMenuItem( B_TRANSLATE_CONTEXT("none", "Groups list"), new BMessage(M_GROUP_MENU))); item->SetEnabled(false); } fGroups->SetTargetForItems(this); }
void MailDaemonApp::SendPendingMessages(BMessage* msg) { BVolumeRoster roster; BVolume volume; map<int32, send_mails_info> messages; int32 account = -1; if (msg->FindInt32("account", &account) != B_OK) account = -1; if (!msg->HasString("message_path")) { while (roster.GetNextVolume(&volume) == B_OK) { BQuery query; query.SetVolume(&volume); query.PushAttr(B_MAIL_ATTR_FLAGS); query.PushInt32(B_MAIL_PENDING); query.PushOp(B_EQ); query.PushAttr(B_MAIL_ATTR_FLAGS); query.PushInt32(B_MAIL_PENDING | B_MAIL_SAVE); query.PushOp(B_EQ); if (account >= 0) { query.PushAttr(B_MAIL_ATTR_ACCOUNT_ID); query.PushInt32(account); query.PushOp(B_EQ); query.PushOp(B_AND); } query.PushOp(B_OR); query.Fetch(); BEntry entry; while (query.GetNextEntry(&entry) == B_OK) { if (_IsEntryInTrash(entry)) continue; BNode node; while (node.SetTo(&entry) == B_BUSY) snooze(1000); if (!_IsPending(node)) continue; int32 messageAccount; if (node.ReadAttr(B_MAIL_ATTR_ACCOUNT_ID, B_INT32_TYPE, 0, &messageAccount, sizeof(int32)) < 0) messageAccount = -1; off_t size = 0; node.GetSize(&size); entry_ref ref; entry.GetRef(&ref); messages[messageAccount].files.push_back(ref); messages[messageAccount].totalSize += size; } } } else { const char* path; if (msg->FindString("message_path", &path) != B_OK) return; off_t size = 0; if (BNode(path).GetSize(&size) != B_OK) return; BEntry entry(path); entry_ref ref; entry.GetRef(&ref); messages[account].files.push_back(ref); messages[account].totalSize += size; } map<int32, send_mails_info>::iterator iter = messages.begin(); for (; iter != messages.end(); iter++) { OutboundProtocolThread* protocolThread = _FindOutboundProtocol( iter->first); if (!protocolThread) continue; send_mails_info& info = iter->second; if (info.files.size() == 0) continue; MailProtocol* protocol = protocolThread->Protocol(); protocolThread->Lock(); protocol->SetTotalItems(info.files.size()); protocol->SetTotalItemsSize(info.totalSize); protocolThread->Unlock(); protocolThread->SendMessages(iter->second.files, info.totalSize); } }
void MailDaemonApp::ReadyToRun() { InstallDeskbarIcon(); _InitAccounts(); _UpdateAutoCheck(fSettingsFile.AutoCheckInterval()); BVolume volume; BVolumeRoster roster; fNewMessages = 0; while (roster.GetNextVolume(&volume) == B_OK) { BQuery* query = new BQuery; query->SetTarget(this); query->SetVolume(&volume); query->PushAttr(B_MAIL_ATTR_STATUS); query->PushString("New"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-email"); query->PushOp(B_EQ); query->PushAttr("BEOS:TYPE"); query->PushString("text/x-partial-email"); query->PushOp(B_EQ); query->PushOp(B_OR); query->PushOp(B_AND); query->Fetch(); BEntry entry; while (query->GetNextEntry(&entry) == B_OK) fNewMessages++; fQueries.AddItem(query); } BString string, numString; if (fNewMessages > 0) { if (fNewMessages != 1) string << B_TRANSLATE("%num new messages."); else string << B_TRANSLATE("%num new message."); numString << fNewMessages; string.ReplaceFirst("%num", numString); } else string = B_TRANSLATE("No new messages"); fCentralBeep = false; fNotification = new BNotification(B_INFORMATION_NOTIFICATION); fNotification->SetGroup(B_TRANSLATE("Mail status")); fNotification->SetTitle(string); fNotification->SetMessageID("daemon_status"); app_info info; be_roster->GetAppInfo(B_MAIL_DAEMON_SIGNATURE, &info); BBitmap icon(BRect(0, 0, 32, 32), B_RGBA32); BNode node(&info.ref); BIconUtils::GetVectorIcon(&node, "BEOS:ICON", &icon); fNotification->SetIcon(&icon); fLEDAnimation = new LEDAnimation; SetPulseRate(1000000); }