summaryrefslogtreecommitdiff
authormjm <mjm>2003-02-26 22:28:06 (UTC)
committer mjm <mjm>2003-02-26 22:28:06 (UTC)
commit7659b28b02edb05de0d4c7cf2a3021c005fb63fe (patch) (side-by-side diff)
tree1c0c5d047452dfc82bad01a7ce763490d18a7bc2
parented168abe1c9c1384b0151ea9b49a7e364f9b67be (diff)
downloadopie-7659b28b02edb05de0d4c7cf2a3021c005fb63fe.zip
opie-7659b28b02edb05de0d4c7cf2a3021c005fb63fe.tar.gz
opie-7659b28b02edb05de0d4c7cf2a3021c005fb63fe.tar.bz2
added send_fail/send_ok/get_fail/get_ok.
fixed some bufferproblems
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc103
-rw-r--r--noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh14
2 files changed, 107 insertions, 10 deletions
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
index 0d0f075..dcdc16b 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.cc
@@ -12,3 +12,3 @@
/* Adds a field to the buffer */
-int add_field(char *buffer, const char *string, int len)
+unsigned int add_field(char *buffer, const char *string, int len)
{
@@ -28,3 +28,3 @@ int add_field(char *buffer, const char *string, int len)
-int get_field(const char *buffer, char *out, int maxlen)
+unsigned int get_field(const char *buffer, char *out, int maxlen)
{
@@ -47,2 +47,93 @@ int get_field(const char *buffer, char *out, int maxlen)
+/* Send ok message */
+int send_ok(const char *guihost, int guiport, int code)
+{
+ unsigned int len = 0;
+ char buffer[128], temp[5];
+
+ memset(buffer, 0, sizeof(buffer));
+
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_OK);
+ memcpy(buffer, temp, 2);
+ len += 2;
+
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp) - 1, "%.2d", code);
+ len += add_field(buffer + len, temp, 2);
+
+ /* Send prepared buffer to UI */
+#ifdef DEBUG
+ wl_loginfo("Sent ok to UI: '%s'", buffer);
+#endif
+
+ return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1);
+}
+
+/* Send fail message */
+int send_fail(const char *guihost, int guiport,
+ int code, const char *errstr)
+{
+ unsigned int len = 0;
+ char buffer[128], temp[5];
+
+ memset(buffer, 0, sizeof(buffer));
+
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp) - 1, "%.2d", CMD_FAIL);
+ memcpy(buffer, temp, 2);
+ len += 2;
+
+ memset(temp, 0, sizeof(temp));
+ snprintf(temp, sizeof(temp) - 1, "%.2d", code);
+ len += add_field(buffer + len, temp, 2);
+
+ len += add_field(buffer + len, errstr, strlen(errstr));
+
+ /* Send prepared buffer to UI */
+#ifdef DEBUG
+ wl_loginfo("Send CMD_FAIL to UI: '%s'", buffer);
+#endif
+
+ return ((!wl_send(guihost, guiport, buffer)) ? 0 : 1);
+}
+
+int get_ok(const char *buffer)
+{
+ char temp[5];
+ unsigned int len = 0;
+
+ /* packet type already determined, skip check */
+ len += 2;
+
+ /* what is ok for? */
+ memset(temp, 0, sizeof(temp));
+ len += get_field(buffer + len, temp, sizeof(temp));
+
+ return atoi(temp);
+}
+
+/* put failmessage into buffer */
+int get_fail(char *out, const char *buffer, size_t len)
+{
+ char temp[5];
+ int error=0;
+ unsigned int len = 0;
+
+ /* packet type already determined, skip check */
+ len += 2;
+
+ /* what is fail for? */
+ memset(temp, 0, sizeof(temp));
+ len += get_field(buffer + len, temp, sizeof(temp));
+ error=atoi(temp);
+
+ /* get errorstring and fill into buffer */
+ memset(out, 0, len);
+ len += get_field(buffer + len, out, len - 1);
+
+ return error;
+}
+
+
/* Send found network to UI */
@@ -59,3 +150,3 @@ int send_network_found (const char *guihost, int guiport, void *structure)
memset(temp, 0, sizeof(temp));
- snprintf(temp, sizeof(temp), "%.2d", WL_NETFOUND);
+ snprintf(temp, sizeof(temp) - 1, "%.2d", WL_NETFOUND);
memcpy(buffer, temp, 2);
@@ -65,3 +156,3 @@ int send_network_found (const char *guihost, int guiport, void *structure)
memset(temp, 0, sizeof(temp));
- snprintf(temp, sizeof(temp), "%d", ptr->net_type);
+ snprintf(temp, sizeof(temp) - 1, "%d", ptr->net_type);
len += add_field(buffer + len, temp, 1);
@@ -70,3 +161,3 @@ int send_network_found (const char *guihost, int guiport, void *structure)
memset(temp, 0, sizeof(temp));
- snprintf(temp, sizeof(temp), "%.2d", ptr->channel);
+ snprintf(temp, sizeof(temp) - 1, "%.2d", ptr->channel);
len += add_field(buffer + len, temp, 2);
@@ -75,3 +166,3 @@ int send_network_found (const char *guihost, int guiport, void *structure)
memset(temp, 0, sizeof(temp));
- snprintf(temp, sizeof(temp), "%d", ptr->wep);
+ snprintf(temp, sizeof(temp) - 1, "%d", ptr->wep);
len += add_field(buffer + len, temp, 1);
diff --git a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
index 46ef8e5..63ac53b 100644
--- a/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
+++ b/noncore/net/wellenreiter/libwellenreiter/source/wl_proto.hh
@@ -10,4 +10,6 @@
/* Type definitions, to be continued */
-#define NETFOUND 01
-#define NETLOST 02
+#define NETFOUND 01
+#define NETLOST 02
+#define CMD_FAIL 50
+#define CMD_OK 51
#define STARTSNIFF 98
@@ -15,4 +17,8 @@
-int add_field(char *, const char *, int);
-int get_field(const char *, char *, int);
+unsigned int add_field(char *, const char *, int);
+unsigned int get_field(const char *, char *, int);
+int send_ok(const char *, int, int);
+int get_ok(const char *);
+int send_fail(const char *, int, int, const char *);
+int get_fail(char *, const char *, size_t);
int send_network_found (const char *, int, void *);