Changeset 292:2f743d4eb625

Show
Ignore:
Timestamp:
07/07/2008 07:18:24 PM (4 years ago)
Author:
Dmitry Nezhevenko <dion@…>
Branch:
default
Message:

Update webstatus implementation

Files:
5 modified

Legend:

Unmodified
Added
Removed
  • misc/webstatus.c

    r95 r292  
    6464                res=read(fd,buf+bsize,sizeof(buf)-bsize-1); 
    6565                if (res<=0) 
    66                         reportForbidden("Failed to read from gluxi socket"); 
    67                 for (i=bsize; i<bsize+res; i++) 
     66                { 
     67                        responseFinished=1; 
     68                        break; 
     69                } 
     70                /*for (i=bsize; i<bsize+res; i++) 
    6871                        if (buf[i]==13 || buf[i]==10) 
    6972                        { 
     
    7275                                break; 
    7376                        } 
     77                */ 
     78                buf[bsize+res]=0; 
    7479                bsize+=res; 
    7580                if (responseFinished) 
     
    8085        if (!responseFinished) 
    8186                reportForbidden("Failed to read response from gluxi socket"); 
    82         if (strlen(buf)==0) 
     87        if (strlen(buf)<3) 
    8388                reportForbidden("Unable to find URL"); 
    8489 
    85         printf("Content-type: text/html\r\n"); 
    86         printf("Location: %s\r\n",buf); 
    87         printf("\r\n"); 
     90        char* bufReal=buf+2; 
     91        buf[1]=0; 
     92 
     93        if (buf[0]=='1') 
     94        { 
     95                printf("Content-type: text/html; charset=utf-8\r\n"); 
     96                printf("Location: %s\r\n",bufReal); 
     97                printf("\r\n"); 
     98        } 
     99        else if (buf[0]=='0') 
     100        { 
     101                printf("%s",bufReal); 
     102        } 
    88103} 
    89  
  • sql/mysql.sql

    r285 r292  
    110110  `hash` varchar(50) collate utf8_unicode_ci NOT NULL, 
    111111  `status` varchar(15) collate utf8_unicode_ci default NULL, 
     112  `display` varchar(300) collate utf8_unicode_ci default NULL, 
    112113  `available` varchar(100) collate utf8_unicode_ci default NULL, 
    113114  `away` varchar(100) collate utf8_unicode_ci default NULL, 
  • sql/pgsql.sql

    r285 r292  
    6363  hash varchar(50) NOT NULL, 
    6464  status varchar(15) default NULL, 
     65  display varchar(300) default NULL, 
    6566  available varchar(100) default NULL, 
    6667  away varchar(100) default NULL, 
  • src/plugins/webstatus/webstatusplugin.cpp

    r145 r292  
    1616                : BasePlugin(parent) 
    1717{ 
    18         commands << "INVITE" << "INFO" << "AVAILABLE" << "AWAY"  
     18        commands << "INVITE" << "INFO" << "AVAILABLE" << "AWAY" 
    1919                << "CHAT" << "DND" << "UNAVAILABLE" << "XA"; 
    2020 
     
    3030        thread->stop(); 
    3131        thread->terminate(); 
    32         thread->wait(1); 
     32        thread->wait(10000); 
    3333        delete thread; 
    3434        thread=0; 
     
    4545                if (!isFromBotOwner(s,true)) 
    4646                        return true; 
    47                          
     47 
    4848                if (arg.isEmpty()) 
    4949                { 
     
    6161                } 
    6262                gloox::Stanza* st; 
    63                 st=gloox::Stanza::createSubscriptionStanza(arg.toStdString(),  
     63                st=gloox::Stanza::createSubscriptionStanza(arg.toStdString(), 
    6464                        "GluxiBot WebStatus service", gloox::StanzaS10nSubscribe); 
    6565                bot()->client()->send(st); 
     
    147147        qDebug() << "Got presence from " << from; 
    148148        QString status=getPresence(s->presence()); 
     149        QString display; 
     150        gloox::Tag* showTag=s->findChild("status"); 
     151        if (showTag) 
     152                display=QString::fromStdString(showTag->cdata()); 
     153 
    149154        if (status.isEmpty()) 
    150155                return; 
    151         query.prepare("UPDATE webstatus SET status=? WHERE jid=?"); 
     156        display.replace ("\n"," "); 
     157        query.prepare("UPDATE webstatus SET status=?, display=? WHERE jid=?"); 
    152158        query.addBindValue(status); 
     159        query.addBindValue(display); 
    153160        query.addBindValue(from); 
    154161        query.exec(); 
  • src/plugins/webstatus/webstatusthread.cpp

    r131 r292  
    1919{ 
    2020        socketName=DataStorage::instance()->getString("webstatus/socket"); 
     21        if (socketName.isEmpty()) 
     22                return; 
    2123        shouldWork=1; 
    2224        db=QSqlDatabase::cloneDatabase(QSqlDatabase::database(),"webStatus"); 
     
    6365                int fd_client=accept(fd_srv, NULL, 0); 
    6466                if (fd_client<0) continue; 
    65                  
     67 
    6668                bsize=0; 
    6769 
     
    102104                buf[bsize]=0; 
    103105                QString request(buf); 
    104                  
     106 
    105107                QString answer; 
    106108 
    107                 if (request.indexOf('\"')<0 && request.indexOf('\'')<0  
     109                if (request.indexOf('\"')<0 && request.indexOf('\'')<0 
    108110                        && request.startsWith("id=") && request.indexOf('&')<0) 
    109111                { 
    110112                        request.remove(0,3); // Delete id= 
    111                         qDebug() << request; 
     113                        int ps=request.indexOf('_'); 
     114                        QString requestType; 
     115                        if (ps>0) 
     116                        { 
     117                                requestType=request.section('_', -1, -1); 
     118                                request=request.section('_', 0, -2); 
     119                        } 
     120                        qDebug() << "request: " << request << " type: " << requestType; 
     121 
    112122                        QSqlQuery query(db); 
    113123                        query.prepare("SELECT LOWER(status) FROM webstatus WHERE hash=?"); 
     
    117127                                QString status=query.value(0).toString(); 
    118128                                qDebug() << "st=" << status; 
    119                                 query.prepare(QString("SELECT %1 FROM webstatus WHERE hash=?").arg(status)); 
     129                                query.prepare(QString("SELECT %1, status, display FROM webstatus WHERE hash=?").arg(status)); 
    120130                                query.addBindValue(request); 
    121131                                if (query.exec() && query.next()) 
    122                                         answer=query.value(0).toString(); 
     132                                { 
     133                                        QString url=query.value(0).toString(); 
     134                                        QString status=query.value(1).toString(); 
     135                                        QString display=query.value(2).toString(); 
     136                                        if (requestType=="all") 
     137                                        { 
     138                                                answer=QString("0:")+url+"\n"+status+"\n"+display; 
     139                                        } 
     140                                        else if (requestType=="text") 
     141                                        { 
     142                                                answer=QString("0:")+status; 
     143                                                if (!display.isEmpty()) 
     144                                                        answer+=QString(" (%1)").arg(display); 
     145                                        } 
     146                                        else 
     147                                        { 
     148                                                answer="1:"+url; 
     149                                        } 
     150 
     151                                } 
    123152                        } 
    124153                        else 
     
    126155                } 
    127156                answer+='\n'; 
    128                 qDebug() << answer; 
     157                qDebug() << "Response: "+answer; 
    129158                write(fd_client,answer.toLocal8Bit().data(), answer.toLocal8Bit().size()); 
    130159                close(fd_client);