Changeset 292:2f743d4eb625
- Timestamp:
- 07/07/2008 07:18:24 PM (4 years ago)
- Author:
- Dmitry Nezhevenko <dion@…>
- Branch:
- default
- Message:
-
Update webstatus implementation
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r95
|
r292
|
|
| 64 | 64 | res=read(fd,buf+bsize,sizeof(buf)-bsize-1); |
| 65 | 65 | 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++) |
| 68 | 71 | if (buf[i]==13 || buf[i]==10) |
| 69 | 72 | { |
| … |
… |
|
| 72 | 75 | break; |
| 73 | 76 | } |
| | 77 | */ |
| | 78 | buf[bsize+res]=0; |
| 74 | 79 | bsize+=res; |
| 75 | 80 | if (responseFinished) |
| … |
… |
|
| 80 | 85 | if (!responseFinished) |
| 81 | 86 | reportForbidden("Failed to read response from gluxi socket"); |
| 82 | | if (strlen(buf)==0) |
| | 87 | if (strlen(buf)<3) |
| 83 | 88 | reportForbidden("Unable to find URL"); |
| 84 | 89 | |
| 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 | } |
| 88 | 103 | } |
| 89 | | |
-
|
r285
|
r292
|
|
| 110 | 110 | `hash` varchar(50) collate utf8_unicode_ci NOT NULL, |
| 111 | 111 | `status` varchar(15) collate utf8_unicode_ci default NULL, |
| | 112 | `display` varchar(300) collate utf8_unicode_ci default NULL, |
| 112 | 113 | `available` varchar(100) collate utf8_unicode_ci default NULL, |
| 113 | 114 | `away` varchar(100) collate utf8_unicode_ci default NULL, |
-
|
r285
|
r292
|
|
| 63 | 63 | hash varchar(50) NOT NULL, |
| 64 | 64 | status varchar(15) default NULL, |
| | 65 | display varchar(300) default NULL, |
| 65 | 66 | available varchar(100) default NULL, |
| 66 | 67 | away varchar(100) default NULL, |
-
|
r145
|
r292
|
|
| 16 | 16 | : BasePlugin(parent) |
| 17 | 17 | { |
| 18 | | commands << "INVITE" << "INFO" << "AVAILABLE" << "AWAY" |
| | 18 | commands << "INVITE" << "INFO" << "AVAILABLE" << "AWAY" |
| 19 | 19 | << "CHAT" << "DND" << "UNAVAILABLE" << "XA"; |
| 20 | 20 | |
| … |
… |
|
| 30 | 30 | thread->stop(); |
| 31 | 31 | thread->terminate(); |
| 32 | | thread->wait(1); |
| | 32 | thread->wait(10000); |
| 33 | 33 | delete thread; |
| 34 | 34 | thread=0; |
| … |
… |
|
| 45 | 45 | if (!isFromBotOwner(s,true)) |
| 46 | 46 | return true; |
| 47 | | |
| | 47 | |
| 48 | 48 | if (arg.isEmpty()) |
| 49 | 49 | { |
| … |
… |
|
| 61 | 61 | } |
| 62 | 62 | gloox::Stanza* st; |
| 63 | | st=gloox::Stanza::createSubscriptionStanza(arg.toStdString(), |
| | 63 | st=gloox::Stanza::createSubscriptionStanza(arg.toStdString(), |
| 64 | 64 | "GluxiBot WebStatus service", gloox::StanzaS10nSubscribe); |
| 65 | 65 | bot()->client()->send(st); |
| … |
… |
|
| 147 | 147 | qDebug() << "Got presence from " << from; |
| 148 | 148 | 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 | |
| 149 | 154 | if (status.isEmpty()) |
| 150 | 155 | return; |
| 151 | | query.prepare("UPDATE webstatus SET status=? WHERE jid=?"); |
| | 156 | display.replace ("\n"," "); |
| | 157 | query.prepare("UPDATE webstatus SET status=?, display=? WHERE jid=?"); |
| 152 | 158 | query.addBindValue(status); |
| | 159 | query.addBindValue(display); |
| 153 | 160 | query.addBindValue(from); |
| 154 | 161 | query.exec(); |
-
|
r131
|
r292
|
|
| 19 | 19 | { |
| 20 | 20 | socketName=DataStorage::instance()->getString("webstatus/socket"); |
| | 21 | if (socketName.isEmpty()) |
| | 22 | return; |
| 21 | 23 | shouldWork=1; |
| 22 | 24 | db=QSqlDatabase::cloneDatabase(QSqlDatabase::database(),"webStatus"); |
| … |
… |
|
| 63 | 65 | int fd_client=accept(fd_srv, NULL, 0); |
| 64 | 66 | if (fd_client<0) continue; |
| 65 | | |
| | 67 | |
| 66 | 68 | bsize=0; |
| 67 | 69 | |
| … |
… |
|
| 102 | 104 | buf[bsize]=0; |
| 103 | 105 | QString request(buf); |
| 104 | | |
| | 106 | |
| 105 | 107 | QString answer; |
| 106 | 108 | |
| 107 | | if (request.indexOf('\"')<0 && request.indexOf('\'')<0 |
| | 109 | if (request.indexOf('\"')<0 && request.indexOf('\'')<0 |
| 108 | 110 | && request.startsWith("id=") && request.indexOf('&')<0) |
| 109 | 111 | { |
| 110 | 112 | 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 | |
| 112 | 122 | QSqlQuery query(db); |
| 113 | 123 | query.prepare("SELECT LOWER(status) FROM webstatus WHERE hash=?"); |
| … |
… |
|
| 117 | 127 | QString status=query.value(0).toString(); |
| 118 | 128 | 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)); |
| 120 | 130 | query.addBindValue(request); |
| 121 | 131 | 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 | } |
| 123 | 152 | } |
| 124 | 153 | else |
| … |
… |
|
| 126 | 155 | } |
| 127 | 156 | answer+='\n'; |
| 128 | | qDebug() << answer; |
| | 157 | qDebug() << "Response: "+answer; |
| 129 | 158 | write(fd_client,answer.toLocal8Bit().data(), answer.toLocal8Bit().size()); |
| 130 | 159 | close(fd_client); |