예제 #1
0
    void Client::parseTransmit()
    {
        qDebug() << "parseTransmit():";
        if ( !(this->status_ == ST_ADMIN ||
               this->status_ == ST_CLIENT))
        {
            qDebug() << "cmd not allowed";
            this->disconnectFromHost();
            return;
        }

        if (buf_.size()<9) // TODO: remove magic number
            return;     // not all data avaliable

        qDebug() << "buf size" << buf_.size();
        qDebug() << "packet len" << getPacketLength(buf_);

        if (buf_.size()<getPacketLength(buf_)+9) // TODO: remove magic number
            return; // not all data avaliable

        qint16 clientId=getClientId(buf_);

        QByteArray cmd=getPacketData(buf_);

        QByteArray response;
        response.append(CSPYP1_PROTOCOL_ID);
        response.append(CSPYP1_PROTOCOL_VERSION);
        response.append(CMD1_TRANSMIT);
        response.append(toBytes(getId()));
        response.append(toBytes(cmd.size()));
        response.append(cmd);

        auto destClient = getServer()->searchClient(clientId);
        qDebug() << "Client to ID:" << clientId;

        if (destClient != getServer()->clientEnd())
        {
            qDebug() << "transmiting data..";
            destClient.value()->send(response);
        }

        buf_=buf_.right(buf_.size() - (getPacketLength(buf_) + 9));

        if (buf_.size() > 0)
            onDataReceived();   // If something in buffer - parse again
    }
int sec_url_filter_slow(struct nf_queue_entry *entry, unsigned int queuenum)
{
    if (entry != NULL)
    {
        if (filterMode)
        {
            struct sk_buff  *skb            = entry->skb;
            char            *request        = NULL;
            tcp_TrackInfo   *gettingNode    = NULL;
            tcp_TrackInfo   *notifyNode     = NULL;
            if (skb != NULL)
            {
                struct iphdr *iph   = (struct iphdr*)ip_hdr(skb);
                if (iph != NULL)
                {
                    if (iph->protocol == 6)
                    {
                        struct tcphdr   *tcph = (struct tcphdr *)skb_transport_header(skb);
                        if (tcph!= NULL)
                        {
                            notifyNode  = find_tcp_TrackInfo(notifying_TrackInfo, skb, 0);
                            if (notifyNode != NULL)     // If this is already notified to user, drop it.
                            {
                                unsigned int verdict    = NF_DROP;
                                nf_reinject(entry, verdict);
                                return 0;
                            }
                            gettingNode	= find_tcp_TrackInfo(getting_TrackInfo, skb, 1);    // Find previous TCP Track Info and remove from list
                            if (gettingNode == NULL)            // No previous Info
                            {
                                gettingNode = isURL(skb);       // If this is URL Request then make TCP Track Info
                            }
                            if (gettingNode != NULL)
                            {
                                request	= getPacketData(skb, gettingNode);  // Get Packet
                                if (request != NULL)                        // If there is packet data
                                {
                                    getURL(request, gettingNode);           // Get URL	and update status
                                    kfree(request);
                                    request	= NULL;
                                    if (gettingNode->status == GOT_FULL_URL)		// If get Full URL, then make notify info
                                    {
                                        makeNotifyInfo(gettingNode);
                                        if ((exceptionURL != NULL) && (gettingNode->url !=NULL))
                                        {
                                            if (strstr(&gettingNode->url[sizeof(URL_Info)], exceptionURL) != NULL)  // This is exception URL
                                            {
                                                free_tcp_TrackInfo(gettingNode);
                                                nf_reinject(entry, NF_ACCEPT);
                                                return 0;
                                            }
                                        }
                                        gettingNode->q_entry = entry;
                                        add_tcp_TrackInfo(notifying_TrackInfo, gettingNode);
                                        wake_up_interruptible(&user_noti_Q);    // Wake Up read function
                                        return 0;
                                    }
                                }
                                add_tcp_TrackInfo_ToHead(getting_TrackInfo, gettingNode);
                            }
                        }
                    }
                }
            }
        }
        nf_reinject(entry, NF_ACCEPT);
    }

    return 0;
}