aboutsummaryrefslogtreecommitdiff
path: root/lib/cmyth
diff options
context:
space:
mode:
authorDavid Teirney <david@teirney.net>2012-06-24 13:17:36 +1200
committerDavid Teirney <david@teirney.net>2012-07-09 23:27:23 +1200
commit174e3e84e1e6b57b137b234cf4110d2529a49608 (patch)
tree38002ce319ca215b78bcc039b36158245496842f /lib/cmyth
parent01b3f30b8338c4e2cdabb2fca2f03fce5325bcca (diff)
[libcmyth] Convert all long long fields and methods to int64.
Pulled from upstream as part of the changes that made for the protocol changes where long long values were changed to be sent in a single 64 bit field rather than two 32 bit hi and lo fields.
Diffstat (limited to 'lib/cmyth')
-rw-r--r--lib/cmyth/libcmyth/bookmark.c6
-rw-r--r--lib/cmyth/libcmyth/cmyth_local.h49
-rw-r--r--lib/cmyth/libcmyth/commbreak.c4
-rw-r--r--lib/cmyth/libcmyth/connection.c20
-rw-r--r--lib/cmyth/libcmyth/file.c31
-rw-r--r--lib/cmyth/libcmyth/ringbuf.c10
-rw-r--r--lib/cmyth/libcmyth/socket.c242
7 files changed, 232 insertions, 130 deletions
diff --git a/lib/cmyth/libcmyth/bookmark.c b/lib/cmyth/libcmyth/bookmark.c
index 466ccb275c..43529697e0 100644
--- a/lib/cmyth/libcmyth/bookmark.c
+++ b/lib/cmyth/libcmyth/bookmark.c
@@ -32,7 +32,7 @@ long long cmyth_get_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog)
int err;
long long ret;
int count;
- long long ll;
+ int64_t ll;
int r;
char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1];
cmyth_datetime_to_string(start_ts_dt, prog->proginfo_rec_start_ts);
@@ -58,9 +58,9 @@ long long cmyth_get_bookmark(cmyth_conn_t conn, cmyth_proginfo_t prog)
ret = count;
goto out;
}
- if ((r=cmyth_rcv_long_long(conn, &err, &ll, count)) < 0) {
+ if ((r=cmyth_rcv_int64(conn, &err, &ll, count)) < 0) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_long_long() failed (%d)\n",
+ "%s: cmyth_rcv_int64() failed (%d)\n",
__FUNCTION__, r);
ret = err;
goto out;
diff --git a/lib/cmyth/libcmyth/cmyth_local.h b/lib/cmyth/libcmyth/cmyth_local.h
index 93fda9efd7..ef8fa8feed 100644
--- a/lib/cmyth/libcmyth/cmyth_local.h
+++ b/lib/cmyth/libcmyth/cmyth_local.h
@@ -150,10 +150,10 @@ struct cmyth_file {
long file_id; /**< file identifier */
/** callback when close is completed */
void (*closed_callback)(cmyth_file_t file);
- unsigned long long file_start; /**< file start offest */
- unsigned long long file_length; /**< file length */
- unsigned long long file_pos; /**< current file position */
- unsigned long long file_req; /**< current file position requested */
+ uint64_t file_start; /**< file start offest */
+ uint64_t file_length; /**< file length */
+ uint64_t file_pos; /**< current file position */
+ uint64_t file_req; /**< current file position requested */
cmyth_conn_t file_control; /**< master backend connection */
};
@@ -161,10 +161,10 @@ struct cmyth_ringbuf {
cmyth_conn_t conn_data;
long file_id;
char *ringbuf_url;
- unsigned long long ringbuf_size;
- unsigned long long file_length;
- unsigned long long file_pos;
- unsigned long long ringbuf_fill;
+ uint64_t ringbuf_size;
+ uint64_t file_length;
+ uint64_t file_pos;
+ uint64_t ringbuf_fill;
char *ringbuf_hostname;
int ringbuf_port;
};
@@ -177,7 +177,7 @@ struct cmyth_rec_num {
struct cmyth_keyframe {
unsigned long keyframe_number;
- unsigned long long keyframe_pos;
+ uint64_t keyframe_pos;
};
struct cmyth_posmap {
@@ -186,8 +186,8 @@ struct cmyth_posmap {
};
struct cmyth_freespace {
- unsigned long long freespace_total;
- unsigned long long freespace_used;
+ uint64_t freespace_total;
+ uint64_t freespace_used;
};
struct cmyth_timestamp {
@@ -213,7 +213,7 @@ struct cmyth_proginfo {
char *proginfo_channame; /* Deprecated in V8, simulated for compat. */
char *proginfo_chanicon; /* New in V8 */
char *proginfo_url;
- long long proginfo_Length;
+ int64_t proginfo_Length;
cmyth_timestamp_t proginfo_start_ts;
cmyth_timestamp_t proginfo_end_ts;
unsigned long proginfo_conflicting; /* Deprecated in V8, always 0 */
@@ -295,14 +295,27 @@ extern int cmyth_rcv_short(cmyth_conn_t conn, int *err, short *buf, int count);
extern int cmyth_rcv_long(cmyth_conn_t conn, int *err, long *buf, int count);
#define cmyth_rcv_u_long(c, e, b, n) cmyth_rcv_long(c, e, (long*)b, n)
-#define cmyth_rcv_long_long __cmyth_rcv_long_long
-extern int cmyth_rcv_long_long(cmyth_conn_t conn, int *err, long long *buf,
+#define cmyth_rcv_old_int64 __cmyth_rcv_old_int64
+extern int cmyth_rcv_old_int64(cmyth_conn_t conn, int *err, int64_t *buf,
int count);
-#define cmyth_rcv_u_long_long(c, e, b, n) cmyth_rcv_long_long(c, e, (long long*)b, n)
-#define cmyth_rcv_int64 __cmyth_rcv_int64
-extern int cmyth_rcv_int64(cmyth_conn_t conn, int *err, long long *buf,
- int count);
+#define cmyth_rcv_new_int64 __cmyth_rcv_new_int64
+extern int cmyth_rcv_new_int64(cmyth_conn_t conn, int *err, int64_t *buf,
+ int count, int forced);
+
+#define cmyth_rcv_old_uint64 __cmyth_rcv_old_uint64
+extern int cmyth_rcv_old_uint64(cmyth_conn_t conn, int *err, uint64_t *buf,
+ int count);
+
+#define cmyth_rcv_new_uint64 __cmyth_rcv_new_uint64
+extern int cmyth_rcv_new_uint64(cmyth_conn_t conn, int *err, uint64_t *buf,
+ int count, int forced);
+
+#define cmyth_rcv_int64(conn, err, buf, count) \
+ cmyth_rcv_new_int64(conn, err, buf, count, 0)
+
+#define cmyth_rcv_uint64(conn, err, buf, count) \
+ cmyth_rcv_new_uint64(conn, err, buf, count, 0)
#define cmyth_rcv_ubyte __cmyth_rcv_ubyte
extern int cmyth_rcv_ubyte(cmyth_conn_t conn, int *err, unsigned char *buf,
diff --git a/lib/cmyth/libcmyth/commbreak.c b/lib/cmyth/libcmyth/commbreak.c
index 6a1098171a..ad5391f1d0 100644
--- a/lib/cmyth/libcmyth/commbreak.c
+++ b/lib/cmyth/libcmyth/commbreak.c
@@ -190,7 +190,7 @@ int cmyth_rcv_commbreaklist(cmyth_conn_t conn, int *err,
int consumed;
int total = 0;
long rows;
- long long mark;
+ int64_t mark;
long long start = -1;
char *failed = NULL;
cmyth_commbreak_t commbreak;
@@ -229,7 +229,7 @@ int cmyth_rcv_commbreaklist(cmyth_conn_t conn, int *err,
goto fail;
}
- consumed = cmyth_rcv_long_long(conn, err, &mark, count);
+ consumed = cmyth_rcv_int64(conn, err, &mark, count);
count -= consumed;
total += consumed;
if (*err) {
diff --git a/lib/cmyth/libcmyth/connection.c b/lib/cmyth/libcmyth/connection.c
index 8ac72ccdb3..7f80f4694d 100644
--- a/lib/cmyth/libcmyth/connection.c
+++ b/lib/cmyth/libcmyth/connection.c
@@ -634,10 +634,10 @@ cmyth_conn_connect_file(cmyth_proginfo_t prog, cmyth_conn_t control,
goto shut;
}
count -= r;
- r = cmyth_rcv_u_long_long(conn, &err, &ret->file_length, count);
+ r = cmyth_rcv_uint64(conn, &err, &ret->file_length, count);
if (err) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: (length) cmyth_rcv_u_long_long() failed (%d)\n",
+ "%s: (length) cmyth_rcv_uint64() failed (%d)\n",
__FUNCTION__, err);
goto shut;
}
@@ -784,10 +784,10 @@ cmyth_conn_connect_path(char* path, cmyth_conn_t control,
goto shut;
}
count -= r;
- r = cmyth_rcv_u_long_long(conn, &err, &ret->file_length, count);
+ r = cmyth_rcv_uint64(conn, &err, &ret->file_length, count);
if (err) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: (length) cmyth_rcv_u_long_long() failed (%d)\n",
+ "%s: (length) cmyth_rcv_uint64() failed (%d)\n",
__FUNCTION__, err);
goto shut;
}
@@ -1197,7 +1197,7 @@ cmyth_conn_get_freespace(cmyth_conn_t control,
int r;
char msg[256];
char reply[256];
- long long lreply;
+ int64_t lreply;
if (control == NULL)
return -EINVAL;
@@ -1231,19 +1231,17 @@ cmyth_conn_get_freespace(cmyth_conn_t control,
}
if (control->conn_version >= 17) {
- if ((r=cmyth_rcv_long_long(control, &err, &lreply,
- count)) < 0) {
+ if ((r=cmyth_rcv_int64(control, &err, &lreply, count)) < 0) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_long_long() failed (%d)\n",
+ "%s: cmyth_rcv_int64() failed (%d)\n",
__FUNCTION__, err);
ret = err;
goto out;
}
*total = lreply;
- if ((r=cmyth_rcv_long_long(control, &err, &lreply,
- count-r)) < 0) {
+ if ((r=cmyth_rcv_int64(control, &err, &lreply, count - r)) < 0) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_long_long() failed (%d)\n",
+ "%s: cmyth_rcv_int64() failed (%d)\n",
__FUNCTION__, err);
ret = err;
goto out;
diff --git a/lib/cmyth/libcmyth/file.c b/lib/cmyth/libcmyth/file.c
index 401e3e7d2b..1939aa9e1c 100644
--- a/lib/cmyth/libcmyth/file.c
+++ b/lib/cmyth/libcmyth/file.c
@@ -424,7 +424,7 @@ cmyth_file_seek(cmyth_file_t file, long long offset, int whence)
char msg[128];
int err;
int count;
- long long c;
+ int64_t c;
long r;
long long ret;
@@ -486,9 +486,9 @@ cmyth_file_seek(cmyth_file_t file, long long offset, int whence)
ret = count;
goto out;
}
- if ((r=cmyth_rcv_long_long(file->file_control, &err, &c, count)) < 0) {
+ if ((r=cmyth_rcv_int64(file->file_control, &err, &c, count)) < 0) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_long_long() failed (%d)\n",
+ "%s: cmyth_rcv_int64() failed (%d)\n",
__FUNCTION__, r);
ret = err;
goto out;
@@ -539,7 +539,7 @@ int cmyth_file_read(cmyth_file_t file, char *buf, unsigned long len)
int ret, req, nfds, rec;
char *end, *cur;
char msg[256];
- long long len64;
+ int64_t len64;
struct timeval tv;
fd_set fds;
@@ -622,9 +622,20 @@ int cmyth_file_read(cmyth_file_t file, char *buf, unsigned long len)
goto out;
}
- if ((ret=cmyth_rcv_int64 (file->file_control, &err, &len64, count))< 0) {
+ /*
+ * MythTV originally sent back a signed 32bit value but was changed to a
+ * signed 64bit value in http://svn.mythtv.org/trac/changeset/18011 (1-Aug-2008).
+ *
+ * libcmyth now retrieves the 64-bit signed value, does error-checking,
+ * and then converts to a 32bit unsigned.
+ *
+ * This rcv_ method needs to be forced to use new_int64 to pull back a
+ * single 64bit number otherwise the handling in rcv_int64 will revert to
+ * the old two 32bit hi and lo long values.
+ */
+ if ((ret=cmyth_rcv_new_int64 (file->file_control, &err, &len64, count, 1))< 0) {
cmyth_dbg (CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_int64() failed (%d)\n",
+ "%s: cmyth_rcv_new_int64() failed (%d)\n",
__FUNCTION__, ret);
ret = err;
goto out;
@@ -632,8 +643,8 @@ int cmyth_file_read(cmyth_file_t file, char *buf, unsigned long len)
if (len64 >= 0x100000000LL || len64 < 0) {
/* -1 seems to be a common result, but isn't valid so use 0 instead. */
cmyth_dbg (CMYTH_DBG_WARN,
- "%s: cmyth_rcv_int64() returned out of bound value (%d). Using 0\n",
- __FUNCTION__, (long)len64);
+ "%s: cmyth_rcv_new_int64() returned out of bound value (%"PRId64"). Using 0 instead.\n",
+ __FUNCTION__, len64);
len64 = 0;
}
len = (unsigned long)len64;
@@ -642,8 +653,8 @@ int cmyth_file_read(cmyth_file_t file, char *buf, unsigned long len)
if (file->file_req < file->file_pos) {
cmyth_dbg (CMYTH_DBG_ERROR,
- "%s: received invalid invalid length, read position is ahead of request (req: %d, rec: %d, len: %d)\n",
- __FUNCTION__, file->file_req, file->file_pos, len);
+ "%s: received invalid invalid length, read position is ahead of request (req: %"PRIu64", pos: %"PRIu64", len: %"PRId64")\n",
+ __FUNCTION__, file->file_req, file->file_pos, len64);
ret = -1;
goto out;
}
diff --git a/lib/cmyth/libcmyth/ringbuf.c b/lib/cmyth/libcmyth/ringbuf.c
index 49519f0cdf..77ea52d54b 100644
--- a/lib/cmyth/libcmyth/ringbuf.c
+++ b/lib/cmyth/libcmyth/ringbuf.c
@@ -131,7 +131,7 @@ cmyth_ringbuf_setup(cmyth_recorder_t rec)
int err, count;
int r;
- long long size, fill;
+ int64_t size, fill;
char msg[256];
char url[1024];
char buf[32];
@@ -167,7 +167,7 @@ cmyth_ringbuf_setup(cmyth_recorder_t rec)
r = cmyth_rcv_string(control, &err, url, sizeof(url)-1, count);
count -= r;
- if ((r=cmyth_rcv_long_long(control, &err, &size, count)) < 0) {
+ if ((r=cmyth_rcv_int64(control, &err, &size, count)) < 0) {
cmyth_dbg(CMYTH_DBG_ERROR,
"%s: cmyth_rcv_length() failed (%d)\n",
__FUNCTION__, r);
@@ -175,7 +175,7 @@ cmyth_ringbuf_setup(cmyth_recorder_t rec)
}
count -= r;
- if ((r=cmyth_rcv_long_long(control, &err, &fill, count)) < 0) {
+ if ((r=cmyth_rcv_int64(control, &err, &fill, count)) < 0) {
cmyth_dbg(CMYTH_DBG_ERROR,
"%s: cmyth_rcv_length() failed (%d)\n",
__FUNCTION__, r);
@@ -528,7 +528,7 @@ cmyth_ringbuf_seek(cmyth_recorder_t rec,
char msg[128];
int err;
int count;
- long long c;
+ int64_t c;
long r;
long long ret;
cmyth_ringbuf_t ring;
@@ -561,7 +561,7 @@ cmyth_ringbuf_seek(cmyth_recorder_t rec,
}
count = cmyth_rcv_length(rec->rec_conn);
- if ((r=cmyth_rcv_long_long(rec->rec_conn, &err, &c, count)) < 0) {
+ if ((r=cmyth_rcv_int64(rec->rec_conn, &err, &c, count)) < 0) {
cmyth_dbg(CMYTH_DBG_ERROR,
"%s: cmyth_rcv_length() failed (%d)\n",
__FUNCTION__, r);
diff --git a/lib/cmyth/libcmyth/socket.c b/lib/cmyth/libcmyth/socket.c
index 4e7ca681c4..096a8e0ae9 100644
--- a/lib/cmyth/libcmyth/socket.c
+++ b/lib/cmyth/libcmyth/socket.c
@@ -832,7 +832,7 @@ cmyth_rcv_short(cmyth_conn_t conn, int *err, short *buf, int count)
}
/*
- * cmyth_rcv_long_long(cmyth_conn_t conn, int *err, long long *buf, int count)
+ * cmyth_rcv_old_int64(cmyth_conn_t conn, int *err, long long *buf, int count)
*
* Scope: PRIVATE (mapped to __cmyth_rcv_long)
*
@@ -863,9 +863,9 @@ cmyth_rcv_short(cmyth_conn_t conn, int *err, short *buf, int count)
* EINVAL The token received is not numeric
*/
int
-cmyth_rcv_long_long(cmyth_conn_t conn, int *err, long long *buf, int count)
+cmyth_rcv_old_int64(cmyth_conn_t conn, int *err, int64_t *buf, int count)
{
- long long val;
+ int64_t val;
int consumed;
int tmp;
unsigned long hi, lo;
@@ -879,45 +879,138 @@ cmyth_rcv_long_long(cmyth_conn_t conn, int *err, long long *buf, int count)
return 0;
}
- if (conn->conn_version >= 66) {
- /*
- * Since protocol 66 mythbackend now sends a single 64 bit integer rather than two hi and lo
- * 32 bit integers for ALL 64 bit values.
- */
- consumed = cmyth_rcv_int64(conn, err, &val, count);
- if (*err) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_int64() failed (%d)\n",
- __FUNCTION__, consumed);
- return consumed;
- }
+ consumed = cmyth_rcv_u_long(conn, err, &hi, count);
+ if (*err) {
+ cmyth_dbg(CMYTH_DBG_ERROR,
+ "%s: cmyth_rcv_u_long() failed (%d)\n",
+ __FUNCTION__, consumed);
+ return consumed;
}
- else {
- consumed = cmyth_rcv_u_long(conn, err, &hi, count);
- if (*err) {
+ consumed += cmyth_rcv_u_long(conn, err, &lo, count-consumed);
+ if (*err) {
+ cmyth_dbg(CMYTH_DBG_ERROR,
+ "%s: cmyth_rcv_u_long() failed (%d)\n",
+ __FUNCTION__, consumed);
+ return consumed;
+ }
+ val = (((long long)hi) << 32) | ((long long)(lo & 0xFFFFFFFF));
+
+ *err = 0;
+ *buf = val;
+
+ return consumed;
+}
+
+/*
+ * cmyth_rcv_new_int64(cmyth_conn_t conn, int *err, long long *buf, int count)
+ *
+ * Scope: PRIVATE (mapped to __cmyth_rcv_long)
+ *
+ * Description
+ *
+ * Receive a long long (signed 64 bit) integer token from a list of tokens
+ * in a MythTV Protocol message. Tokens in MythTV Protocol messages
+ * are separated by the string: []:[] or terminated by running out of
+ * message. Up to 'count' Bytes will be consumed from the socket
+ * specified by 'conn' (stopping when a separator is seen or 'count'
+ * is exhausted). The long integer value of the token is placed in
+ * the location pointed to by 'buf'. If an error is encountered and
+ * 'err' is not NULL, an indication of the nature of the error will be
+ * recorded by placing an error code in the location pointed to by
+ * 'err'. If all goes well, 'err' wil be set to 0.
+ *
+ * As of protocol version 57, Myth now sends a single 64bit string instead
+ * of 2 32bit strings when sending proginfo data. This does not seem to
+ * apply uniformly though. For instance 'ANN FILETRANSFER' still uses
+ * the old method
+ *
+ * Return Value:
+ *
+ * A value >=0 indicating the number of bytes consumed.
+ *
+ * Error Codes:
+ *
+ * In addition to system call error codes, the following errors may be
+ * placed in 'err':
+ *
+ * ERANGE The token received is too large to fit in a long integer
+ *
+ * EINVAL The token received is not numeric
+ */
+int
+cmyth_rcv_new_int64(cmyth_conn_t conn, int *err, int64_t *buf, int count,
+ int forced)
+{
+ char num[32];
+ char *num_p = num;
+ unsigned long long val = 0;
+ int sign = 1;
+ long long limit = 0x7fffffffffffffffLL;
+ int consumed;
+ int tmp;
+
+ /*
+ * Between protocols 57 and 66, not all messages used the new
+ * format for 64-bit values.
+ */
+ if ((conn->conn_version < 57) ||
+ ((conn->conn_version < 66) && !forced)) {
+ return cmyth_rcv_old_int64(conn, err, buf, count);
+ }
+
+ if (!err) {
+ err = &tmp;
+ }
+ if (count <= 0) {
+ *err = EINVAL;
+ return 0;
+ }
+ *err = 0;
+ consumed = cmyth_rcv_string(conn, err, num, sizeof(num), count);
+ if (*err) {
+ cmyth_dbg(CMYTH_DBG_ERROR,
+ "%s: cmyth_rcv_string() failed (%d)\n",
+ __FUNCTION__, consumed);
+ return consumed;
+ }
+ if (*num_p && (*num_p == '-')) {
+ ++num_p;
+ sign = -1;
+ }
+ while (*num_p) {
+ if (!isdigit(*num_p)) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_u_long_long() failed (%d)\n",
- __FUNCTION__, consumed);
+ "%s: received illegal integer: '%s'\n",
+ __FUNCTION__, num);
+ *err = EINVAL;
return consumed;
}
- consumed += cmyth_rcv_u_long(conn, err, &lo, count-consumed);
- if (*err) {
+ val *= 10;
+ val += ((*num_p) - '0');
+ /*
+ * Check and make sure we are still under the limit (this is
+ * an absolute value limit, sign will be applied later).
+ */
+ if (val > (unsigned long long)limit) {
cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_u_long_long() failed (%d)\n",
- __FUNCTION__, consumed);
+ "%s: long long out of range: '%s'\n",
+ __FUNCTION__, num, limit);
+ *err = ERANGE;
return consumed;
}
- val = (((long long)hi) << 32) | ((long long)(lo & 0xFFFFFFFF));
+ num_p++;
}
- *err = 0;
- *buf = val;
+ /*
+ * Got a result, return it.
+ */
+ *buf = (long long)(sign * val);
return consumed;
}
/*
- * cmyth_rcv_int64(cmyth_conn_t conn, int *err, long long *buf, int count)
+ * cmyth_rcv_new_uint64(cmyth_conn_t conn, int *err, uint64_t *buf, int count)
*
* Scope: PRIVATE (mapped to __cmyth_rcv_long)
*
@@ -953,16 +1046,26 @@ cmyth_rcv_long_long(cmyth_conn_t conn, int *err, long long *buf, int count)
* EINVAL The token received is not numeric
*/
int
-cmyth_rcv_int64(cmyth_conn_t conn, int *err, long long *buf, int count)
+cmyth_rcv_new_uint64(cmyth_conn_t conn, int *err, uint64_t *buf, int count,
+ int forced)
{
char num[32];
char *num_p = num;
- unsigned long long val = 0;
+ uint64_t val = 0;
int sign = 1;
long long limit = 0x7fffffffffffffffLL;
int consumed;
int tmp;
+ /*
+ * Between protocols 57 and 66, not all messages used the new
+ * format for 64-bit values.
+ */
+ if ((conn->conn_version < 57) ||
+ ((conn->conn_version < 66) && !forced)) {
+ return cmyth_rcv_old_uint64(conn, err, buf, count);
+ }
+
if (!err) {
err = &tmp;
}
@@ -1179,16 +1282,14 @@ cmyth_rcv_ushort(cmyth_conn_t conn, int *err, unsigned short *buf, int count)
* EINVAL The token received is not numeric or is signed
*/
int
-cmyth_rcv_ulong_long(cmyth_conn_t conn, int *err,
- unsigned long long *buf, int count)
+cmyth_rcv_old_uint64(cmyth_conn_t conn, int *err, uint64_t *buf, int count)
{
unsigned long long val;
- long long val64;
unsigned long hi, lo;
int consumed;
int tmp;
- *buf = 0;
+ *buf = 0;
if (!err) {
err = &tmp;
@@ -1199,44 +1300,22 @@ cmyth_rcv_ulong_long(cmyth_conn_t conn, int *err,
return 0;
}
- if (conn->conn_version >= 66) {
- /*
- * Since protocol 66 mythbackend now sends a single 64 bit integer rather than two hi and lo
- * 32 bit integers for ALL 64 bit values.
- */
- consumed = cmyth_rcv_int64(conn, err, &val64, count);
- if (*err) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_int64() failed (%d)\n",
- __FUNCTION__, consumed);
- return consumed;
- }
- if (val64 < 0) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_int64() failed as signed 64 bit integer received\n",
- __FUNCTION__, consumed);
- *err = EINVAL;
- return consumed;
- }
- val = (unsigned long long)val64;
+ consumed = cmyth_rcv_u_long(conn, err, &hi, count);
+ if (*err) {
+ cmyth_dbg(CMYTH_DBG_ERROR,
+ "%s: cmyth_rcv_u_long() failed (%d)\n",
+ __FUNCTION__, consumed);
+ return consumed;
}
- else {
- consumed = cmyth_rcv_u_long(conn, err, &hi, count);
- if (*err) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_u_long_long() failed (%d)\n",
- __FUNCTION__, consumed);
- return consumed;
- }
- consumed += cmyth_rcv_u_long(conn, err, &lo, count);
- if (*err) {
- cmyth_dbg(CMYTH_DBG_ERROR,
- "%s: cmyth_rcv_u_long_long() failed (%d)\n",
- __FUNCTION__, consumed);
- return consumed;
- }
- val = (((unsigned long long)hi) << 32) | ((unsigned long long)(lo & 0xFFFFFFFF));
+ consumed += cmyth_rcv_u_long(conn, err, &lo, count - consumed);
+ if (*err) {
+ cmyth_dbg(CMYTH_DBG_ERROR,
+ "%s: cmyth_rcv_u_long() failed (%d)\n",
+ __FUNCTION__, consumed);
+ return consumed;
}
+ val = (((unsigned long long)hi) << 32) | ((unsigned long long)(lo & 0xFFFFFFFF));
+
*err = 0;
*buf = val;
@@ -1504,7 +1583,6 @@ cmyth_rcv_proginfo(cmyth_conn_t conn, int *err, cmyth_proginfo_t buf,
int total = 0;
char *failed = NULL;
char tmp_str[32768];
- int (*rcv_64)(cmyth_conn_t, int *, long long *, int);
if (count <= 0) {
*err = EINVAL;
@@ -1517,15 +1595,6 @@ cmyth_rcv_proginfo(cmyth_conn_t conn, int *err, cmyth_proginfo_t buf,
cmyth_dbg(CMYTH_DBG_DEBUG, "%s: VERSION IS %ld\n",
__FUNCTION__, buf->proginfo_version);
- if (buf->proginfo_version >= 57) {
- /*
- * Since protocol 57 mythbackend now sends a single 64 bit integer rather than two 32 bit
- * hi and lo integers for the proginfo length.
- */
- rcv_64 = &cmyth_rcv_int64;
- } else {
- rcv_64 = &cmyth_rcv_long_long;
- }
/*
* Get proginfo_title (string)
*/
@@ -1703,7 +1772,18 @@ cmyth_rcv_proginfo(cmyth_conn_t conn, int *err, cmyth_proginfo_t buf,
/*
* Get proginfo_Length (long_long)
*/
- consumed = rcv_64(conn, err, &buf->proginfo_Length, count);
+ if (buf->proginfo_version < 57) {
+ consumed = cmyth_rcv_old_int64(conn, err, &buf->proginfo_Length,
+ count);
+ } else {
+ /*
+ * Since protocol 57 mythbackend now sends a single 64 bit
+ * integer rather than two 32 bit hi and lo integers for the
+ * proginfo length.
+ */
+ consumed = cmyth_rcv_new_int64(conn, err, &buf->proginfo_Length,
+ count, 1);
+ }
count -= consumed;
total += consumed;
if (*err) {