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
|
$NetBSD: patch-ac,v 1.1 2005/02/20 11:31:11 markd Exp $
--- kstars/kstars/devicemanager.cpp.orig 2004-07-18 05:52:56.000000000 +1200
+++ kstars/kstars/devicemanager.cpp
@@ -17,6 +17,7 @@
#include "indiproperty.h"
#include "indigroup.h"
#include "indidevice.h"
+#include "indi/indicom.h"
#include "kstars.h"
#include "kstarsdatetime.h"
@@ -136,50 +137,51 @@ bool DeviceManager::indiConnect(QString
void DeviceManager::dataReceived()
{
char ibuf[32]; /* not so much user input lags */
- char msg[1024];
+ char errmsg[ERRMSG_SIZE];
int i, nr;
/* read INDI command */
- nr = read (serverFD, ibuf, sizeof(ibuf));
+ nr = read (serverFD, ibuf, sizeof(ibuf)-1);
if (nr <= 0)
{
if (nr < 0)
- sprintf (msg, "INDI: input error.");
+ strcpy (errmsg, "INDI: input error.");
else
- sprintf (msg, "INDI: agent closed connection.");
+ strcpy (errmsg, "INDI: agent closed connection.");
tcflush(serverFD, TCIFLUSH);
sNotifier->disconnect();
close(serverFD);
parent->removeDeviceMgr(mgrID);
- KMessageBox::error(0, QString(msg));
+ KMessageBox::error(0, QString::fromLatin1(errmsg));
return;
}
+ ibuf[ sizeof( ibuf )-1 ] = '\0';
+
/* process each char */
for (i = 0; i < nr; i++)
{
if (!XMLParser)
return;
- XMLEle *root = readXMLEle (XMLParser, (int)ibuf[i], msg);
+ XMLEle *root = readXMLEle (XMLParser, (int)ibuf[i], errmsg);
if (root)
{
//prXMLEle (stdout, root, 0);
- if (dispatchCommand(root, msg) < 0)
+ if (dispatchCommand(root, errmsg) < 0)
{
- //kdDebug() << msg << endl;
- fprintf(stderr, msg);
+ fprintf(stderr, "%s", errmsg);
prXMLEle (stdout, root, 0);
}
delXMLEle (root);
}
- else if (msg[0])
+ else if (*errmsg)
{
- kdDebug() << msg << endl;
+ kdDebug() << errmsg << endl;
}
}
}
@@ -271,7 +273,7 @@ int DeviceManager::removeDevice(QString
}
}
- sprintf(errmsg, "Device %s not found" , devName.ascii());
+ snprintf(errmsg, ERRMSG_SIZE, "Device %.32s not found" , devName.ascii());
return -1;
}
@@ -284,7 +286,7 @@ INDI_D * DeviceManager::findDev (QString
return (indi_dev.at(i));
}
- sprintf (errmsg, "INDI: no such device %s", devName.ascii());
+ snprintf (errmsg, ERRMSG_SIZE, "INDI: no such device %.32s", devName.ascii());
kdDebug() << errmsg;
return NULL;
@@ -342,7 +344,7 @@ INDI_D * DeviceManager::findDev (XMLEle
return (addDevice (root, errmsg));
- sprintf (errmsg, "INDI: <%s> no such device %s", tagXMLEle(root), dn);
+ snprintf (errmsg, ERRMSG_SIZE, "INDI: <%.32s> no such device %.32s", tagXMLEle(root), dn);
return NULL;
}
|