AuthorizationRecord QJsonUIDAuthority::clientConnected(QJsonStream *stream) { AuthorizationRecord authRecord; authRecord.state = QJsonAuthority::StateNotAuthorized; if (!stream) return authRecord; QLocalSocket *socket = qobject_cast<QLocalSocket*>(stream->device()); if (!socket) return authRecord; if (socket->socketDescriptor() == (qintptr)-1) { qWarning() << Q_FUNC_INFO << "no socket descriptor available for connection" << socket; return authRecord; } uid_t euid; #if defined(Q_OS_MAC) gid_t egid; if (::getpeereid(socket->socketDescriptor(), &euid, &egid) != 0) { qWarning() << "getpeereid failed with errcode" << errno << socket->socketDescriptor(); return authRecord; } #else // Check the UID table and return Authorized if appropriate. struct ucred cr; socklen_t len = sizeof(struct ucred); if (::getsockopt(socket->socketDescriptor(), SOL_SOCKET, SO_PEERCRED, &cr, &len) != 0) { qWarning() << "getsockopt failed with errcode" << errno << socket->socketDescriptor(); return authRecord; } euid = cr.uid; #endif if (m_nameForUid.contains(euid)) { authRecord.identifier = m_nameForUid.value(euid); authRecord.state = StateAuthorized; } return authRecord; }
int qt_waitforinput(void) { #ifdef USE_MOUSE fd_set read_fds; int stdin_fd = fileno(stdin); int socket_fd = qt_socket.socketDescriptor(); if (!qt_initialized || (socket_fd < 0) || (qt_socket.state() != QLocalSocket::ConnectedState)) return getchar(); // Gnuplot event loop do { // Watch file descriptors FD_ZERO(&read_fds); FD_SET(socket_fd, &read_fds); if (!paused_for_mouse) FD_SET(stdin_fd, &read_fds); // Wait for input if (select(socket_fd+1, &read_fds, NULL, NULL, NULL) < 0) { fprintf(stderr, "Qt terminal communication error: select() error\n"); break; } // Terminal event coming if (FD_ISSET(socket_fd, &read_fds)) { qt_socket.waitForReadyRead(-1); while (qt_socket.bytesAvailable() >= sizeof(gp_event_t)) { struct gp_event_t event; qt_socket.read((char*) &event, sizeof(gp_event_t)); /// @todo don't process mouse move events if others are in the queue if (qt_processTermEvent(&event)) return '\0'; // exit from paused_for_mouse } } } while (paused_for_mouse || (!paused_for_mouse && !FD_ISSET(stdin_fd, &read_fds))); #endif return getchar(); }
void QServer::readSocket() { //Pointer to the signal sender QLocalSocket * socket = (QLocalSocket*)sender(); //Read all data on the socket & store it on a QByteArray QByteArray block = socket->readAll(); //Data stream to easy read all data QDataStream in(&block, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_5_4); while (!in.atEnd()) //loop needed cause some messages can come on a single packet { QString receiveString; in >> receiveString; receiveString.prepend(QString("%1 :: ").arg(socket->socketDescriptor())); emit sms(receiveString); } }
int qt_waitforinput(void) { #ifdef USE_MOUSE fd_set read_fds; int stdin_fd = fileno(stdin); int socket_fd = qt_socket.socketDescriptor(); if (!qt_initialized || (socket_fd < 0) || (qt_socket.state() != QLocalSocket::ConnectedState)) return getchar(); // Gnuplot event loop do { // Watch file descriptors FD_ZERO(&read_fds); FD_SET(socket_fd, &read_fds); if (!paused_for_mouse) FD_SET(stdin_fd, &read_fds); // Wait for input if (select(socket_fd+1, &read_fds, NULL, NULL, NULL) < 0) { // Display the error message except when Ctrl + C is pressed if (errno != 4) fprintf(stderr, "Qt terminal communication error: select() error %i %s\n", errno, strerror(errno)); break; } // Terminal event coming if (FD_ISSET(socket_fd, &read_fds)) { if (!(qt_socket.waitForReadyRead(-1))) { // Must be a socket error; we need to restart qt_gnuplot qDebug() << "Error: gnuplot_qt socket not responding"; qt_gnuplot_qtStarted = false; return '\0'; } // Temporary event for mouse move events. If several consecutive // move events are received, only transmit the last one. gp_event_t tempEvent; tempEvent.type = -1; if (qt_socket.bytesAvailable() < sizeof(gp_event_t)) { qDebug() << "Error: short read from gnuplot_qt socket"; return '\0'; } while (qt_socket.bytesAvailable() >= sizeof(gp_event_t)) { struct gp_event_t event; qt_socket.read((char*) &event, sizeof(gp_event_t)); // Delay move events if (event.type == GE_motion) tempEvent = event; // Other events. Replay the last move event if present else { if (tempEvent.type == GE_motion) { qt_processTermEvent(&tempEvent); tempEvent.type = -1; } if (qt_processTermEvent(&event)) return '\0'; // exit from paused_for_mouse } } // Replay move event if (tempEvent.type == GE_motion) qt_processTermEvent(&tempEvent); } } while (paused_for_mouse || (!paused_for_mouse && !FD_ISSET(stdin_fd, &read_fds))); #endif return getchar(); }