root/trunk/src/renetcolSender.c @ 2

Revision 2, 3.1 KB (checked in by andreu, 17 years ago)

First RENETCOL CVS Integration

  • Property svn:eol-style set to native
Line 
1/*
2 * File: renetcolSender.c
3 *
4 * Authors: ANDREU François-Xavier
5 *
6 * Copyright (C) 2005 GIP RENATER
7 */
8
9/*  This file is part of renetcol.
10 *
11 *  renetcol is free software; you can redistribute it and/or modify
12 *  it under the terms of the GNU General Public License as published by
13 *  the Free Software Foundation; either version 2 of the License, or
14 *  (at your option) any later version.
15 *
16 *  renetcol is distributed in the hope that it will be useful,
17 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 *  GNU General Public License for more details.
20 *
21 *  You should have received a copy of the GNU General Public License
22 *  along with renetcol; if not, write to the Free Software
23 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 */
25
26#include "renetcolSender.h"
27
28key_t myKey = 0;
29int myQueue = 0;
30msgType myMsg;
31long type;
32RulesPtr rulesListPtr;
33char *rulesFileName;
34
35int i=0;
36int j=0;
37unsigned char *myText;
38unsigned char buffer2[2];
39unsigned char buffer4[4];
40unsigned short nb=0;
41unsigned short typeMsg = 0;
42RulesPtr tmp = NULL;
43
44/*
45 * Main
46 * ----
47 */
48int 
49main (int argc, char *argv[])
50{
51  int s=0;
52  unsigned short rulesID = 0;
53
54  if ( argc != 4) {
55    fprintf (stderr,
56             "%s: Usage: %s <key> <msg type> <rules file>\n exp: %s colnetv9 1 rules.txt\n",
57             argv[0], argv[0], argv[0]);
58    exit(1);
59  }
60
61  openlog(argv[0], LOG_PID, LOG_USER);
62  rulesFileName = (char *) malloc((strlen(argv[3])+1) * sizeof(char));
63  strcpy (rulesFileName, argv[3]);
64  rulesListPtr = NULL;
65  rulesListPtr = getRules(rulesListPtr, rulesFileName);
66  /* we delete rules which are not type socket */
67  tmp = rulesListPtr;
68  for ( ; tmp->next; tmp=tmp->next) {
69    if (tmp->type != 2) {
70      rulesListPtr = delRule(tmp, rulesListPtr);
71    }
72  }
73  tmp = NULL;
74  printRule(rulesListPtr);
75
76  /* get IPC messages queue */
77  if ((myKey = ftok(argv[1], 0))== -1){
78    perror("ftok");
79    exit(1);
80  }
81  if ((myQueue = msgget(myKey, 0)) == -1){
82    perror("msgget");
83    exit(1);
84  }
85  if (sscanf (argv[2], "%ld", &type) != 1){
86    fprintf(stderr, "Invalid type\n");
87    exit(1);
88  }
89  while (1) {
90    i=0;
91    myText = msgRcv(myQueue, &myMsg, type);
92    buffer2[0]= *(myText+i); i++;
93    buffer2[1]= *(myText+i); i++;
94    typeMsg = *((unsigned short *)&buffer2);
95    if (1==typeMsg){
96      /* we send the template definition to all the known destination */
97      tmp = rulesListPtr;
98      for ( ; tmp; tmp=tmp->next) {
99        s = sendMessage(tmp->host->sockId, myText, sizeof(myMsg.text),
100                        tmp->host->hostAddressPtr);
101      }
102    } else if (11==*((unsigned short*)&buffer2)){
103      buffer2[0]= *(myText+i); i++;
104      buffer2[1]= *(myText+i); i++;
105      rulesID = *((unsigned short *)&buffer2);
106      /* here we send the flow to the correct remote client */
107      tmp = rulesListPtr;
108      for ( ; tmp; tmp=tmp->next) { /* FIXME while */
109        if (tmp->id == rulesID){
110          s = sendMessage(tmp->host->sockId, myText, sizeof(myMsg.text),
111                          tmp->host->hostAddressPtr);
112        }
113      }
114    } else {
115      syslog(LOG_INFO, "Msg type undefined ??");
116    }
117    i=0;
118  }
119}
Note: See TracBrowser for help on using the browser.