void UPnP::start() { try { _out.init(GD::bl.get()); _out.setPrefix("UPnP Server: "); stop(); registerServers(); if(_packets.empty()) { GD::out.printWarning("Warning: Not starting server, because no suitable RPC server for serving the XML description is available (Necessary settings: No SSL, no auth, webserver enabled)."); return; } _stopServer = false; GD::bl->threadManager.start(_listenThread, true, &UPnP::listen, this); sendNotify(); } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } }
CommandExec::CommandExec(QObject *parent) : QObject(parent) , m_lastMessagesLines(0) { m_pCPart = new pCPart; m_pCPart->parser = 0; SshAgent ag; ag.querySshAgent(); connect(m_pCPart->m_SvnWrapper, SIGNAL(clientException(QString)), this, SLOT(clientException(QString))); connect(m_pCPart->m_SvnWrapper, SIGNAL(sendNotify(QString)), this, SLOT(slotNotifyMessage(QString))); m_pCPart->m_SvnWrapper->reInitClient(); }
void CXWindowsScreenSaver::setXScreenSaverActive(bool activated) { if (m_xscreensaverActive != activated) { LOG((CLOG_DEBUG "xscreensaver %s on window 0x%08x", activated ? "activated" : "deactivated", m_xscreensaver)); m_xscreensaverActive = activated; // if screen saver was activated forcefully (i.e. against // our will) then just accept it. don't try to keep it // from activating since that'll just pop up the password // dialog if locking is enabled. m_suppressDisable = activated; updateDisableJob(); sendNotify(activated); } }
int main(int argc, char * * argv) { signal(SIGPIPE, SIG_IGN); char addrStr[INET_ADDRSTRLEN]; in_addr_t addr = GetIfAddrIPv4("eth0"); inet_ntop(AF_INET, &addr, addrStr, INET_ADDRSTRLEN); printf("Using address %s\n", addrStr); char * uuid = "uuid:ABBB6631-67A4-4BA1-8E6A-C073FAE13FC1"; char location[2048]; snprintf(location, sizeof(location), "http://%s/upnp.xml?uuid=%s", addrStr, uuid); sendSspd("/var/run/minissdpd.sock", uuid, location, "upnp-beacon/1.0"); sendNotify(INADDR_ANY, uuid, location, "upnp-beacon/1.0"); return 0; }
void UPnP::processPacket(BaseLib::Http& http) { try { BaseLib::Http::Header& header = http.getHeader(); if(header.method != "M-SEARCH" || header.fields.find("st") == header.fields.end() || header.host.empty()) return; BaseLib::HelperFunctions::toLower(header.fields.at("st")); if(header.fields.at("st") == "urn:schemas-upnp-org:device:basic:1" || header.fields.at("st") == "urn:schemas-upnp-org:device:basic:1.0" || header.fields.at("st") == "ssdp:all" || header.fields.at("st") == "upnp:rootdevice" || header.fields.at("st") == _st) { if(GD::bl->debugLevel >= 5) _out.printDebug("Debug: Discovery packet received from " + header.host); std::pair<std::string, std::string> address = BaseLib::HelperFunctions::splitLast(header.host, ':'); int32_t port = BaseLib::Math::getNumber(address.second, false); if(!address.first.empty() && port > 0) { int32_t mx = 500; if(header.fields.find("mx") != header.fields.end()) mx = BaseLib::Math::getNumber(header.fields.at("mx"), false) * 1000; std::this_thread::sleep_for(std::chrono::milliseconds(20)); //Wait for 0 to mx seconds for load balancing if(mx > 500) { mx = BaseLib::HelperFunctions::getRandomNumber(0, mx - 500); GD::out.printDebug("Debug: Sleeping " + std::to_string(mx) + "ms before sending response."); std::this_thread::sleep_for(std::chrono::milliseconds(mx)); } sendOK(address.first, port, header.fields.at("st") == "upnp:rootdevice"); std::this_thread::sleep_for(std::chrono::milliseconds(100)); sendNotify(); } } } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } }
void Core::checkAutoSave(bool first) { if (_conf->getAutoSave()) { // hack if (first) { if (_conf->getAutoSaveFirst()) QTimer::singleShot(600, this, SLOT(autoSave())); } else autoSave(); } else { if (!first) { StateNotifyMessage message(tr("New screen"), tr("New screen is getted!")); sendNotify(message); } } }
bool Core::writeScreen(QString& fileName, QString& format, bool tmpScreen) { // adding extension format if (!fileName.contains("." + format)) fileName.append("." + format); // saving temp file (for uploader module) if (tmpScreen) { if (!fileName.isEmpty()) return _pixelMap->save(fileName, format.toLatin1(), _conf->getImageQuality()); else return false; } // writing file bool saved = false; if (!fileName.isEmpty()) { if (format == "jpg") saved = _pixelMap->save(fileName,format.toLatin1(), _conf->getImageQuality()); else saved = _pixelMap->save(fileName,format.toLatin1(), -1); if (saved) { StateNotifyMessage message(tr("Saved"), tr("Saved to ") + fileName); message.message = message.message + copyFileNameToCliipboard(fileName); _conf->updateLastSaveDate(); sendNotify(message); } else qWarning() << "Error saving file " << fileName; } return saved; }
void SipPhoneProxy::incomingSubscribe( SipCallMember *member, bool sendSubscribe ) { //clist->auditList(); if( member == 0 ) { return; } dbgPrintf( "KPhoneView: Incoming Subscribe\n" ); bool remove_subscribe = false; SipUri uri = member->getUri(); QString uristr = member->getUri().reqUri(); //for ( QStringList::Iterator it = rejectedContactList.begin(); it != rejectedContactList.end(); ++it ) //{ // if( uristr == QString(*it) ) // { // dbgPrintf( "KPhoneView: Incoming Subscribe Rejected\n" ); // remove_subscribe = true; // } //} SipCallIterator it( _pSipClient->getCallList() ); SipCall* current = NULL; bool find = false; if( !remove_subscribe ) { it.toFront(); while(it.hasNext()) { current = it.next(); if(current->getCallType() == SipCall::outSubscribeCall) { if(current->getMember(uri) != NULL) { find = true; } } } } if( !find && !remove_subscribe) { QString uristr = member->getUri().reqUri(); QMessageBox mb( tr("Contacts"), tr("Subscribe message from uri:") + "\n" + uristr + "\n\n" + tr("Do you want to accept and create a contact ?"), QMessageBox::Information, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape ); mb.setButtonText( QMessageBox::Yes, tr("Accept") ); mb.setButtonText( QMessageBox::No, tr("Reject permanently") ); mb.setButtonText( QMessageBox::Cancel, tr("Reject this time") ); switch( mb.exec() ) { case QMessageBox::Yes: //addContactToPhoneBook( member ); sendSubscribe = false; break; case QMessageBox::No: //rejectedContactList.append( member->getUri().reqUri() ); //saveRejectContactList(); remove_subscribe = true; break; case QMessageBox::Cancel: remove_subscribe = true; break; } } if( remove_subscribe ) { current = NULL; it.toFront(); while(it.hasNext()) { current = it.next(); if(current->getCallType() == SipCall::inSubscribeCall) { if(current->getMember(uri)) { delete current; } } } return; } if( _isOnline ) { connect( member, SIGNAL( statusUpdated( SipCallMember * ) ), _pSipAuthentication, SLOT( authRequest( SipCallMember * ) ) ); sendNotify( ONLINE, member ); } current = NULL; it.toFront(); while(it.hasNext()) { current = it.next(); if( current->getCallType() == SipCall::outSubscribeCall ) { if( current->getCallStatus() != SipCall::callDead ) { if( current->getMember( uri ) ) { if( sendSubscribe ) { if( _pSipRegister->getRegisterState() == SipRegister::Connected ) { QString uristr = current->getSubject(); QString contactStr = current->getContactStr(); if( current->getCallStatus() == SipCall::callInProgress ) { current->getMember( uri )->requestClearSubscribe(); } delete current; SipCall *newcall = new SipCall( _pSipUser, QString::null, SipCall::outSubscribeCall ); newcall->setSubject( uristr ); SipUri remoteuri( uristr ); member = new SipCallMember( newcall, remoteuri ); //connect( member, SIGNAL( statusUpdated( SipCallMember * ) ), clist, SLOT( auditList() ) ); connect( member, SIGNAL( statusUpdated( SipCallMember * ) ), _pSipAuthentication, SLOT( authRequest( SipCallMember * ) ) ); member->requestSubscribe( _subscribeExpiresTime ); newcall->setContactStr( contactStr ); break; } } } } } } }
bool XWindowsClipboard::sendReply(Reply* reply) { assert(reply != NULL); // bail out immediately if reply is done if (reply->m_done) { LOG((CLOG_DEBUG1 "clipboard: finished reply to 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property)); return true; } // start in failed state if property is None bool failed = (reply->m_property == None); if (!failed) { LOG((CLOG_DEBUG1 "clipboard: setting property on 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property)); // send using INCR if already sending incrementally or if reply // is too large, otherwise just send it. const UInt32 maxRequestSize = 3 * XMaxRequestSize(m_display); const bool useINCR = (reply->m_data.size() > maxRequestSize); // send INCR reply if incremental and we haven't replied yet if (useINCR && !reply->m_replied) { UInt32 size = reply->m_data.size(); if (!XWindowsUtil::setWindowProperty(m_display, reply->m_requestor, reply->m_property, &size, 4, m_atomINCR, 32)) { failed = true; } } // send more INCR reply or entire non-incremental reply else { // how much more data should we send? UInt32 size = reply->m_data.size() - reply->m_ptr; if (size > maxRequestSize) size = maxRequestSize; // send it if (!XWindowsUtil::setWindowProperty(m_display, reply->m_requestor, reply->m_property, reply->m_data.data() + reply->m_ptr, size, reply->m_type, reply->m_format)) { failed = true; } else { reply->m_ptr += size; // we've finished the reply if we just sent the zero // size incremental chunk or if we're not incremental. reply->m_done = (size == 0 || !useINCR); } } } // if we've failed then delete the property and say we're done. // if we haven't replied yet then we can send a failure notify, // otherwise we've failed in the middle of an incremental // transfer; i don't know how to cancel that so i'll just send // the final zero-length property. // FIXME -- how do you gracefully cancel an incremental transfer? if (failed) { LOG((CLOG_DEBUG1 "clipboard: sending failure to 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property)); reply->m_done = true; if (reply->m_property != None) { XWindowsUtil::ErrorLock lock(m_display); XDeleteProperty(m_display, reply->m_requestor, reply->m_property); } if (!reply->m_replied) { sendNotify(reply->m_requestor, m_selection, reply->m_target, None, reply->m_time); // don't wait for any reply (because we're not expecting one) return true; } else { static const char dummy = 0; XWindowsUtil::setWindowProperty(m_display, reply->m_requestor, reply->m_property, &dummy, 0, reply->m_type, reply->m_format); // wait for delete notify return false; } } // send notification if we haven't yet if (!reply->m_replied) { LOG((CLOG_DEBUG1 "clipboard: sending notify to 0x%08x,%d,%d", reply->m_requestor, reply->m_target, reply->m_property)); reply->m_replied = true; // dump every property on the requestor window to the debug2 // log. we've seen what appears to be a bug in lesstif and // knowing the properties may help design a workaround, if // it becomes necessary. if (CLOG->getFilter() >= kDEBUG2) { XWindowsUtil::ErrorLock lock(m_display); int n; Atom* props = XListProperties(m_display, reply->m_requestor, &n); LOG((CLOG_DEBUG2 "properties of 0x%08x:", reply->m_requestor)); for (int i = 0; i < n; ++i) { Atom target; String data; char* name = XGetAtomName(m_display, props[i]); if (!XWindowsUtil::getWindowProperty(m_display, reply->m_requestor, props[i], &data, &target, NULL, False)) { LOG((CLOG_DEBUG2 " %s: <can't read property>", name)); } else { // if there are any non-ascii characters in string // then print the binary data. static const char* hex = "0123456789abcdef"; for (String::size_type j = 0; j < data.size(); ++j) { if (data[j] < 32 || data[j] > 126) { String tmp; tmp.reserve(data.size() * 3); for (j = 0; j < data.size(); ++j) { unsigned char v = (unsigned char)data[j]; tmp += hex[v >> 16]; tmp += hex[v & 15]; tmp += ' '; } data = tmp; break; } } char* type = XGetAtomName(m_display, target); LOG((CLOG_DEBUG2 " %s (%s): %s", name, type, data.c_str())); if (type != NULL) { XFree(type); } } if (name != NULL) { XFree(name); } }
void ClientWS::sendNotify(ConstStrA method, const JSON::ConstValue& params) { Synchronized<FastLockR> _(lock); sendNotify(PreparedNotify(method,params,jsonFactory)); }
void Core::copyScreen() { QApplication::clipboard()->setPixmap(*_pixelMap, QClipboard::Clipboard); StateNotifyMessage message(tr("Copied"), tr("Screenshot is copied to clipboard")); sendNotify(message); }
void UPnP::listen() { try { getSocketDescriptor(); _out.printInfo("Info: Started listening."); _lastAdvertisement = BaseLib::HelperFunctions::getTimeSeconds(); char buffer[1024]; int32_t bytesReceived = 0; struct sockaddr_in si_other; socklen_t slen = sizeof(si_other); fd_set readFileDescriptor; timeval timeout; int32_t nfds = 0; BaseLib::Http http; while(!_stopServer) { try { if(!_serverSocketDescriptor || _serverSocketDescriptor->descriptor == -1) { if(_stopServer) break; std::this_thread::sleep_for(std::chrono::milliseconds(5000)); getSocketDescriptor(); continue; } timeout.tv_sec = 0; timeout.tv_usec = 100000; FD_ZERO(&readFileDescriptor); { auto fileDescriptorGuard = GD::bl->fileDescriptorManager.getLock(); fileDescriptorGuard.lock(); nfds = _serverSocketDescriptor->descriptor + 1; if(nfds <= 0) { fileDescriptorGuard.unlock(); _out.printError("Error: Socket closed (1)."); GD::bl->fileDescriptorManager.shutdown(_serverSocketDescriptor); } FD_SET(_serverSocketDescriptor->descriptor, &readFileDescriptor); } bytesReceived = select(nfds, &readFileDescriptor, NULL, NULL, &timeout); if(bytesReceived == 0) { if(BaseLib::HelperFunctions::getTimeSeconds() - _lastAdvertisement >= 60) sendNotify(); continue; } if(bytesReceived != 1) { _out.printError("Error: Socket closed (2)."); GD::bl->fileDescriptorManager.shutdown(_serverSocketDescriptor); } bytesReceived = recvfrom(_serverSocketDescriptor->descriptor, buffer, 1024, 0, (struct sockaddr *)&si_other, &slen); if(bytesReceived <= 0) continue; http.reset(); http.process(buffer, bytesReceived, false); if(http.isFinished()) processPacket(http); } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } } } catch(const std::exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(BaseLib::Exception& ex) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what()); } catch(...) { _out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__); } GD::bl->fileDescriptorManager.shutdown(_serverSocketDescriptor); }
void ClientNotifierThread::run(){ while(mIsRunning){ sendNotify(HostInfo::getComputerName()); sleep(qAbs(mSendInterval)); } }
MainWindow::MainWindow(ContactRoster *roster, bool showWhatsNew, QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); // Configure the main listView model = new ContactSelectionModel(ui->listView); model->setSortRole(Qt::UserRole + 2); ui->listView->setModel(model); ui->listView->installEventFilter(this); ChatDisplayDelegate *delegate = new ChatDisplayDelegate(ui->listView); ui->listView->setItemDelegate(delegate); connect(ui->createChatButton,SIGNAL(pressed()),this,SLOT(createChatWindow())); connect(ui->actionSettings,SIGNAL(triggered()),this,SLOT(showGlobalSettingsDialog())); connect(ui->actionStatus,SIGNAL(triggered()),this,SLOT(showStatusWindow())); connect(ui->actionQuit,SIGNAL(triggered()),this,SLOT(quit())); connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(showAboutDialog())); connect(ui->actionDonate,SIGNAL(triggered()),this,SLOT(showDonate())); connect(ui->actionSync,SIGNAL(triggered()),this,SLOT(requestSync())); connect(ui->actionProfile,SIGNAL(triggered()), this,SLOT(showProfileWindow())); connect(ui->actionAccountInfo,SIGNAL(triggered()), this,SLOT(showAccountInfoWindow())); connect(ui->actionNetworkUsage,SIGNAL(triggered()), this,SLOT(showNetworkUsageWindow())); connect(ui->actionCreateGroup,SIGNAL(triggered()), this,SLOT(showCreateGroupWindow())); connect(ui->actionBlockedContacts,SIGNAL(triggered()), this,SLOT(showBlockedContactsWindow())); connect(ui->listView,SIGNAL(clicked(QModelIndex)), this,SLOT(contactSelected(QModelIndex))); connect(this,SIGNAL(sendRightButtonClicked(QPoint)), this,SLOT(contextMenu(QPoint))); this->roster = roster; setAttribute(Qt::WA_Maemo5StackedWindow); setAttribute(Qt::WA_DeleteOnClose,false); setAttribute(Qt::WA_QuitOnClose,false); isScreenLocked = false; notifyObject = new NotifyObject(this); connect(this,SIGNAL(sendNotification(QString,FMessage)), notifyObject,SLOT(sendNotify(QString,FMessage))); newDayTimer = new QTimer(this); connect(newDayTimer,SIGNAL(timeout()),this,SLOT(updateTimestamps())); resetNewDayTimer(); loadOpenChats(); // WhatsNew Window if (showWhatsNew) { WhatsNewWindow *window = new WhatsNewWindow(this); window->setAttribute(Qt::WA_Maemo5StackedWindow); window->setAttribute(Qt::WA_DeleteOnClose); window->setWindowFlags(window->windowFlags() | Qt::Window); window->show(); } }
bool ComThread::readMessage(void) { size_t size = 4096; struct anoubis_msg *msg; char *str = NULL; wxString message; achat_rc rc; if ((channel_ == 0) || (client_ == 0)) { sendComEvent(JobCtrl::ERR_RW); return (false); } if ((msg = anoubis_msg_new(size)) == 0) { sendComEvent(JobCtrl::ERR_RW); return (false); } while(1) { rc = acc_receivemsg(channel_, (char*)(msg->u.buf), &size); if (rc != ACHAT_RC_NOSPACE) break; size *= 2; if (anoubis_msg_resize(msg, size) < 0) rc = ACHAT_RC_ERROR; } if (rc != ACHAT_RC_OK) { anoubis_msg_free(msg); sendComEvent(JobCtrl::ERR_RW); return (false); } anoubis_msg_resize(msg, size); if (Debug::checkLevel(Debug::CHAT)) { anoubis_dump_str(msg, NULL, &str); Debug::chat(wxString::FromAscii(str)); free(str); } /* This will free the message. */ int result = anoubis_client_process(client_, msg); if (result < 0) { /* Error */ /* XXX CEH */ sendComEvent(JobCtrl::ERR_RW); return (false); } else if (result == 0) { /* * Message does not fit into current protocol flow. * Skip it. */ fprintf(stderr, "ComThread: Message does not fit "); fprintf(stderr, "into protocol flow, skipping...\n"); } else if (anoubis_client_hasnotifies(client_) != 0) { struct anoubis_msg *notifyMsg = NULL; bool handled; notifyMsg = anoubis_client_getnotify(client_); handled = checkNotify(notifyMsg); if (!handled) { sendNotify(notifyMsg); } } return (true); }