summaryrefslogtreecommitdiff
path: root/library/qcopenvelope_qws.cpp
Unidiff
Diffstat (limited to 'library/qcopenvelope_qws.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--library/qcopenvelope_qws.cpp66
1 files changed, 20 insertions, 46 deletions
diff --git a/library/qcopenvelope_qws.cpp b/library/qcopenvelope_qws.cpp
index 81bb0f5..0aac32b 100644
--- a/library/qcopenvelope_qws.cpp
+++ b/library/qcopenvelope_qws.cpp
@@ -93,81 +93,55 @@ QCopEnvelope::QCopEnvelope( const QCString& channel, const QCString& message ) :
93 Writes the message and then destroys the QCopEnvelope. 93 Writes the message and then destroys the QCopEnvelope.
94*/ 94*/
95QCopEnvelope::~QCopEnvelope() 95QCopEnvelope::~QCopEnvelope()
96{ 96{
97 QByteArray data = ((QBuffer*)device())->buffer(); 97 QByteArray data = ((QBuffer*)device())->buffer();
98 const int pref=16; 98 const int pref=16;
99 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) { 99 if ( qstrncmp(ch.data(),"QPE/Application/",pref)==0 ) {
100 QString qcopfn("/tmp/qcop-msg-"); 100 QString qcopfn("/tmp/qcop-msg-");
101 qcopfn += ch.mid(pref); 101 qcopfn += ch.mid(pref);
102 QFile qcopfile(qcopfn); 102 QFile qcopfile(qcopfn);
103 103
104 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) { 104 if ( qcopfile.open(IO_WriteOnly | IO_Append) ) {
105#ifndef Q_OS_WIN32
105 if(flock(qcopfile.handle(), LOCK_EX)) { 106 if(flock(qcopfile.handle(), LOCK_EX)) {
106 /* some error occured */ 107 /* some error occurred */
107 qWarning(QString("Failed to obtain file lock on %1 (%2)") 108 qWarning(QString("Failed to obtain file lock on %1 (%2)")
108 .arg(qcopfn).arg( errno )); 109 .arg(qcopfn).arg( errno ));
109 } 110 }
110 /* file locked, but might be stale (e.g. program for whatever 111#endif
111 reason did not start). I modified more than 1 minute ago, 112 {
112 truncate the file */ 113 QDataStream ds(&qcopfile);
113 struct stat buf; 114 ds << ch << msg << data;
114 time_t t; 115 qcopfile.flush();
115 if (!fstat(qcopfile.handle(), &buf) && (time(&t) != (time_t)-1) ) { 116#ifndef Q_OS_WIN32
116 // success on fstat, lets compare times 117 flock(qcopfile.handle(), LOCK_UN);
117 if (buf.st_ctime + 60 < t) { 118#endif
118 qWarning("stale file " + qcopfn + " found. Truncating"); 119 qcopfile.close();
119 ftruncate(qcopfile.handle(), 0);
120 qcopfile.reset();
121 }
122 } 120 }
123 121
124 if ( !QCopChannel::isRegistered(ch) ) { 122 QByteArray b;
125 int fsize = qcopfile.size(); 123 QDataStream stream(b, IO_WriteOnly);
126 { 124 stream << QString(ch.mid(pref));
127 QDataStream ds(&qcopfile); 125 QCopChannel::send("QPE/Server", "processQCop(QString)", b);
128 ds << ch << msg << data; 126 delete device();
129 flock(qcopfile.handle(), LOCK_UN); 127 return;
130 qcopfile.close();
131 }
132
133 if (fsize == 0) {
134 QString cmd = ch.mid(pref);
135 Global::execute(cmd);
136 }
137
138 char c;
139 for (int i=0; (c=msg[i]); i++) {
140 if ( c == ' ' ) {
141 // Return-value required
142 // ###### wait for it
143 break;
144 } else if ( c == '(' ) {
145 // No return value
146 break;
147 }
148 }
149 goto end;
150 } // endif isRegisterd
151 flock(qcopfile.handle(), LOCK_UN);
152 qcopfile.close();
153 qcopfile.remove();
154 } else { 128 } else {
155 qWarning(QString("Failed to obtain file lock on %1") 129 qWarning(QString("Failed to open file %1")
156 .arg(qcopfn)); 130 .arg(qcopfn));
157 } // endif open 131 } // endif open
158 } 132 }
159 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) { 133 else if (qstrncmp(ch.data(), "QPE/SOAP/", 9) == 0) {
160 // If this is a message that should go along the SOAP channel, we move the 134 // If this is a message that should go along the SOAP channel, we move the
161 // endpoint URL to the data section. 135 // endpoint URL to the data section.
162 QString endpoint = ch.mid(9); 136 QString endpoint = ch.mid(9);
163 137
164 ch = "QPE/SOAP"; 138 ch = "QPE/SOAP";
165 // Since byte arrays are explicitly shared, this is appended to the data variable.. 139 // Since byte arrays are explicitly shared, this is appended to the data variable..
166 *this << endpoint; 140 *this << endpoint;
167 } 141 }
142
168 QCopChannel::send(ch,msg,data); 143 QCopChannel::send(ch,msg,data);
169end:
170 delete device(); 144 delete device();
171} 145}
172 146
173#endif 147#endif