aboutsummaryrefslogtreecommitdiff
path: root/osc
diff options
context:
space:
mode:
authorMartin Peach <mrpeach@users.sourceforge.net>2010-12-16 05:35:47 +0000
committerMartin Peach <mrpeach@users.sourceforge.net>2010-12-16 05:35:47 +0000
commitec9960cb49988a010b76b537f7fd4f7391a208a5 (patch)
tree03529f6288554a3f93c8fac67b47876cf54a3ce6 /osc
parent4de9340c311527de508fcbab74e32dd55fe73273 (diff)
Fixed problems when bundle depth is exceeded. Placed global defines in packingOSC.h. Thanks to zmoelnig for pointing this out in tracker id 3136648.
svn path=/trunk/externals/mrpeach/; revision=14663
Diffstat (limited to 'osc')
-rw-r--r--osc/packOSC.c30
-rw-r--r--osc/packingOSC.h42
-rw-r--r--osc/unpackOSC.c57
3 files changed, 57 insertions, 72 deletions
diff --git a/osc/packOSC.c b/osc/packOSC.c
index b2d1086..728b83a 100644
--- a/osc/packOSC.c
+++ b/osc/packOSC.c
@@ -33,22 +33,8 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
#define SC_BUFFER_SIZE 64000
-#include "m_pd.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
+#include "packingOSC.h"
-#ifdef _WIN32
-#include <winsock2.h>
-#include <sys/timeb.h>
-#else
-#include <ctype.h>
-#include <sys/time.h>
-#endif
-
-#ifdef unix
-#include <netinet/in.h>
-#endif
/* This is from OSC-client.h :*/
/*
@@ -92,14 +78,6 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
to dereference a pointer to an 8 byte int that's not 8-byte aligned.
*/
-/* You may have to redefine this typedef if ints on your system
- aren't 4 bytes. */
-typedef unsigned int uint4;
-typedef struct
-{
- uint4 seconds;
- uint4 fraction;
-} OSCTimeTag;
/* Return the time tag 0x0000000000000001, indicating to the receiving device
that it should process the message immediately. */
@@ -321,8 +299,8 @@ static void packOSC_openbundle(t_packOSC *x)
result = OSC_openBundle(x->x_oscbuf, OSCTT_Immediately());
else
result = OSC_openBundle(x->x_oscbuf, OSCTT_CurrentTimePlusOffset((uint4)x->x_timeTagOffset));
- if (result != 0) return;
- x->x_bundle = 1;
+ if (result != 0) x->x_bundle = 0;
+ else x->x_bundle = 1;
outlet_float(x->x_bdpthout, (float)x->x_oscbuf->bundleDepth);
}
@@ -1074,7 +1052,7 @@ static int OSC_closeBundle(OSCbuf *buf)
if (buf->bundleDepth == 0)
{
/* This handles EMPTY, ONE_MSG, ARGS, and DONE */
- post("packOSC: Can't close bundle; no bundle is open!");
+ post("packOSC: Can't close bundle: no bundle is open!");
return 5;
}
diff --git a/osc/packingOSC.h b/osc/packingOSC.h
new file mode 100644
index 0000000..49e9e1e
--- /dev/null
+++ b/osc/packingOSC.h
@@ -0,0 +1,42 @@
+/* packingOSC.h */
+#ifndef _PACKINGOSC
+#include "m_pd.h"
+
+ #include <stdio.h>
+ #include <string.h>
+ #include <stdlib.h>
+#ifdef _WIN32
+ #include <winsock2.h>
+ #include <sys/timeb.h>
+#else
+ #include <sys/types.h>
+ #include <netinet/in.h>
+ #include <ctype.h>
+ #include <sys/time.h>
+#endif /* _WIN32 */
+
+/* Declarations */
+#ifdef WIN32
+ typedef unsigned __int64 osc_time_t;
+#else
+ typedef unsigned long long osc_time_t;
+#endif
+
+#define MAX_MESG 65536 /* same as MAX_UDP_PACKET */
+#define MAX_BUNDLE_NESTING 32 /* maximum bundle depth */
+/* You may have to redefine this typedef if ints on your system
+ aren't 4 bytes. */
+typedef unsigned int uint4;
+typedef struct
+{
+ uint4 seconds;
+ uint4 fraction;
+} OSCTimeTag;
+
+typedef union
+{
+ int i;
+ float f;
+} intfloat32;
+
+#endif // _PACKINGOSC \ No newline at end of file
diff --git a/osc/unpackOSC.c b/osc/unpackOSC.c
index 1e83a66..f6ef559 100644
--- a/osc/unpackOSC.c
+++ b/osc/unpackOSC.c
@@ -65,47 +65,8 @@ The OSC webpage is http://cnmat.cnmat.berkeley.edu/OpenSoundControl
*/
-#include "m_pd.h"
+#include "packingOSC.h"
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
-#ifdef _WIN32
- #include <winsock2.h>
- #include <sys/timeb.h>
-#else
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <ctype.h>
- #include <sys/time.h>
-#endif /* _WIN32 */
-
-/* Declarations */
-#ifdef WIN32
- typedef unsigned __int64 osc_time_t;
-#else
- typedef unsigned long long osc_time_t;
-#endif
-
-#define MAX_MESG 65536
-/* MAX_MESG was 32768 MP: make same as MAX_UDP_PACKET */
-#define OSC_MAX_RECURSION 16 /* maximum bundle depth */
-/* ----------------------------- was dumpOSC ------------------------- */
-
-/* You may have to redefine this typedef if ints on your system
- aren't 4 bytes. */
-typedef unsigned int uint4;
-typedef struct
-{
- uint4 seconds;
- uint4 fraction;
-} OSCTimeTag;
-
-typedef union
-{
- int i;
- float f;
-} intfloat32;
static t_class *unpackOSC_class;
@@ -119,7 +80,8 @@ typedef struct _unpackOSC
char x_raw[MAX_MESG];/* bytes making up the entire OSC message */
int x_raw_c;/* number of bytes in OSC message */
int x_bundle_flag;/* non-zero if we are processing a bundle */
- int x_recursion_level;/* number of times we reenter unpackOSCPath */
+ int x_recursion_level;/* number of times we reenter unpackOSC_list */
+ int x_abort_bundle;/* non-zero if unpackOSC_list is not well formed */
} t_unpackOSC;
void unpackOSC_setup(void);
@@ -137,13 +99,13 @@ static t_float unpackOSC_DeltaTime(OSCTimeTag tt);
static void *unpackOSC_new(void)
{
t_unpackOSC *x;
-
x = (t_unpackOSC *)pd_new(unpackOSC_class);
x->x_data_out = outlet_new(&x->x_obj, &s_list);
x->x_delay_out = outlet_new(&x->x_obj, &s_float);
x->x_raw_c = x->x_data_atc = 0;
x->x_bundle_flag = 0;
x->x_recursion_level = 0;
+ x->x_abort_bundle = 0;
return (x);
}
@@ -167,6 +129,7 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
char *messageName, *args, *buf;
OSCTimeTag tt;
+ if(x->x_abort_bundle) return; /* if backing quietly out of the recursive stack */
if ((argc%4) != 0)
{
post("unpackOSC: Packet size (%d) not a multiple of 4 bytes: dropping packet", argc);
@@ -253,15 +216,16 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
post("unpackOSC: Bad size count %d in bundle (only %d bytes left in entire bundle)",
size, argc-i-4);
x->x_recursion_level = 0;
- return;
+ return;
}
/* Recursively handle element of bundle */
x->x_recursion_level++;
- if (x->x_recursion_level > OSC_MAX_RECURSION)
+ if (x->x_recursion_level > MAX_BUNDLE_NESTING)
{
- post("unpackSOC: bundle depth %d exceeded", OSC_MAX_RECURSION);
+ post("unpackOSC: bundle depth %d exceeded", MAX_BUNDLE_NESTING);
x->x_recursion_level = 0;
+ x->x_abort_bundle = 1;/* we need to back out of the recursive stack*/
return;
}
unpackOSC_list(x, s, size, &argv[i+4]);
@@ -283,7 +247,7 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
{
post("unpackOSC: Time message: %s\n :).\n", buf);
x->x_recursion_level = 0;
- return;
+ return;
}
else
{ /* This is not a bundle message or a time message */
@@ -314,6 +278,7 @@ static void unpackOSC_list(t_unpackOSC *x, t_symbol *s, int argc, t_atom *argv)
outlet_anything(x->x_data_out, atom_getsymbol(x->x_data_at), x->x_data_atc-1, x->x_data_at+1);
x->x_data_atc = 0;
x->x_recursion_level = 0;
+ x->x_abort_bundle = 0;
}
static int unpackOSC_path(t_unpackOSC *x, char *path)