summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author(no author)2006-01-10 13:51:39 +0000
committer(no author)2006-01-10 13:51:39 +0000
commitd7960adb0c52a7abb2af932d1e7af98b980c8642 (patch)
tree7b995c5f5d12d102735a562364ca1a6ca50a29bc
parentdeaa6a5ec82c1d158caf360fd12672f72d7dae5b (diff)
downloadivy-c-d7960adb0c52a7abb2af932d1e7af98b980c8642.zip
ivy-c-d7960adb0c52a7abb2af932d1e7af98b980c8642.tar.gz
ivy-c-d7960adb0c52a7abb2af932d1e7af98b980c8642.tar.bz2
ivy-c-d7960adb0c52a7abb2af932d1e7af98b980c8642.tar.xz
This commit was manufactured by cvs2svn to create branch 'protocol_v3'.
-rw-r--r--redhat/changelog105
-rw-r--r--redhat/files15
-rw-r--r--redhat/rules21
-rw-r--r--redhat/rules-devel17
-rwxr-xr-xsrc/getopt.c76
-rwxr-xr-xsrc/getopt.h16
-rw-r--r--src/ivybind.c322
-rw-r--r--src/ivybind.h31
8 files changed, 445 insertions, 158 deletions
diff --git a/redhat/changelog b/redhat/changelog
deleted file mode 100644
index 72bccd0..0000000
--- a/redhat/changelog
+++ /dev/null
@@ -1,105 +0,0 @@
-$Version = "3.7";
-$Release = 0;
-
-$ChangeLog = ' * Sat Feb 20 1999 Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
-- Generation of ivy-c-3.0-2
-- New version 3.0, with new syntax for bus specification.
-
- * Sat Feb 20 1999 Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
-- Generation of ivy-c-3.0-3
-- New Makefile with major and minor numbers
-
- * Sat Feb 20 1999 Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
-- Generation of ivy-c-3.0-4
-- First attempt to fix dependencies
-
- * Sat Feb 20 1999 Stéphane Chatty <chatty@cenatoulouse.dgac.fr>
-- Generation of ivy-c-3.0-5
-- Fixed Makefile: added links for shared libs
-
- * Tue Apr 13 1999 Michelle Jacomi <jacomi@cenatoulouse.dgac.fr>
-- Generation of ivy-c-3.0-8
-- doc files added to ivy-c package
-
- * Mon Mar 13 2000 Stéphane Chatty <chatty@cena.fr>
-- Generation of ivy-c-3.2-1
-- First package with new version of rpmize. This is ivy-c 3.2
-
- * Tue Jul 4 2000 Stéphane Chatty <chatty@cena.fr>
-- Generation of version 3.2-2
-- First packages made with rpmize 3.1
-- Separation between ivy-c and ivy-c-devel
-
- * Wed Jul 12 2000 Stéphane Chatty <chatty@cena.fr>
-- Generation of version 3.2-3
-- The ivyprobe man page is now part of the main package
-- The URL has been fixed
-
- * Mon Aug 7 2000 Stéphane Chatty <chatty@cena.fr>
-- Generation of version 3.2-4
-- Just an upgrade of the documentation and fixes in the copyright headers
-
- * Tue Dec 12 2000 Stéphane Chatty <chatty@cena.fr>
-- Generation of version 3.2-5
-- Small fix in doc
-
- * Fri Dec 22 2000 Stéphane Chatty <chatty@cena.fr>
-- Generation of version 3.3-1
-- Additions by F.R.Colin
-
- * Tue Jun 25 2002 Stéphane Chatty <chatty@cena.fr>
-- Generation of version 3.4-1
-- * support of multicast, with IP adresses between 224.0.0.0 and 239.255.255.255
-- (i.e. no support for named group), by frc
-- * correction of message parsing in some strange but correct messages, by frc
-- e.g. with a regexp like "foo(.*) (.*)" and a message like "foo1 2", the receiver
-- will receive two values \'1\' and \'2\'
-- * upgrade of the documentation and fixes in the copyright headers, by sc
-- * miminal support of glut toolkit, by frc. However, there is currently no
-- libglutivy in the bin package due to some glut loop limitation.
-
-
-
- * Thu, 24 Jun 2004 Yannick Jestin <jestin@cena.fr>
-- Generation of version 3.6
-- * now uses PCRE ( Perl Compatible Regular Expressions ). Please use -livy -lpcre
-- now when compiling. See http://www.pcre.org or man pcre for more details
-- * tclivy.c : many bugfixes to support spaces in parameters captured by
-- regexp
-- * added an example directory, with gtk motif and tk bindings
-- * fixed a nasty bug in the IvyUnbindMsg, where new client still were sent a
-- binding to the unbound regexps
-- * added a help message for ivyprobe, when called with -? or with unknown
-- command line switches
-- * added a -n switch to ivyprobe to change the name of the ivyprobe
-- * added a -v switch to ivyprobe to check the ivy-c version
-- * Makefile merges solaris, linux, and OSX versions. edit before compiling...
-
- * Thu Sep 2 2004 Alexandre Bustico <bustico@cena.fr>
-- Generation of version 3.6-1
-- updates redhat files to coorect rules file for rpmize
-
- * Tue Sep 7 2004 Alexandre Bustico <bustico@cena.fr>
-- Generation of version 3.6-1
-- update rules file
-
- * Tue Sep 7 2004 Alexandre Bustico <bustico@cena.fr>
-- Generation of version 3.6-1
-
- * Tue Sep 7 2004 Alexandre Bustico <bustico@cena.fr>
-- Generation of version 3.6-1
-- no more libgtkivy, replaced by libgivy, changing redhat/files rules to take change
-
- * Tue Sep 7 2004 Alexandre Bustico <bustico@cena.fr>
-- Generation of version 3.6-1
-
- * Tue Sep 7 2004 Alexandre Bustico <bustico@cena.fr>
-- Generation of version 3.6-1
-
- * Tue Sep 7 2004 Alexandre Bustico <bustico@cena.fr>
-- Generation of version 3.6-2
-
- * Thu Fev 24 2005 Guillaume Vidon <vidon@cena.fr>
-- Generation of version 3.7
-
-';
diff --git a/redhat/files b/redhat/files
deleted file mode 100644
index 3c3fca5..0000000
--- a/redhat/files
+++ /dev/null
@@ -1,15 +0,0 @@
-/usr/bin/ivyprobe
-/usr/lib/libgivy.so
-/usr/lib/libgivy.so.3
-/usr/lib/libgivy.so.3.6
-/usr/lib/libivy.so
-/usr/lib/libivy.so.3
-/usr/lib/libivy.so.3.6
-/usr/lib/libtclivy.so
-/usr/lib/libtclivy.so.3.6
-/usr/man/man1/ivyprobe.1
-/usr/X11R6/bin/ivygtkprobe
-/usr/X11R6/bin/ivyxtprobe
-/usr/X11R6/lib/libxtivy.so
-/usr/X11R6/lib/libxtivy.so.3
-/usr/X11R6/lib/libxtivy.so.3.6
diff --git a/redhat/rules b/redhat/rules
deleted file mode 100644
index d5d7603..0000000
--- a/redhat/rules
+++ /dev/null
@@ -1,21 +0,0 @@
-$Summary = "Ivy, C interface";
-$Name = "ivy-c";
-$Copyright = "CENA";
-$Vendor = "Centre d'Etudes de la Navigation Aerienne";
-$Distribution = "Toccata";
-$Group = "System Environment/Libraries";
-$Url = "http://www.tls.cena.fr/products/ivy";
-$BuildArchitectures = "i586";
-$Description = "This is the C library that implements the
-connection to the Ivy software bus developed at CENA";
-$Requires = "ivy-c = \%{version}-\%{release} " .
- "glibc libpcre libgtk+1.2 libglib2 libxfree86 tcl" ;
-
-
-$FindFiles = "(find \$RPM_BUILD_ROOT -type f -print ; find \$RPM_BUILD_ROOT -type l -print) | sed \"s\@^\$RPM_BUILD_ROOT\@\@g\" | sort | join redhat/files - ";
-
-$Install = "rm -Rf \$RPM_BUILD_ROOT
-cd src
-make PREFIX=\$RPM_BUILD_ROOT install
-cd ..
-(find \$RPM_BUILD_ROOT -type f -print; find \$RPM_BUILD_ROOT -type l -print) | sed \"s\@^\$RPM_BUILD_ROOT\@\@g\" | grep -v perllocal.pod | grep -v .packlist > $Name-\%{version}-filelist";
diff --git a/redhat/rules-devel b/redhat/rules-devel
deleted file mode 100644
index 04bfa0e..0000000
--- a/redhat/rules-devel
+++ /dev/null
@@ -1,17 +0,0 @@
-$Summary = "Ivy, development files for the C interface";
-$Name = "ivy-c-devel";
-$Copyright = "CENA";
-$Vendor = "Centre d'Etudes de la Navigation Aerienne";
-$Distribution = "Toccata";
-$Group = "Development/Libraries";
-$Url = "http://www.tls.cena.fr/divisions/PII/";
-$BuildArchitectures = "i586";
-$Requires = "ivy-c = \%{version}-\%{release} " .
- "glibc-devel libpcre0-devel libgtk+1.2-devel libglib2-devel libxfree86-devel tcl-devel" ;
-
-undef $FindFiles;
-undef $Install ;
-
-$Description = "This contains the headers and static libraries necessary for
-developping and debugging applications that use the Ivy C library.";
-
diff --git a/src/getopt.c b/src/getopt.c
new file mode 100755
index 0000000..36a9bc1
--- /dev/null
+++ b/src/getopt.c
@@ -0,0 +1,76 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+int optind = 1;
+char *optarg = (char *)NULL;
+
+int getopt (int argc, char **argv, char *optstring)
+{
+ int cur_option; /* Current option */
+ char *cp; /* Character pointer */
+ static int GetOptionPosition = 1;
+
+ if (GetOptionPosition == 1)
+ {
+
+/* Check for out of range, correct start character and not single */
+
+ if ((optind >= argc) || (*argv[optind] != '-') || !argv[optind][1])
+ return EOF;
+
+ if (!strcmp (argv[optind], "--"))
+ return EOF;
+ }
+
+/* Get the current character from the current argument vector */
+
+ cur_option = argv[optind][GetOptionPosition];
+
+/* Validate it */
+
+ if ((cur_option == ':') ||
+ ((cp = strchr (optstring, cur_option)) == (char *)NULL))
+ {
+
+/* Move to the next offset */
+
+ if (!argv[optind][++GetOptionPosition])
+ {
+ optind++;
+ GetOptionPosition = 1;
+ }
+
+ return '?';
+ }
+
+/* Parameters following ? */
+
+ optarg = (char *)NULL;
+
+ if (*(++cp) == ':')
+ {
+ if (argv[optind][GetOptionPosition + 1])
+ optarg = &argv[optind++][GetOptionPosition + 1];
+
+ else if (++optind >= argc)
+ {
+ optarg = (char *)NULL;
+ GetOptionPosition = 1;
+ return '?';
+ }
+
+ else
+ optarg = argv[optind++];
+
+ GetOptionPosition = 1;
+ }
+
+ else if (!argv[optind][++GetOptionPosition])
+ {
+ GetOptionPosition = 1;
+ optind++;
+ }
+
+ return cur_option;
+}
diff --git a/src/getopt.h b/src/getopt.h
new file mode 100755
index 0000000..d52543f
--- /dev/null
+++ b/src/getopt.h
@@ -0,0 +1,16 @@
+#ifndef __GETOPT_H_
+#define __GETOPT_H_
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+extern int optind ;
+extern char *optarg ;
+extern int getopt (int argc, char **argv, char *optstring) ;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/src/ivybind.c b/src/ivybind.c
new file mode 100644
index 0000000..237ee78
--- /dev/null
+++ b/src/ivybind.c
@@ -0,0 +1,322 @@
+/*
+ * Ivy, C interface
+ *
+ * Copyright (C) 1997-2000
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Bind syntax for extracting message comtent
+ * using regexp or other
+ *
+ * Authors: François-Régis Colin <fcolin@cena.fr>
+ *
+ * $Id$
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+/* Module de gestion de la syntaxe des messages Ivy */
+#include <stdio.h>
+#include <sys/types.h>
+#include <time.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <string.h>
+#include <stdarg.h>
+
+#ifdef WIN32
+#include <crtdbg.h>
+#endif
+
+
+#ifdef USE_PCRE_REGEX
+#define OVECSIZE 60 /* must be multiple of 3, for regexp return */
+#include <pcre.h>
+#else
+#define MAX_MSG_FIELDS 200
+#include <regex.h>
+#endif
+
+#include "list.h"
+#include "hash.h"
+#include "ivybind.h"
+
+static int err_offset;
+
+#ifdef USE_PCRE_REGEX
+ static const char *err_buf;
+#else
+ static char err_buf[4096];
+#endif
+
+struct _binding {
+ IvyBindingType type;
+ const char *msgname; /* msg tag name first word of message */
+ char **msgargs; /* list of msg argument name */
+ IvyArgument args; /* result */
+#ifdef USE_PCRE_REGEX
+ pcre *regexp;
+ pcre_extra *inspect;
+ int nb_match;
+ int ovector[OVECSIZE];
+#else
+ regex_t regexp; /* la regexp sous forme machine */
+ regmatch_t match[MAX_MSG_FIELDS+1]; /* resultat du match */
+#endif
+ };
+
+
+/* classes de messages emis par l'application utilise pour le filtrage */
+static int messages_classes_count = 0;
+static const char **messages_classes = 0;
+
+
+/* stokage du message parse avant l'execution des regles de binding simple */
+static char *current_msg = NULL;
+static char *msgtag;
+static HASHTABLE msg_args_values = NULL;
+
+static IvyBinding IvyBindingCompileSimple( IvyBindingType typ, const char * expression )
+{
+ int nb_arg= 0;
+ char *argname;
+ char **argv;
+ char *expr;
+ IvyBinding bind=0;
+
+ expr = strdup( expression ); //Allocate a new buffer of separated token
+ /* count nb args */
+ argname = expr;
+ while ( *argname )
+ {
+ if ( *argname++ == ' ' ) nb_arg++;
+ }
+
+ bind = (IvyBinding)malloc( sizeof( struct _binding ));
+ memset( bind, 0, sizeof(*bind ) );
+ bind->type = IvyBindSimple;
+ bind->msgname = strtok( expr, " ");
+ bind->msgargs = malloc ( sizeof( char* ) * ( nb_arg + 1) );
+ argv = bind->msgargs;
+ while ( (argname = strtok( NULL, " ")) )
+ *argv++ = argname;
+ *argv++ = argname; /* end with NULL */
+ return bind;
+}
+static IvyBinding IvyBindingCompileRegexp( IvyBindingType typ, const char * expression )
+{
+ IvyBinding bind=0;
+#ifdef USE_PCRE_REGEX
+ pcre *regexp;
+ regexp = pcre_compile(expression, PCRE_OPT,&err_buf,&err_offset,NULL);
+ if ( regexp != NULL )
+ {
+ bind = (IvyBinding)malloc( sizeof( struct _binding ));
+ memset( bind, 0, sizeof(*bind ) );
+ bind->regexp = regexp;
+ bind->type = IvyBindRegexp;
+ bind->inspect = pcre_study(regexp,0,&err_buf);
+ if (err_buf!=NULL)
+ {
+ printf("Error studying %s, message: %s\n",expression,err_buf);
+ }
+ }
+ else
+ {
+ printf("Error compiling '%s', %s\n", expression, err_buf);
+ }
+#else
+ regex_t regexp;
+ int reg;
+ reg = regcomp(&regexp, expression, REGCOMP_OPT|REG_EXTENDED);
+ if ( reg == 0 )
+ {
+ bind = (IvyBinding)malloc( sizeof( struct _binding ));
+ memset( bind, 0, sizeof(*bind ) );
+ bind->regexp = regexp;
+ bind->next = NULL;
+ }
+ else
+ {
+ regerror (reg, &regexp, err_buf, sizeof(err_buf) );
+ err_offset = 0; // TODO unkown offset error
+ printf("Error compiling '%s', %s\n", expression, err_buf);
+ }
+#endif
+ return bind;
+}
+IvyBinding IvyBindingCompile( IvyBindingType typ, const char * expression )
+{
+ if ( typ == IvyBindRegexp )
+ return IvyBindingCompileRegexp( typ, expression);
+ else
+ return IvyBindingCompileSimple( typ, expression);
+}
+void IvyBindingGetCompileError( int *offset, const char **errmessage )
+{
+ *offset = err_offset;
+ *errmessage = err_buf;
+}
+void IvyBindingFree( IvyBinding bind )
+{
+#ifdef USE_PCRE_REGEX
+ if (bind->inspect!=NULL) pcre_free(bind->inspect);
+ pcre_free(bind->regexp);
+#else
+#endif
+ if (bind->msgname)
+ free ( bind->msgname );
+ if (bind->msgargs)
+ free ( bind->msgargs );
+ free ( bind );
+}
+int IvyBindingExecRegexp( IvyBinding bind, const char * message )
+{
+ int nb_match = 0;
+#ifdef USE_PCRE_REGEX
+
+ nb_match = pcre_exec(
+ bind->regexp,
+ bind->inspect,
+ message,
+ strlen(message),
+ 0, /* debut */
+ 0, /* no other regexp option */
+ bind->ovector,
+ OVECSIZE);
+ if (nb_match<1) return 0; /* no match */
+ bind->nb_match = nb_match;
+ nb_match--; // firts arg wall string ???
+
+#else
+ memset( bind->match, -1, sizeof(bind->match )); /* work around bug !!!*/
+ nb_match = regexec (&bind->regexp, message, MAX_MSG_FIELDS, bind->match, 0)
+ if (nb_match == REG_NOMATCH)
+ return 0;
+ for ( index = 1; index < MAX_MSG_FIELDS; index++ )
+ {
+ if ( bind->match[i].rm_so != -1 )
+ nb_match++;
+ }
+#endif
+ return nb_match;
+}
+int IvyBindingExecSimple( IvyBinding bind, const char * message )
+{
+ char **msg_args;
+ if ( strcmp( bind->msgname, msgtag ) != 0 )
+ return 0;
+ msg_args = bind->msgargs;
+ bind->args = IvyArgumentNew( 0,NULL );
+ while( *msg_args )
+ {
+ char *value;
+ value = hash_lookup(msg_args_values, (HASHKEYTYPE)*msg_args++);
+ if ( !value ) value = ""; /* TODO should we report matching ??? */
+ IvyAddChildValue( bind->args, strlen( value ), value);
+ }
+ return 1;
+}
+int IvyBindingExec( IvyBinding bind, const char * message )
+{
+ if ( bind->type == IvyBindRegexp )
+ return IvyBindingExecRegexp( bind, message);
+ else
+ return IvyBindingExecSimple( bind, message);
+}
+static IvyArgument IvyBindingMatchSimple( IvyBinding bind, const char *message)
+{
+ return bind->args;
+}
+static IvyArgument IvyBindingMatchRegexp( IvyBinding bind, const char *message)
+{
+ int index=1;// firts arg wall string ???
+ int arglen;
+ const void* arg;
+ IvyArgument args;
+ args = IvyArgumentNew( 0,NULL );
+
+#ifdef USE_PCRE_REGEX
+ while ( index<bind->nb_match ) {
+ arglen = bind->ovector[2*index+1]- bind->ovector[2*index];
+ arg = message + bind->ovector[2*index];
+ index++;
+#else /* we don't USE_PCRE_REGEX */
+ for ( index = 1; index < MAX_MSG_FIELDS; index++ )
+ {
+ regmatch_t* p;
+
+ p = &bind->match[index];
+ if ( p->rm_so != -1 ) {
+ arglen = p->rm_eo - p->rm_so;
+ arg = message + p->rm_so;
+ } else { // ARG VIDE
+ arglen = 0;
+ arg = NULL;
+ }
+#endif // USE_PCRE_REGEX
+ IvyAddChildValue( args, arglen, arg );
+ }
+ return args;
+}
+IvyArgument IvyBindingMatch( IvyBinding bind, const char *message)
+{
+ if ( bind->type == IvyBindRegexp )
+ return IvyBindingMatchRegexp( bind, message);
+ else
+ return IvyBindingMatchSimple( bind, message);
+}
+
+//filter Expression Bind
+void IvyBindingSetFilter( int argc, const char **argv)
+{
+ messages_classes_count = argc;
+ messages_classes = argv;
+}
+void IvyBindingParseMessage( const char *msg )
+{
+ char *arg;
+ if ( current_msg ) free( current_msg );
+ if ( msg_args_values ) hash_destroy( msg_args_values );
+ current_msg = strdup( msg );
+ msg_args_values = hash_create( 256, TRUE );
+ msgtag = strtok( current_msg, " " );
+ while( (arg = strtok( NULL, " =" )) )
+ {
+ char *val = strtok( NULL, " =");
+ if ( arg && val )
+ hash_addstring( msg_args_values, arg, val );
+ }
+}
+int IvyBindingFilter(IvyBindingType typ, int len, const char *exp)
+{
+ /* TODO check args limits !!!*/
+ int i;
+ /* accepte tout par default */
+ int regexp_ok = 1;
+ // TODO simplify test 3 conditions
+ if ( typ == IvyBindRegexp )
+ {
+ if ( *exp =='^' && messages_classes_count !=0 )
+ {
+ regexp_ok = 0;
+ for ( i = 0 ; i < messages_classes_count; i++ )
+ {
+ if (strncmp( messages_classes[i], exp+1, strlen( messages_classes[i] )) == 0)
+ return 1;
+ }
+ }
+ }
+ else
+ {
+ if ( messages_classes_count !=0 )
+ {
+ regexp_ok = 0;
+ for ( i = 0 ; i < messages_classes_count; i++ )
+ {
+ if (strncmp( messages_classes[i], exp, strlen( messages_classes[i] )) == 0)
+ return 1;
+ }
+ }
+ }
+ return regexp_ok;
+} \ No newline at end of file
diff --git a/src/ivybind.h b/src/ivybind.h
new file mode 100644
index 0000000..9846d3f
--- /dev/null
+++ b/src/ivybind.h
@@ -0,0 +1,31 @@
+/*
+ * Ivy, C interface
+ *
+ * Copyright (C) 1997-2000
+ * Centre d'Études de la Navigation Aérienne
+ *
+ * Bind syntax for extracting message comtent
+ * using regexp or other
+ *
+ * Authors: François-Régis Colin <fcolin@cena.fr>
+ *
+ * $Id$
+ *
+ * Please refer to file version.h for the
+ * copyright notice regarding this software
+ */
+#include "ivyargument.h"
+
+/* Module de gestion de la syntaxe des messages Ivy */
+
+typedef struct _binding *IvyBinding;
+
+typedef enum { IvyBindRegexp, IvyBindSimple } IvyBindingType;
+void IvyBindingParseMessage( const char *msg );
+void IvyBindingSetFilter( int argc, const char ** argv );
+int IvyBindingFilter( IvyBindingType typ, int len, const char *exp );
+IvyBinding IvyBindingCompile( IvyBindingType typ, const char * expression );
+void IvyBindingGetCompileError( int *erroffset, const char **errmessage );
+void IvyBindingFree( IvyBinding bind );
+int IvyBindingExec( IvyBinding bind, const char * message );
+IvyArgument IvyBindingMatch( IvyBinding bind, const char *message );