23 #include <tqstringlist.h>
27 #include <dcopclient.h>
30 #include <tdeprocess.h>
44 m_dcopTransport = dcopTransport;
45 m_bHaveDCOPCookies =
false;
46 m_bHaveICECookies =
false;
52 QCStringList KCookie::split(
const TQCString &line,
char ch)
57 while ((pos = line.find(ch, i)) != -1)
59 result += line.mid(i, pos-i);
62 if (i < (
int) line.length())
63 result += line.mid(i);
67 void KCookie::blockSigChild()
71 sigaddset(&sset, SIGCHLD);
72 sigprocmask(SIG_BLOCK, &sset, 0L);
75 void KCookie::unblockSigChild()
79 sigaddset(&sset, SIGCHLD);
80 sigprocmask(SIG_UNBLOCK, &sset, 0L);
83 void KCookie::getXCookie()
89 m_Display = getenv(
"DISPLAY");
91 m_Display = getenv(
"QWS_DISPLAY");
93 if (m_Display.isEmpty())
95 kdError(900) << k_lineinfo <<
"$DISPLAY is not set.\n";
99 TQCString disp = m_Display;
100 if (!memcmp(disp.data(),
"localhost:", 10))
103 TQString cmd =
"xauth list "+TDEProcess::quote(disp);
105 if (!(f = popen(TQFile::encodeName(cmd),
"r")))
107 kdError(900) << k_lineinfo <<
"popen(): " << perror <<
"\n";
111 TQCString output = fgets(buf, 1024, f);
114 kdError(900) << k_lineinfo <<
"Could not run xauth.\n";
119 output = output.simplifyWhiteSpace();
120 if (output.isEmpty())
122 kdWarning(900) <<
"No X authentication info set for display " <<
123 m_Display << endl;
return;
125 QCStringList lst = split(output,
' ');
126 if (lst.count() != 3)
128 kdError(900) << k_lineinfo <<
"parse error.\n";
131 m_DisplayAuth = (lst[1] +
' ' + lst[2]);
135 void KCookie::getICECookie()
140 TQCString dcopsrv = getenv(
"DCOPSERVER");
141 if (dcopsrv.isEmpty())
143 TQCString dcopFile = DCOPClient::dcopServerFile();
144 if (!(f = fopen(dcopFile,
"r")))
146 kdWarning(900) << k_lineinfo <<
"Cannot open " << dcopFile <<
".\n";
149 dcopsrv = fgets(buf, 1024, f);
150 dcopsrv = dcopsrv.stripWhiteSpace();
153 QCStringList dcopServerList = split(dcopsrv,
',');
154 if (dcopServerList.isEmpty())
156 kdError(900) << k_lineinfo <<
"No DCOP servers found.\n";
160 QCStringList::Iterator it;
161 for (it=dcopServerList.begin(); it != dcopServerList.end(); ++it)
163 if (strncmp((*it).data(), m_dcopTransport.data(), m_dcopTransport.length()) != 0)
166 TQCString cmd = DCOPClient::iceauthPath()+
" list netid="+TQFile::encodeName(TDEProcess::quote(m_DCOPSrv));
168 if (!(f = popen(cmd,
"r")))
170 kdError(900) << k_lineinfo <<
"popen(): " << perror <<
"\n";
175 while (fgets(buf, 1024, f))
179 kdError(900) << k_lineinfo <<
"Could not run iceauth.\n";
184 QCStringList::Iterator it2;
185 for (it2=output.begin(); it2!=output.end(); ++it2)
187 QCStringList lst = split((*it2).simplifyWhiteSpace(),
' ');
188 if (lst.count() != 5)
190 kdError(900) <<
"parse error.\n";
193 if (lst[0] ==
"DCOP")
194 m_DCOPAuth = (lst[3] +
' ' + lst[4]);
195 else if (lst[0] ==
"ICE")
196 m_ICEAuth = (lst[3] +
' ' + lst[4]);
198 kdError(900) << k_lineinfo <<
"unknown protocol: " << lst[0] <<
"\n";
202 m_bHaveDCOPCookies =
true;
203 m_bHaveICECookies =
true;
208 if (!m_bHaveDCOPCookies)
215 if (!m_bHaveDCOPCookies)
222 if (!m_bHaveICECookies)
TQCString dcopServer()
Returns the netid where the dcopserver is running.
TQCString iceAuth()
Returns a list of magic cookies for the ICE protocol.
TQCString dcopAuth()
Returns a list of magic cookies for DCOP protocol authentication.
void setDcopTransport(const TQCString &dcopTransport)
Select the DCOP transport to look for.