Пример #1
0
void ServerSocketNotify::bind(const char *path)
{
    if (m_listener)
        getSocketFactory()->remove(m_listener);
    m_listener = getSocketFactory()->createServerSocket();
    m_listener->setNotify(this);
    m_listener->bind(path);
}
Пример #2
0
void ServerSocketNotify::bind(unsigned short minPort, unsigned short maxPort, TCPClient *client)
{
    if (m_listener)
        getSocketFactory()->remove(m_listener);
    m_listener = getSocketFactory()->createServerSocket();
    m_listener->setNotify(this);
    m_listener->bind(minPort, maxPort, client);
}
Пример #3
0
ClientSocket::~ClientSocket()
{
    if (m_sock)
        delete m_sock;
    for (list<ClientSocket*>::iterator it = getSocketFactory()->p->errSockets.begin(); it != getSocketFactory()->p->errSockets.end(); ++it){
        if ((*it) == this){
            getSocketFactory()->p->errSockets.erase(it);
            break;
        }
    }
}
Пример #4
0
void ClientSocket::error_state(const char *err, unsigned code)
{
    list<ClientSocket*>::iterator it;
    for (it = getSocketFactory()->p->errSockets.begin(); it != getSocketFactory()->p->errSockets.end(); ++it)
        if ((*it) == this) return;
    errString = "";
    errCode = code;
    if (err)
        errString = err;
    getSocketFactory()->p->errSockets.push_back(this);
    QTimer::singleShot(0, getSocketFactory(), SLOT(idle()));
}
Пример #5
0
void SIMClientSocket::slotConnected()
{
    log(L_DEBUG, "Connected");
    timerStop();
    if (notify) notify->connect_ready();
    getSocketFactory()->setActive(true);
}
Пример #6
0
void SIMResolver::resolveTimeout()
{
    bDone    = true;
    bTimeout = true;
    getSocketFactory()->setActive(false);
    QTimer::singleShot(0, parent(), SLOT(resultsReady()));
}
Пример #7
0
void ServerSocketNotify::setListener(ServerSocket *listener)
{
    if (m_listener)
        getSocketFactory()->remove(m_listener);
    m_listener = listener;
    if (m_listener)
        m_listener->setNotify(this);
}
Пример #8
0
void SIMServerSocket::error(const char *err)
{
    close();
    if (notify && notify->error(err)){
        notify->m_listener = NULL;
        getSocketFactory()->remove(this);
    }
}
Пример #9
0
void Proxy::proxy_connect_ready()
{
    static_cast<ClientSocket*>(notify)->setSocket(m_sock);
    m_sock = NULL;
    if (notify)
        notify->connect_ready();
    getSocketFactory()->remove(this);
}
Пример #10
0
ClientSocket::ClientSocket(ClientSocketNotify *notify)
{
    m_notify = notify;
    bRawMode = false;
    bClosed  = false;
    m_sock = getSocketFactory()->createSocket();
    m_sock->setNotify(this);
}
Пример #11
0
void SIMClientSocket::slotLookupFinished(int state)
{
    log(L_DEBUG, "Lookup finished %u", state);
    if (state == 0){
        log(L_WARN, "Can't lookup");
        notify->error_state(I18N_NOOP("Connect error"));
        getSocketFactory()->setActive(false);
    }
}
Пример #12
0
Listener::Listener(ProxyPlugin *plugin, ProxyData *_data, ServerSocketNotify *notify, unsigned long ip)
{
    m_ip     = ip;
    m_plugin = plugin;
    m_sock   = getSocketFactory()->createSocket();
    m_sock->setNotify(this);
    data     = *_data;
    notify->setListener(this);
}
Пример #13
0
void ClientSocket::setSocket(Socket *s, bool bClearError)
{
    if (m_sock){
        if (m_sock->notify == this)
            m_sock->setNotify(NULL);
		if (bClearError){
			list<ClientSocket*>::iterator it;
			for (it = getSocketFactory()->p->errSockets.begin(); it != getSocketFactory()->p->errSockets.end(); ++it){
				if ((*it) == this){
					getSocketFactory()->p->errSockets.erase(it);
					break;
				}
            }
        }
    }
    m_sock = s;
    if (s)
        s->setNotify(this);
}
Пример #14
0
void Proxy::proxy_connect_ready()
{
    if (notify){
        SocketNotify *n = notify;
        static_cast<ClientSocket*>(n)->setSocket(m_sock);
        m_sock = NULL;
        n->connect_ready();
    }
    getSocketFactory()->remove(this);
}
Пример #15
0
void WeatherPlugin::timeout()
{
    if (!getSocketFactory()->isActive() || m_fetch_id || (*getURL() == 0))
        return;
    time_t now;
    time(&now);
    if ((unsigned)now < getTime() + CHECK_INTERVAL)
        return;
    m_fetch_id = fetch(NULL, getURL());
}
Пример #16
0
void SIMClientSocket::slotConnectionClosed()
{
    log(L_WARN, "Connection closed");
    timerStop();
    if (notify)
        notify->error_state(I18N_NOOP("Connection closed"));
#ifdef WIN32
    bool bState;
    if (get_connection_state(bState) && !bState)
        getSocketFactory()->setActive(false);
#endif
}
Пример #17
0
void SIMClientSocket::connect(const char *_host, int _port)
{
    port = _port;
    host = _host;
    log(L_DEBUG, "Connect to %s:%u", host.c_str(), port);
    if (inet_addr(host.c_str()) == INADDR_NONE){
        log(L_DEBUG, "Start resolve %s", host.c_str());
        SIMSockets *s = static_cast<SIMSockets*>(getSocketFactory());
        QObject::connect(s, SIGNAL(resolveReady(unsigned long, const char*)), this, SLOT(resolveReady(unsigned long, const char*)));
        s->resolve(host.c_str());
        return;
    }
Пример #18
0
unsigned SIM::fetch(const char *url, Buffer *postData, const char *headers, bool bRedirect)
{
#ifdef WIN32
    bool bState;
    if (get_connection_state(bState))
        getSocketFactory()->setActive(bState);
#endif
    FetchClient *client = new FetchClient(url, postData, headers, bRedirect);
    if (client->id())
        return client->id();
    delete client;
    return 0;
}
Пример #19
0
void WeatherPlugin::timeout()
{
    if (!getSocketFactory()->isActive() || m_fetch_id || (*getID() == 0))
        return;
    time_t now;
    time(&now);
    if ((unsigned)now < getTime() + CHECK_INTERVAL)
        return;
	string url = "http://xoap.weather.com/weather/local/";
	url += getID();
	url += "?cc=*&prod=xoap&par=1004517364&key=a29796f587f206b2&unit=";
	url += getUnits() ? "s" : "m";
    m_fetch_id = fetch(url.c_str());
}
Пример #20
0
void UpdatePlugin::timeout()
{
    if (!getSocketFactory()->isActive() || m_fetch_id)
        return;
    time_t now;
    time(&now);
    if ((unsigned)now >= getTime() + CHECK_INTERVAL){
        string url = "http://sim.shutoff.ru/cgi-bin/update1.pl?v=" VERSION;
#ifdef WIN32
        url += "&os=1";
#else
#ifdef QT_MACOSX_VERSION
        url += "&os=2";
#endif
#endif
#ifdef CVS_BUILD
        url += "&cvs=";
        for (const char *p = __DATE__; *p; p++){
            if (*p == ' '){
                url += "%20";
                continue;
            }
            url += *p;
        }
#else
        url += "&release";
#endif
        url += "&l=";
        QString s = i18n("Message", "%n messages", 1);
        s = s.replace(QRegExp("1 "), "");
        for (int i = 0; i < (int)(s.length()); i++){
            unsigned short c = s[i].unicode();
            if ((c == ' ') || (c == '%') || (c == '=') || (c == '&')){
                char b[5];
                sprintf(b, "%02X", c);
                url += b;
            }else if (c > 0x77){
                char b[10];
                sprintf(b, "#%04X", c);
                url += b;
            }else{
                url += (char)c;
            }
        }
        TCPClient *client = NULL;
        if (getContacts()->nClients())
            client = static_cast<TCPClient*>(getContacts()->getClient(0));
        m_fetch_id = fetch(NULL, url.c_str());
    }
}
Пример #21
0
int HTTP_Proxy::read(char *buf, unsigned int size)
{
    if (!m_bHTTP)
        return HTTPS_Proxy::read(buf, size);
    if (m_head.empty())
        return 0;
    if (size > m_head.length())
        size = m_head.length();
    memcpy(buf, m_head.c_str(), size);
    m_head = m_head.substr(size);
    if (m_head.empty()){
        static_cast<ClientSocket*>(notify)->setSocket(m_sock);
        m_sock = NULL;
        getSocketFactory()->remove(this);
    }
    return size;
}
Пример #22
0
void WeatherPlugin::timeout()
{
    if (!getSocketFactory()->isActive() || !isDone() || (*getID() == 0))
        return;
    time_t now = time(NULL);
    if ((unsigned)now < getTime() + CHECK1_INTERVAL)
        return;
    m_bForecast = false;
    if ((unsigned)now >= getForecastTime() + CHECK2_INTERVAL)
        m_bForecast = true;
    string url = "http://xoap.weather.com/weather/local/";
    url += getID();
    url += "?cc=*&prod=xoap&par=1004517364&key=a29796f587f206b2&unit=";
    url += getUnits() ? "s" : "m";
    if (m_bForecast && getForecast()){
        url += "&dayf=";
        url += number(getForecast());
    }
    fetch(url.c_str());
}
Пример #23
0
bool TCPClient::error_state(const char *err, unsigned code)
{
    log(L_DEBUG, "Socket error %s (%u)", err, code);
    if (m_reconnect == NO_RECONNECT){
        m_timer->stop();
        setStatus(STATUS_OFFLINE, getCommonStatus());
        setState(Error, err, code);
        return false;
    }
    if (!m_timer->isActive()){
        unsigned reconnectTime = m_reconnect;
        if (!getSocketFactory()->isActive()){
            if (reconnectTime < RECONNECT_IFINACTIVE)
                reconnectTime = RECONNECT_IFINACTIVE;
        }
        setClientStatus(STATUS_OFFLINE);
        setState((m_reconnect == NO_RECONNECT) ? Error : Connecting, err, code);
        m_bWaitReconnect = true;
        log(L_DEBUG, "Wait reconnect %u sec", reconnectTime);
        m_timer->start(reconnectTime * 1000);
    }
    return false;
}
Пример #24
0
void SIMClientSocket::connect(const char *_host, unsigned short _port)
{
    port = _port;
    host = _host;
#ifdef WIN32
    bool bState;
    if (get_connection_state(bState) && !bState){
        QTimer::singleShot(0, this, SLOT(slotConnectionClosed()));
        return;
    }
#endif
    log(L_DEBUG, "Connect to %s:%u", host.c_str(), port);
    if (inet_addr(host.c_str()) == INADDR_NONE){
        if (!host.empty() && (host[host.length() - 1] != '.'))
            host += ".";
        log(L_DEBUG, "Start resolve %s", host.c_str());
        SIMSockets *s = static_cast<SIMSockets*>(getSocketFactory());
        QObject::connect(s, SIGNAL(resolveReady(unsigned long, const char*)), this, SLOT(resolveReady(unsigned long, const char*)));
        s->resolve(host.c_str());
        return;
    }
    resolveReady(inet_addr(host.c_str()), host.c_str());
}
Пример #25
0
void SIMServerSocket::activated(int)
{
    if (sock == NULL) return;
    int fd = sock->accept();
    if (fd >= 0){
        log(L_DEBUG, "accept ready");
        if (notify){
            QSocket *s = new QSocket;
            s->setSocket(fd);
            if (notify->accept(new SIMClientSocket(s), htonl(s->address().ip4Addr()))){
                if (notify)
                    notify->m_listener = NULL;
                getSocketFactory()->remove(this);
            }
        }else{
#ifdef WIN32
            ::closesocket(fd);
#else
            ::close(fd);
#endif
        }
    }
}
Пример #26
0
void UpdatePlugin::timeout()
{
	if (!getSocketFactory()->isActive() || m_fetch_id)
		return;
	time_t now;
	time(&now);
	if ((unsigned)now >= getTime() + CHECK_INTERVAL){
		string url = "http://sim.shutoff.ru/cgi-bin/update.pl?v=" VERSION;
#ifdef WIN32
		url += "&os=1";
#endif
#ifdef CVS_BUILD
		url += "&cvs=";
		for (const char *p = __DATE__; *p; p++){
			if (p == ' '){
				url += "%20";
				continue;
			}
			url += *p;
		}
#endif
		m_fetch_id = fetch(NULL, url.c_str());
	}
}
Пример #27
0
ClientSocket::~ClientSocket()
{
    if (m_sock)
        delete m_sock;
    getSocketFactory()->p->errSockets.remove(this);
}
Пример #28
0
void FetchClient::fetch(const char *url, const char *headers, Buffer *postData, bool bRedirect)
{
    getSocketFactory()->checkState();
    p->fetch(url, headers, postData, bRedirect);
}
Пример #29
0
ServerSocketNotify::~ServerSocketNotify()
{
    if (m_listener)
        getSocketFactory()->remove(m_listener);
}
Пример #30
0
void StatusLabel::setPict()
{
    string icon;
    const char *text;
    if (m_client->getState() == Client::Connecting){
        if (getSocketFactory()->isActive()){
            if (m_timer == NULL){
                m_timer = new QTimer(this);
                connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
                m_timer->start(1000);
                m_bBlink = false;
            }
            Protocol *protocol = m_client->protocol();
            text = I18N_NOOP("Connecting");
            unsigned status;
            if (m_bBlink){
                icon = "online";
                status = m_client->getManualStatus();
            }else{
                icon = "offline";
                status = STATUS_OFFLINE;
            }
            if (protocol){
                for (const CommandDef *cmd = protocol->statusList(); cmd->text; cmd++){
                    if (cmd->id == status){
                        icon = cmd->icon;
                        break;
                    }
                }
            }
        }else{
            if (m_timer){
                delete m_timer;
                m_timer = NULL;
            }

            Protocol *protocol = m_client->protocol();
            const CommandDef *cmd = protocol->description();
            icon = cmd->icon;
            int n = icon.find('_');
            if (n > 0)
                icon = icon.substr(0, n);
            icon += "_inactive";
            text = I18N_NOOP("Inactive");
        }
    }else{
        if (m_timer){
            delete m_timer;
            m_timer = NULL;
        }
        if (m_client->getState() == Client::Error){
            icon = "error";
            text = I18N_NOOP("Error");
        }else{
            Protocol *protocol = m_client->protocol();
            const CommandDef *cmd = protocol->description();
            icon = cmd->icon;
            text = cmd->text;
            for (cmd = protocol->statusList(); cmd->text; cmd++){
                if (cmd->id == m_client->getStatus()){
                    icon = cmd->icon;
                    text = cmd->text;
                    break;
                }
            }
        }
    }
    QPixmap pict = Pict(icon.c_str());
    QString tip = CorePlugin::m_plugin->clientName(m_client);
    tip += "\n";
    tip += i18n(text);
    setPixmap(pict);
    QToolTip::add(this, tip);
    resize(pict.width(), pict.height());
    setFixedSize(pict.width(), pict.height());
};