blob: f51aa301cf00e4a098fb6232200261e48bc06399 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
smpppdready.cpp
Copyright (c) 2006 by Heiko Schaefer <[email protected]>
Kopete (c) 2002-2006 by the Kopete developers <[email protected]>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; version 2 of the License. *
* *
*************************************************************************
*/
#include <tqregexp.h>
#include <kdebug.h>
#include <kstreamsocket.h>
#include "smpppdunsettled.h"
#include "smpppdclient.h"
#include "smpppdready.h"
using namespace SMPPPD;
Ready * Ready::m_instance = NULL;
Ready::Ready() {}
Ready::~Ready() {}
Ready * Ready::instance() {
if(!m_instance) {
m_instance = new Ready;
}
return m_instance;
}
void Ready::disconnect(Client * client) {
kdDebug(14312) << k_funcinfo << endl;
if(socket(client)) {
socket(client)->flush();
socket(client)->close();
delete socket(client);
setSocket(client, NULL);
setServerID(client, TQString::null);
setServerVersion(client, TQString::null);
}
changeState(client, Unsettled::instance());
}
TQStringList Ready::getInterfaceConfigurations(Client * client) {
TQStringList ifcfgs;
// we want all ifcfgs
kdDebug(14312) << k_funcinfo << "smpppd req: list-ifcfgs" << endl;
write(client, "list-ifcfgs");
TQStringList stream = read(client);
kdDebug(14312) << k_funcinfo << "smpppd ack: " << stream[0] << endl;
if(stream[0].startsWith("ok")) {
// we have now a TQStringList with all ifcfgs
// we extract them and put them in the global ifcfgs-list
// stream[1] tells us how many ifcfgs are coming next
TQRegExp numIfcfgsRex("^BEGIN IFCFGS ([0-9]+).*");
if(numIfcfgsRex.exactMatch(stream[1])) {
int count_ifcfgs = numIfcfgsRex.cap(1).toInt();
kdDebug(14312) << k_funcinfo << "ifcfgs: " << count_ifcfgs << endl;
for(int i = 0; i < count_ifcfgs; i++) {
TQRegExp ifcfgRex("^i \"(ifcfg-[a-zA-Z]+[0-9]+)\".*");
if(ifcfgRex.exactMatch(stream[i+2])) {
ifcfgs.push_back(ifcfgRex.cap(1));
}
}
}
}
return ifcfgs;
}
bool Ready::statusInterface(Client * client, const TQString& ifcfg) {
TQString cmd = "list-status " + ifcfg;
write(client, cmd.latin1());
socket(client)->waitForMore(0);
TQStringList stream = read(client);
if(stream[0].startsWith("ok")) {
if(stream[2].startsWith("status connected")) {
return true;
}
}
return false;
}
|