From 74c6d2ba6172d4601e03c89f1d21cf54c45fa920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Sun, 10 Apr 2005 21:47:14 +0000 Subject: [PATCH] fix proprer read_string() return code error handling git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2003 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- alinco/alinco.c | 17 +++++++++++------ aor/ar3000.c | 12 +++++++++--- aor/ar3030.c | 11 ++++++++--- drake/drake.c | 11 ++++++++--- jrc/jrc.c | 9 +++++++-- kenwood/ic10.c | 11 ++++++++--- lowe/lowe.c | 11 ++++++++--- pcr/pcr.c | 21 ++++++++++++++------- rft/rft.c | 11 ++++++++--- skanti/skanti.c | 19 ++++++++++++------- tentec/tentec.c | 15 ++++++++++----- tentec/tt550.c | 11 +++++++++-- uniden/uniden.c | 13 +++++++++---- 13 files changed, 121 insertions(+), 51 deletions(-) diff --git a/alinco/alinco.c b/alinco/alinco.c index 2af17c0d9..4415d10f1 100644 --- a/alinco/alinco.c +++ b/alinco/alinco.c @@ -2,7 +2,7 @@ * Hamlib Alinco backend - main file * Copyright (c) 2001-2005 by Stephane Fillod * - * $Id: alinco.c,v 1.26 2005-01-25 00:19:38 fillods Exp $ + * $Id: alinco.c,v 1.27 2005-04-10 21:47:12 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -109,28 +109,33 @@ int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int * retval = write_block(&rs->rigport, cmd, cmd_len); if (retval != RIG_OK) - return retval; + return retval; /* * Transceiver sends an echo of cmd followed by a CR/LF * TODO: check whether cmd and echobuf match (optional) */ retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF)); - /* if (retval <= 3) - return retval; */ + if (retval < 0) + return retval; /* no data expected, check for OK returned */ if (!data || !data_len) { retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF)); + if (retval < 0) + return retval; retval -= 2; echobuf[retval] = 0; if (strcmp(echobuf, "OK") == 0) return RIG_OK; else - return RIG_ERJCTED; + return -RIG_ERJCTED; } - *data_len = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF)); + retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF)); + if (retval < 0) + return retval; + *data_len = retval; /* strip CR/LF from string */ diff --git a/aor/ar3000.c b/aor/ar3000.c index 63d82a8c6..34c3f4861 100644 --- a/aor/ar3000.c +++ b/aor/ar3000.c @@ -2,7 +2,7 @@ * Hamlib AOR backend - AR3000 description * Copyright (c) 2000-2005 by Stephane Fillod * - * $Id: ar3000.c,v 1.8 2005-02-26 22:28:19 fillods Exp $ + * $Id: ar3000.c,v 1.9 2005-04-10 21:47:12 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -74,7 +74,7 @@ const struct rig_caps ar3000a_caps = { .rig_model = RIG_MODEL_AR3000A, .model_name = "AR3000A", .mfg_name = "AOR", -.version = "0.3", +.version = "0.4", .copyright = "LGPL", .status = RIG_STATUS_BETA, .rig_type = RIG_TYPE_SCANNER, @@ -205,7 +205,13 @@ static int ar3k_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, if (!data || !data_len) return RIG_OK; - *data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM)); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM)); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + + *data_len = retval; return RIG_OK; } diff --git a/aor/ar3030.c b/aor/ar3030.c index b48c8c81a..788d5876d 100644 --- a/aor/ar3030.c +++ b/aor/ar3030.c @@ -2,7 +2,7 @@ * Hamlib AOR backend - AR3030 description * Copyright (c) 2000-2005 by Stephane Fillod * - * $Id: ar3030.c,v 1.8 2005-04-03 19:40:15 fillods Exp $ + * $Id: ar3030.c,v 1.9 2005-04-10 21:47:12 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -100,7 +100,7 @@ const struct rig_caps ar3030_caps = { .rig_model = RIG_MODEL_AR3030, .model_name = "AR3030", .mfg_name = "AOR", -.version = "0.2", +.version = "0.3", .copyright = "LGPL", .status = RIG_STATUS_UNTESTED, .rig_type = RIG_TYPE_RECEIVER, @@ -230,7 +230,12 @@ static int ar3030_transaction(RIG *rig, const char *cmd, int cmd_len, char *data if (!data || !data_len) return RIG_OK; - *data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM)); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM)); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; } diff --git a/drake/drake.c b/drake/drake.c index cfd527677..d5c00ced7 100644 --- a/drake/drake.c +++ b/drake/drake.c @@ -1,8 +1,8 @@ /* * Hamlib Drake backend - main file - * Copyright (c) 2001-2004 by Stephane Fillod + * Copyright (c) 2001-2005 by Stephane Fillod * - * $Id: drake.c,v 1.16 2004-09-05 19:15:10 fineware Exp $ + * $Id: drake.c,v 1.17 2005-04-10 21:47:12 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -80,7 +80,12 @@ int drake_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *d if (!data || !data_len) return 0; - *data_len = read_string(&rs->rigport, data, BUFSZ, LF, 1); + retval = read_string(&rs->rigport, data, BUFSZ, LF, 1); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; } diff --git a/jrc/jrc.c b/jrc/jrc.c index 32161d0e0..ae1503a43 100644 --- a/jrc/jrc.c +++ b/jrc/jrc.c @@ -2,7 +2,7 @@ * Hamlib JRC backend - main file * Copyright (c) 2001-2005 by Stephane Fillod * - * $Id: jrc.c,v 1.21 2005-01-25 00:19:41 fillods Exp $ + * $Id: jrc.c,v 1.22 2005-04-10 21:47:13 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -85,7 +85,12 @@ int jrc_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat if (!data || !data_len) return 0; - *data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM)); + retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM)); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; } diff --git a/kenwood/ic10.c b/kenwood/ic10.c index 3c5644668..15dc855d3 100644 --- a/kenwood/ic10.c +++ b/kenwood/ic10.c @@ -4,7 +4,7 @@ * * Copyright (c) 2000-2005 by Stephane Fillod and others * - * $Id: ic10.c,v 1.4 2005-01-25 00:20:04 fillods Exp $ + * $Id: ic10.c,v 1.5 2005-04-10 21:47:13 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -72,8 +72,13 @@ int ic10_transaction (RIG *rig, const char *cmd, int cmd_len, char *data, int *d if (!data || !data_len) return 0; - *data_len = read_string(&rs->rigport, data, 50, EOM_KEN, 1); - + retval = read_string(&rs->rigport, data, 50, EOM_KEN, 1); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; + return RIG_OK; } diff --git a/lowe/lowe.c b/lowe/lowe.c index 311345488..10236e2f7 100644 --- a/lowe/lowe.c +++ b/lowe/lowe.c @@ -1,8 +1,8 @@ /* * Hamlib Lowe backend - main file - * Copyright (c) 2003-2004 by Stephane Fillod + * Copyright (c) 2003-2005 by Stephane Fillod * - * $Id: lowe.c,v 1.3 2004-08-08 19:42:59 fillods Exp $ + * $Id: lowe.c,v 1.4 2005-04-10 21:47:13 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -74,7 +74,12 @@ int lowe_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *da if (!data || !data_len) return 0; - *data_len = read_string(&rs->rigport, data, BUFSZ, CR, 1); + retval = read_string(&rs->rigport, data, BUFSZ, CR, 1); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; } diff --git a/pcr/pcr.c b/pcr/pcr.c index c9ee1833c..6a2fa9d59 100644 --- a/pcr/pcr.c +++ b/pcr/pcr.c @@ -2,7 +2,7 @@ * Hamlib PCR backend - main file * Copyright (c) 2001-2005 by Stephane Fillod and Darren Hatcher * - * $Id: pcr.c,v 1.21 2005-01-25 00:20:40 fillods Exp $ + * $Id: pcr.c,v 1.22 2005-04-10 21:47:13 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -96,7 +96,7 @@ const int pcr1_ctcss_list[] = { * Otherwise, you'll get a nice seg fault. You've been warned! * TODO: error case handling */ -int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len) +static int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len) { int retval; struct rig_state *rs; @@ -107,25 +107,32 @@ int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat retval = write_block(&rs->rigport, cmd, cmd_len); if (retval != RIG_OK) - return retval; + return retval; /* eat the first ack */ #ifdef WANT_READ_STRING retval = read_string(&rs->rigport, data, 1, "\x0a", 1); if (retval < 0) - return retval; + return retval; if (retval != 1) - return -RIG_EPROTO; + return -RIG_EPROTO; #else retval = read_block(&rs->rigport, data, 1); + if (retval < 0) + return retval; #endif /* here is the real response */ #ifdef WANT_READ_STRING - *data_len = read_string(&rs->rigport, data, *data_len, "\x0a", 1); + retval = read_string(&rs->rigport, data, *data_len, "\x0a", 1); #else - *data_len = read_block( &rs->rigport, data, *data_len ); + retval = read_block( &rs->rigport, data, *data_len ); #endif + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; } diff --git a/rft/rft.c b/rft/rft.c index 31c7781b4..2acaeb209 100644 --- a/rft/rft.c +++ b/rft/rft.c @@ -2,7 +2,7 @@ * Hamlib RFT backend - main file * Copyright (c) 2003 by Thomas B. Ruecker * - * $Id: rft.c,v 1.1 2003-10-07 22:15:49 fillods Exp $ + * $Id: rft.c,v 1.2 2005-04-10 21:47:14 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -64,9 +64,14 @@ int rft_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat /* no data expected, TODO: flush input? */ if (!data || !data_len) - return 0; + return 0; - *data_len = read_string(&rs->rigport, data, BUFSZ, CR, 1); + retval = read_string(&rs->rigport, data, BUFSZ, CR, 1); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; } diff --git a/skanti/skanti.c b/skanti/skanti.c index 38d3d1dd8..7d8b354cb 100644 --- a/skanti/skanti.c +++ b/skanti/skanti.c @@ -1,8 +1,8 @@ /* * Hamlib Skanti backend - main file - * Copyright (c) 2004 by Stephane Fillod + * Copyright (c) 2004-2005 by Stephane Fillod * - * $Id: skanti.c,v 1.1 2004-08-18 18:51:24 fillods Exp $ + * $Id: skanti.c,v 1.2 2005-04-10 21:47:14 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -76,7 +76,7 @@ static int skanti_transaction(RIG *rig, const char *cmd, int cmd_len, char *data retval = write_block(&rs->rigport, cmd, cmd_len); if (retval != RIG_OK) - return retval; + return retval; /* no data expected, check for OK returned */ @@ -85,18 +85,23 @@ static int skanti_transaction(RIG *rig, const char *cmd, int cmd_len, char *data * Transceiver sends back ">" */ retval = read_string(&rs->rigport, retbuf, BUFSZ, PROMPT, strlen(PROMPT)); - if (retval < 0 || retval > BUFSZ) - return RIG_ERJCTED; + if (retval < 0) + return retval; retbuf[retval] = '\0'; if (strstr(retbuf, PROMPT)) return RIG_OK; else - return RIG_ERJCTED; + return -RIG_ERJCTED; } - *data_len = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF)); + retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF)); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; /* strip CR/LF from string */ diff --git a/tentec/tentec.c b/tentec/tentec.c index a79bf26d0..7750e8e11 100644 --- a/tentec/tentec.c +++ b/tentec/tentec.c @@ -1,8 +1,8 @@ /* * Hamlib Tentec backend - main file - * Copyright (c) 2001-2004 by Stephane Fillod + * Copyright (c) 2001-2005 by Stephane Fillod * - * $Id: tentec.c,v 1.14 2004-05-26 21:30:13 fillods Exp $ + * $Id: tentec.c,v 1.15 2005-04-10 21:47:14 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -73,13 +73,18 @@ int tentec_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int * retval = write_block(&rs->rigport, cmd, cmd_len); if (retval != RIG_OK) - return retval; + return retval; /* no data expected, TODO: flush input? */ if (!data || !data_len) - return 0; + return 0; - *data_len = read_string(&rs->rigport, data, *data_len, "", 0); + retval = read_string(&rs->rigport, data, *data_len, "", 0); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; } diff --git a/tentec/tt550.c b/tentec/tt550.c index 8a2c31d32..2759e37d9 100644 --- a/tentec/tt550.c +++ b/tentec/tt550.c @@ -95,10 +95,17 @@ tt550_transaction (RIG * rig, const char *cmd, int cmd_len, char *data, /* * no data expected, TODO: flush input? */ - if (!data || !data_len) + if (!data || !data_len) { + Unhold_Decode (rig); return 0; + } - *data_len = read_string (&rs->rigport, data, *data_len, "", 0); + retval = read_string (&rs->rigport, data, *data_len, "", 0); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; Unhold_Decode (rig); diff --git a/uniden/uniden.c b/uniden/uniden.c index 2fae51b8b..f7696ab2d 100644 --- a/uniden/uniden.c +++ b/uniden/uniden.c @@ -2,7 +2,7 @@ * Hamlib Uniden backend - main file * Copyright (c) 2001-2005 by Stephane Fillod * - * $Id: uniden.c,v 1.10 2005-01-25 00:21:56 fillods Exp $ + * $Id: uniden.c,v 1.11 2005-04-10 21:47:14 fillods Exp $ * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License as @@ -56,7 +56,7 @@ * We assume that rig!=NULL, rig->state!= NULL, data!=NULL, data_len!=NULL * Otherwise, you'll get a nice seg fault. You've been warned! */ -int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len) +static int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len) { int retval; struct rig_state *rs; @@ -72,9 +72,14 @@ int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int * /* no data expected, TODO: flush input? */ if (!data || !data_len) - return 0; + return 0; - *data_len = read_string(&rs->rigport, data, BUFSZ, "\x0a", 1); + retval = read_string(&rs->rigport, data, BUFSZ, "\x0a", 1); + if (retval == -RIG_ETIMEOUT) + retval = 0; + if (retval < 0) + return retval; + *data_len = retval; return RIG_OK; }