Ejemplo n.º 1
0
void InitializeStringRouter(
  Environment *theEnv)
  {
   AllocateEnvironmentData(theEnv,STRING_ROUTER_DATA,sizeof(struct stringRouterData),DeallocateStringRouterData);

   AddRouter(theEnv,"string",0,QueryStringCallback,WriteStringCallback,ReadStringCallback,UnreadStringCallback,NULL,NULL);
   AddRouter(theEnv,"stringBuilder",0,QueryStringBuilderCallback,WriteStringBuilderCallback,NULL,NULL,NULL,NULL);
  }
Ejemplo n.º 2
0
int InitializeStdCLIPSRouters(void)
{
	struct WebCLIPSRouter *pWCRouter;

	//Create a linked list of WebCLIPS routers
	g_pStdWebCLIPSRouter = (struct WebCLIPSRouter *)calloc(1, sizeof(struct WebCLIPSRouter));
	pWCRouter = g_pStdWebCLIPSRouter;

	// stdout
	//Populate this router for stdout
	if(CreateStdWebCLIPSRouter(pWCRouter, "stdout") == FALSE)
	{
		ProcessErrorCode("ROUT0005", "stdout", 'n', 'n');
		return(-1);
	}
	pWCRouter->pNextRouter = (struct WebCLIPSRouter *)calloc(1, sizeof(struct WebCLIPSRouter));
	pWCRouter = pWCRouter->pNextRouter;

	// wdialog
	//Populate this router for wdialog
	if(CreateStdWebCLIPSRouter(pWCRouter, "wdialog") == FALSE)
	{
		ProcessErrorCode("ROUT0005", "wdialog", 'n', 'n');
		return(-1);
	}
	pWCRouter->pNextRouter = (struct WebCLIPSRouter *)calloc(1, sizeof(struct WebCLIPSRouter));
	pWCRouter = pWCRouter->pNextRouter;

	// wwarning
	//Populate this router for wwarning
	if(CreateStdWebCLIPSRouter(pWCRouter, "wwarning") == FALSE)
	{
		ProcessErrorCode("ROUT0005", "wwarning", 'n', 'n');
		return(-1);
	}
	pWCRouter->pNextRouter = (struct WebCLIPSRouter *)calloc(1, sizeof(struct WebCLIPSRouter));
	pWCRouter = pWCRouter->pNextRouter;

	// werror
	//Populate this router for werror
	if(CreateStdWebCLIPSRouter(pWCRouter, "werror") == FALSE)
	{
		ProcessErrorCode("ROUT0005", "werror", 'n', 'n');
		return(-1);
	}

	//Add a router to catch output from the 'standard' CLIPS routers
	if(AddRouter(STANDARD_ROUTER, 20, StdWCQuery, StdWCPrint, NULL, NULL, StdWCExit) == 0)
	{
		ProcessErrorCode("ROUT0005", "Standard WebCLIPS Routers", 'n', 'n');
		return(-1);
	}

	return(0);
}
Ejemplo n.º 3
0
bool DribbleOn(
  Environment *theEnv,
  const char *fileName)
  {
   /*==============================*/
   /* If a dribble file is already */
   /* open, then close it.         */
   /*==============================*/

   if (FileCommandData(theEnv)->DribbleFP != NULL)
     { DribbleOff(theEnv); }

   /*========================*/
   /* Open the dribble file. */
   /*========================*/

   FileCommandData(theEnv)->DribbleFP = GenOpen(theEnv,fileName,"w");
   if (FileCommandData(theEnv)->DribbleFP == NULL)
     {
      OpenErrorMessage(theEnv,"dribble-on",fileName);
      return false;
     }

   /*============================*/
   /* Create the dribble router. */
   /*============================*/

   AddRouter(theEnv,"dribble",40,
             QueryDribbleCallback,WriteDribbleCallback,
             ReadDribbleCallback,UnreadDribbleCallback,
             ExitDribbleCallback,NULL);

   FileCommandData(theEnv)->DribbleCurrentPosition = 0;

   /*================================================*/
   /* Call the dribble status function. This is used */
   /* by some of the machine specific interfaces to  */
   /* do things such as changing the wording of menu */
   /* items from "Turn Dribble On..." to             */
   /* "Turn Dribble Off..."                          */
   /*================================================*/

   if (FileCommandData(theEnv)->DribbleStatusFunction != NULL)
     { (*FileCommandData(theEnv)->DribbleStatusFunction)(theEnv,true); }

   /*=====================================*/
   /* Return true to indicate the dribble */
   /* file was successfully opened.       */
   /*=====================================*/

   return true;
  }
Ejemplo n.º 4
0
globle void WatchFunctionDefinitions()
  {
#if ! RUN_TIME
   DefineFunction2("watch",   'v', PTIF WatchCommand,   "WatchCommand", "1**w");
   DefineFunction2("unwatch", 'v', PTIF UnwatchCommand, "UnwatchCommand", "1**w");
   DefineFunction2("get-watch-item", 'b', PTIF GetWatchItemCommand,   "GetWatchItemCommand", "11w");
   DefineFunction2("list-watch-items", 'v', PTIF ListWatchItemsCommand,
                   "ListWatchItemsCommand", "0**w");
#endif

   AddRouter(WTRACE,1000,RecognizeWatchRouters,CaptureWatchPrints,NULL,NULL,NULL);
   DeactivateRouter(WTRACE);
  }
Ejemplo n.º 5
0
void AnalyzeArp(struct iovec *packet_ring, char **argv)
{
    struct ether_header     *eth;
    struct  ether_arp       *arptr;

    eth = (struct ether_header *)packet_ring->iov_base;

    switch(ntohs(eth -> ether_type))
    {
        case ETHERTYPE_ARP:
            arptr = (struct ether_arp *)((unsigned char *)eth+sizeof(*eth));
            ISlist_send(packet_ring); //send arp packet to any child
                                     //waiting
            //arp reply
            if ( ntohs(arptr -> ea_hdr.ar_op) == ARPOP_REPLY )
            {
                //pthread_mutex_lock(&cmutex);
                if (SearchClientMac(arptr -> arp_sha) == FALSE &&
                        memcmp(src_ip, arptr -> arp_spa, 4) != 0)
                {
                    if ( GetRouter() == NULL && memcmp(router_ip, arptr -> arp_spa, 4) == 0 )
                    {
                        AddRouter(arptr -> arp_sha, arptr -> arp_spa);
                        //ISlist_send(packet_ring);
                        //pthread_cond_signal(&cvar);
                    }
                    else
                    if ( memcmp(router_ip, arptr -> arp_spa, 4) != 0 )
                    {
                        AddClient(arptr -> arp_sha, arptr -> arp_spa);
                        //ISlist_send(packet_ring);
                       //pthread_cond_signal(&cvar);
                    }
                }
                //pthread_mutex_unlock(&cmutex);
            }
            PrintClients();
            PrintRouter();
            break;
        default:
            fprintf(stderr, "packet is not arp!!\n");
            break;
    }
}
Ejemplo n.º 6
0
bool OpenStringBatch(
  Environment *theEnv,
  const char *stringName,
  const char *theString,
  bool placeAtEnd)
  {
   if (OpenStringSource(theEnv,stringName,theString,0) == false)
     { return false; }

   if (FileCommandData(theEnv)->TopOfBatchList == NULL)
     {
      AddRouter(theEnv,"batch", 20,
                QueryBatchCallback,NULL,
                ReadBatchCallback,UnreadBatchCallback,
                ExitBatchCallback,NULL);
     }

   AddBatch(theEnv,placeAtEnd,NULL,stringName,STRING_BATCH,theString,NULL);

   return true;
  }
Ejemplo n.º 7
0
globle int CheckSyntax(
  char *theString,
  DATA_OBJECT_PTR returnValue)
  {
   char *name;
   struct token theToken;
   struct expr *top;
   short rv;

   /*==============================*/
   /* Set the default return value */
   /* (TRUE for problems found).   */
   /*==============================*/

   SetpType(returnValue,SYMBOL);
   SetpValue(returnValue,TrueSymbol);

   /*===========================================*/
   /* Create a string source router so that the */
   /* string can be used as an input source.    */
   /*===========================================*/

   if (OpenStringSource("check-syntax",theString,0) == 0)
     { return(TRUE); }

   /*=================================*/
   /* Only expressions and constructs */
   /* can have their syntax checked.  */
   /*=================================*/

   GetToken("check-syntax",&theToken);

   if (theToken.type != LPAREN)
     {
      CloseStringSource("check-syntax");
      SetpValue(returnValue,AddSymbol("MISSING-LEFT-PARENTHESIS"));
      return(TRUE);
     }

   /*========================================*/
   /* The next token should be the construct */
   /* type or function name.                 */
   /*========================================*/

   GetToken("check-syntax",&theToken);
   if (theToken.type != SYMBOL)
     {
      CloseStringSource("check-syntax");
      SetpValue(returnValue,AddSymbol("EXPECTED-SYMBOL-AFTER-LEFT-PARENTHESIS"));
      return(TRUE);
     }

   name = ValueToString(theToken.value);

   /*==============================================*/
   /* Set up a router to capture the error output. */
   /*==============================================*/

   AddRouter("error-capture",40,
              FindErrorCapture, PrintErrorCapture,
              NULL, NULL, NULL);

   /*================================*/
   /* Determine if it's a construct. */
   /*================================*/

   if (FindConstruct(name))
     {
      CheckSyntaxMode = TRUE;
      rv = (short) ParseConstruct(name,"check-syntax");
      GetToken("check-syntax",&theToken);
      CheckSyntaxMode = FALSE;

      if (rv)
        {
         PrintRouter(WERROR,"\nERROR:\n");
         PrintInChunks(WERROR,GetPPBuffer());
         PrintRouter(WERROR,"\n");
        }

      DestroyPPBuffer();

      CloseStringSource("check-syntax");

      if ((rv != FALSE) || (WarningString != NULL))
        {
         SetErrorCaptureValues(returnValue);
         DeactivateErrorCapture();
         return(TRUE);
        }

      if (theToken.type != STOP)
        {
         SetpValue(returnValue,AddSymbol("EXTRANEOUS-INPUT-AFTER-LAST-PARENTHESIS"));
         DeactivateErrorCapture();
         return(TRUE);
        }

      SetpType(returnValue,SYMBOL);
      SetpValue(returnValue,FalseSymbol);
      DeactivateErrorCapture();
      return(FALSE);
     }

   /*=======================*/
   /* Parse the expression. */
   /*=======================*/

   top = Function2Parse("check-syntax",name);
   GetToken("check-syntax",&theToken);
   ClearParsedBindNames();
   CloseStringSource("check-syntax");

   if (top == NULL)
     {
      SetErrorCaptureValues(returnValue);
      DeactivateErrorCapture();
      return(TRUE);
     }

   if (theToken.type != STOP)
     {
      SetpValue(returnValue,AddSymbol("EXTRANEOUS-INPUT-AFTER-LAST-PARENTHESIS"));
      DeactivateErrorCapture();
      ReturnExpression(top);
      return(TRUE);
     }

   DeactivateErrorCapture();

   ReturnExpression(top);
   SetpType(returnValue,SYMBOL);
   SetpValue(returnValue,FalseSymbol);
   return(FALSE);
  }
Ejemplo n.º 8
0
bool OpenBatch(
  Environment *theEnv,
  const char *fileName,
  bool placeAtEnd)
  {
   FILE *theFile;

   /*======================*/
   /* Open the batch file. */
   /*======================*/

   theFile = GenOpen(theEnv,fileName,"r");

   if (theFile == NULL)
     {
      OpenErrorMessage(theEnv,"batch",fileName);
      return false;
     }

   /*============================*/
   /* Create the batch router if */
   /* it doesn't already exist.  */
   /*============================*/

   if (FileCommandData(theEnv)->TopOfBatchList == NULL)
     {
      AddRouter(theEnv,"batch",20,QueryBatchCallback,NULL,
                ReadBatchCallback,UnreadBatchCallback,
                ExitBatchCallback,NULL);
     }

   /*===============================================================*/
   /* If a batch file is already open, save its current line count. */
   /*===============================================================*/

   if (FileCommandData(theEnv)->TopOfBatchList != NULL)
     { FileCommandData(theEnv)->TopOfBatchList->lineNumber = GetLineCount(theEnv); }

#if (! RUN_TIME) && (! BLOAD_ONLY)

   /*========================================================================*/
   /* If this is the first batch file, remember the prior parsing file name. */
   /*========================================================================*/

   if (FileCommandData(theEnv)->TopOfBatchList == NULL)
     { FileCommandData(theEnv)->batchPriorParsingFile = CopyString(theEnv,GetParsingFileName(theEnv)); }

   /*=======================================================*/
   /* Create the error capture router if it does not exist. */
   /*=======================================================*/

   SetParsingFileName(theEnv,fileName);
   SetLineCount(theEnv,0);

   CreateErrorCaptureRouter(theEnv);
#endif

   /*====================================*/
   /* Add the newly opened batch file to */
   /* the list of batch files opened.    */
   /*====================================*/

   AddBatch(theEnv,placeAtEnd,theFile,NULL,FILE_BATCH,NULL,fileName);

   /*===================================*/
   /* Return true to indicate the batch */
   /* file was successfully opened.     */
   /*===================================*/

   return true;
  }
Ejemplo n.º 9
0
//Setup all routers. Parse through the WebCLIPS.INI and open
//	all required routers.
int	SetupRouters(void)
{
	char szRouterList[MAX_SETTINGS_LINE_LEN], *p, szEchoEntry[MAX_ROUTER_NAME_LEN + 4 + 1]; //<router> "Echo" = 4
	char szRouterFile[MAXNAMLEN + 1];
	int iMaxPriority = 40;
	char szRouterTemp[MAX_ROUTER_NAME_LEN + 1], szRouterTemp2[MAX_ROUTER_NAME_LEN + 1];
	struct WebCLIPSRouter *pWCRouter;
	int bSetRouterResult, bResult;

	//Get the list of routers
	GetWebCLIPSSettings(
		g_szScreenName,		// section name
		"RouterList",		// entry name
		"",				// default value
		szRouterList,		// return value
		sizeof(szRouterList),	// max length
		g_szWebCLIPSINI
        );

	//Set up the standard CLIPS routers : stdout, wdialog, wwarning, werror
	if(InitializeStdCLIPSRouters() != 0)
		return(-1);

	//If no additional routers requested then exit
	if(strlen(szRouterList) == 0)
	{
		return(0);
	}

	//Search for '|'. Set each router name in the string array
	p = strtok(szRouterList, "|");
	g_pUDFWebCLIPSRouter = (struct WebCLIPSRouter *)calloc(1, sizeof(struct WebCLIPSRouter));
	pWCRouter = g_pUDFWebCLIPSRouter;
	while(p)
	{
		strcpy(szRouterTemp2, p);
		Trim(szRouterTemp2, szRouterTemp);

		strcpy(szEchoEntry, szRouterTemp);
		strcat(szEchoEntry, "Echo");

		//Get <router>Echo entry
		GetWebCLIPSSettings(
			g_szScreenName,			// section name
			szEchoEntry,			// entry name
			"",					// default value
			szRouterFile,			// return value
			sizeof(szRouterFile),		// max length
			g_szWebCLIPSINI
			);

		//If router is set to 'no' or is absent then get the next router. Also, if
		//	there is a request for stdout, wdialog, wwarning, werror to be directed
		//	to the screen, then ignore it. These will be handled by automatically.
		//
		//	Also, ignore requests to 'dribble' to screen. The reason is that because
		//	there are no </form> tags any facts that are asserted from a screen actually
		//	get asserted TWICE..this is undesirable
		if(strcasecmp(szRouterFile, "no") == 0 || strlen(szRouterFile) == 0 ||
		  (strcasecmp(szRouterFile, "screen") == 0 && 
			(strcasecmp(szRouterTemp, "stdout") == 0 ||
			 strcasecmp(szRouterTemp, "dribble") == 0 ||
			 strcasecmp(szRouterTemp, "wdialog") == 0 ||
			 strcasecmp(szRouterTemp, "wwarning") == 0||
			 strcasecmp(szRouterTemp, "werror") == 0)))
		{
			p = strtok(NULL, "|");
			continue;
		}

		//Set the name of the router.
		pWCRouter->szRouter = (char *)malloc(strlen(szRouterTemp) + 1);
		if (!pWCRouter->szRouter)
		{
			ProcessErrorCode("ROUT0003", szRouterTemp, 'n', 'n');
			return(-1);
		}
		strcpy(pWCRouter->szRouter, szRouterTemp);

		//If router is to be directed to the screen, then get a
		//	temporary file name else use the entry in WebCLIPS.INI
		if(strcasecmp(szRouterFile, "screen") == 0)
		{
			pWCRouter->cDestination = WCRouter_ToScreen;

			//Generate temporary filename.
			bResult = GenerateTempFileName(&pWCRouter->szRouterFileName);
			if(bResult == FALSE)
			{
				ProcessErrorCode("ROUT0001", szRouterFile, 'n', 'n');
				return(-1);
			}
		}
		else
		{
			pWCRouter->cDestination = WCRouter_ToFile;

			pWCRouter->szRouterFileName = (char *)malloc(strlen(szRouterFile) + 1);
			if (!pWCRouter->szRouterFileName)
			{
				ProcessErrorCode("ROUT0003", szRouterFile, 'n', 'n');
				return(-1);
			}
			strcpy(pWCRouter->szRouterFileName, szRouterFile);
		}


		//Router request for dribble.
		if(strcasecmp(szRouterTemp, "dribble") == 0)
		{
			bSetRouterResult = DribbleOn(pWCRouter->szRouterFileName);
			if(bSetRouterResult == FALSE) //Error, process error and end program
			{
				ProcessErrorCode("DRBL0002", szRouterFile, 'n', 'n');
				return(-1);
			}
			pWCRouter->cRouterType = WCRouter_Dribble;
		}
		else
		{
			if((pWCRouter->fp = fopen(pWCRouter->szRouterFileName, "wb")) == NULL)
			{
				ProcessErrorCode("ROUT0003", pWCRouter->szRouterFileName, 'n', 'n');
				return(FALSE);
			}
			pWCRouter->cRouterType = WCRouter_Userdefined;
		}

		//System-defined router. Set priority appropriately
		if(strcasecmp(szRouterTemp, "wclips") == 0  || strcasecmp(szRouterTemp, "wtrace") == 0 ||
		   strcasecmp(szRouterTemp, "wagenda") == 0 || strcasecmp(szRouterTemp, "stdout") == 0 ||
		   strcasecmp(szRouterTemp, "wdialog") == 0 || strcasecmp(szRouterTemp, "wwarning") == 0 ||
		   strcasecmp(szRouterTemp, "werror") == 0  || strcasecmp(szRouterTemp, "wdisplay") == 0)
		   iMaxPriority = 20;

		//Get next router
		p = &p[strlen(p) + 1];
		p = strtok(p, "|");

		//If there is another router to process, then allocate space for it
		if(p != NULL)
		{
			pWCRouter->pNextRouter = (struct WebCLIPSRouter *)calloc(1, sizeof(struct WebCLIPSRouter));
			pWCRouter = pWCRouter->pNextRouter;
		}

	} // while(p)

	if(AddRouter(USERDEFINED_ROUTER, iMaxPriority, UDFWCQuery, UDFWCPrint, NULL, NULL, UDFWCExit) == 0)
	{
		ProcessErrorCode("ROUT0005", "User-Defined WebCLIPS Routers", 'n', 'n');
		return(-1);
	}

	return(0);
}