void File::setTrackEvents(Event events) { #ifdef HAVE_INOTIFY if (events == d->m_events) { return; } Application::PrivateImpl *app_d = static_cast<Application::PrivateImpl*>(application()->d); if (!app_d->m_inotifyStarted) { if ((app_d->m_inotify = inotify_init1(IN_NONBLOCK)) > -1) { app_d->m_inotifyStarted = true; } } if (app_d->m_inotifyStarted) { if (events != NoEvent) { uint32_t inotifyMask = 0; if (events & AccessEvent) { inotifyMask |= IN_ACCESS; } if (events & AttributeChangeEvent) { inotifyMask |= IN_ATTRIB; } if (events & CloseEvent) { inotifyMask |= IN_CLOSE; } if (events & CreateEvent) { inotifyMask |= IN_CREATE; } if (events & DeleteEvent) { inotifyMask |= IN_DELETE; } if (events & ModifyEvent) { inotifyMask |= IN_MODIFY; } if (events & MoveEvent) { inotifyMask |= IN_MOVE; } if (events & OpenEvent) { inotifyMask |= IN_OPEN; } D_I->m_inotifyWatch = inotify_add_watch(app_d->m_inotify, uri().path().data(), inotifyMask); app_d->m_inotifyMap[D_I->m_inotifyWatch] = this; } else { inotify_rm_watch(app_d->m_inotify, D_I->m_inotifyWatch); app_d->m_inotifyMap.erase(D_I->m_inotifyWatch); if (!app_d->m_inotifyMap.size()) { app_d->m_inotifyStarted = false; close(app_d->m_inotify); } } } else { IDEAL_DEBUG_WARNING("it was not possible to track events for file " << uri().uri()); } #else if (events != NoEvent) { IDEAL_DEBUG_WARNING("it was not possible to track events for file " << uri().uri()); } #endif }
ProtocolHandler::ErrorCode BuiltinProtocolHandlersLocal::open(const Uri &uri, iint32 openMode) { if (!d->m_opened.empty() && d->m_opened.isValid()) { IDEAL_DEBUG_WARNING("the uri " << d->m_opened.uri() << " was opened. Closing"); close(); } d->m_opened = uri; if (!uri.isValid()) { return InvalidURI; } iint32 oflag = 0; if ((openMode & Read) && (openMode & Write)) { oflag = O_RDWR; } else if (openMode & Read) { oflag = O_RDONLY; } else { oflag = O_WRONLY; } d->m_fd = ::open(uri.path().data(), oflag); if (d->m_fd > -1) { return NoError; } switch (errno) { case EACCES: return InsufficientPermissions; break; default: return UnknownError; break; } }
bool BuiltinProtocolHandlersHttp::Private::sendCommand(CommandType commandType, const Uri &uri) { iint32 commandSize = 0; switch (commandType) { case Get: commandSize = strlen(m_commandGet); break; case Head: commandSize = strlen(m_commandHead); break; } commandSize += uri.host().size() + uri.path().size(); ichar *command = (ichar*) calloc(commandSize + 1, sizeof(ichar)); switch (commandType) { case Get: sprintf(command, "GET %s HTTP/1.1\r\nHost: %s\r\n\r\n", uri.path().data(), uri.host().data()); break; case Head: sprintf(command, "HEAD %s HTTP/1.1\r\nHost: %s\r\n\r\n", uri.path().data(), uri.host().data()); break; default: IDEAL_DEBUG_WARNING("unknown command type"); break; } const iint32 bytesSent = send(m_sockfd, command, commandSize, 0); free(command); return bytesSent == commandSize; }