blob: 5ff1654b5930f91280cb9e2ace8bca5a7135a8d8 (
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
|
/*
smpppdclient.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 <kstreamsocket.h>
#include "smpppdunsettled.h"
#include "smpppdclient.h"
using namespace SMPPPD;
Client::Client()
: m_state(NULL), m_sock(NULL), m_serverID(TQString::null), m_serverVer(TQString::null), m_password(TQString::null) {
changeState(Unsettled::instance());
}
Client::~Client() {
disconnect();
}
bool Client::connect(const TQString& server, uint port) {
return m_state->connect(this, server, port);
}
void Client::disconnect() {
m_state->disconnect(this);
}
TQStringList Client::getInterfaceConfigurations() {
return m_state->getInterfaceConfigurations(this);
}
bool Client::statusInterface(const TQString& ifcfg) {
return m_state->statusInterface(this, ifcfg);
}
TQString Client::serverID() const {
return m_serverID;
}
TQString Client::serverVersion() const {
return m_serverVer;
}
TQStringList Client::read() const {
TQStringList qsl;
if(isReady()) {
TQDataStream stream(m_sock);
char s[1024];
stream.readRawBytes(s, 1023);
char *sp = s;
for(int i = 0; i < 1024; i++) {
if(s[i] == '\n') {
s[i] = 0;
qsl.push_back(sp);
sp = &(s[i+1]);
}
}
}
return qsl;
}
void Client::write(const char * cmd) {
if(isReady()) {
TQDataStream stream(m_sock);
stream.writeRawBytes(cmd, strlen(cmd));
stream.writeRawBytes("\n", strlen("\n"));
m_sock->flush();
}
}
bool Client::isReady() const {
return m_sock && m_sock->state() == KNetwork::KStreamSocket::Connected;
}
bool Client::isOnline() {
if(isReady()) {
TQStringList ifcfgs = getInterfaceConfigurations();
for(uint i = 0; i < ifcfgs.count(); i++) {
if(statusInterface(ifcfgs[i])) {
return true;
}
}
}
return false;
}
|