⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slp_filter_y.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 3 页
字号:
  goto yynewstate;/*-----------------------------------------------------------.| yydefault -- do the default action for the current state.  |`-----------------------------------------------------------*/yydefault:  yyn = yydefact[yystate];  if (yyn == 0)    goto yyerrlab;  goto yyreduce;/*-----------------------------.| yyreduce -- Do a reduction.  |`-----------------------------*/yyreduce:  /* yyn is the number of a rule to reduce with.  */  yylen = yyr2[yyn];  /* If YYLEN is nonzero, implement the default value of the action:     `$$ = $1'.     Otherwise, the following line sets YYVAL to garbage.     This behavior is undocumented and Bison     users should not rely upon it.  Assigning to YYVAL     unconditionally makes the parser a bit smaller, and it avoids a     GCC warning that YYVAL may be used uninitialized.  */  yyval = yyvsp[1-yylen];  YY_REDUCE_PRINT (yyn);  switch (yyn)    {        case 4:#line 127 "slp_filter_y.y"    {     if(NULL != (yyval.filter_filter = SLPAllocFilter(yyvsp[-2].filter_int)))    {        yyval.filter_filter->nestingLevel = nesting_level;        if(!SLP_IS_EMPTY(&reducedFilters) )        {            SLPLDAPFilter *temp = (SLPLDAPFilter *)reducedFilters.next;            while(!SLP_IS_HEAD(temp))            {                if(temp->nestingLevel == nesting_level + 1)                {                    SLPLDAPFilter *nest = temp;                    temp = temp->next;                   SLP_UNLINK(nest);                   SLP_INSERT_BEFORE(nest, (SLPLDAPFilter *)&(yyval.filter_filter->children)) ;                }                else                {                    temp = temp->next;                }            }           SLP_INSERT_BEFORE( (filterHead *)yyval.filter_filter, &reducedFilters);        }        else        {            SLPFreeFilter(yyval.filter_filter) ; yyval.filter_filter = NULL ;        }    }}    break;  case 5:#line 157 "slp_filter_y.y"    {     yyval.filter_filter = yyvsp[-1].filter_filter;    if(yyvsp[-1].filter_filter != NULL)    {        yyvsp[-1].filter_filter->nestingLevel = nesting_level;       SLP_INSERT_BEFORE((filterHead *)yyvsp[-1].filter_filter, &reducedFilters) ;     }}    break;  case 6:#line 167 "slp_filter_y.y"    {     nesting_level++; }    break;  case 7:#line 172 "slp_filter_y.y"    {     nesting_level--; }    break;  case 10:#line 177 "slp_filter_y.y"    {     yyval.filter_int = yylval.filter_int; }    break;  case 11:#line 182 "slp_filter_y.y"    {      /* presence test binds to single operand */    if(NULL != (yyval.filter_filter = SLPAllocFilter(expr_present)))    {        SLPAttrList *attr = SLPAllocAttr(yyvsp[-1].filter_string, string, "*", (int)strlen("*") + 1);        if(attr != NULL)        {           SLP_INSERT(attr, &(yyval.filter_filter->attrs));        }        else        {            SLPFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL;        }    }}    break;  case 12:#line 198 "slp_filter_y.y"    {  /* must be an int or a bool */    /* remember to touch up the token values to match the enum in SLP.h */    if(NULL != (yyval.filter_filter = SLPAllocFilter(yyvsp[-1].filter_int)))    {        SLPAttrList *attr = SLPAllocAttr(yyvsp[-2].filter_string, integer, &(yyvsp[0].filter_int), sizeof(yyvsp[0].filter_int));        if(attr != NULL)        {           SLP_INSERT(attr, &(yyval.filter_filter->attrs));        }        else        {            SLPFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL ;        }     }}    break;  case 13:#line 214 "slp_filter_y.y"    {  /* must be an int or a bool */    /* remember to touch up the token values to match the enum in SLP.h */    if(NULL != (yyval.filter_filter = SLPAllocFilter(yyvsp[-1].filter_int)))    {        SLPAttrList *attr = SLPAllocAttr(yyvsp[-2].filter_string, boolean, &(yyvsp[0].filter_int), sizeof(yyvsp[0].filter_int));        if(attr != NULL)        {           SLP_INSERT(attr, &(yyval.filter_filter->attrs));        }        else        {            SLPFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL ;        }     }}    break;  case 14:#line 230 "slp_filter_y.y"    {   /* both operands are strings */    if(NULL != (yyval.filter_filter = SLPAllocFilter(yyvsp[-1].filter_int)))    {        SLPAttrList *attr = SLPAllocAttr(yyvsp[-2].filter_string, string, yyvsp[0].filter_string, (int)strlen(yyvsp[0].filter_string) + 1 );        if(attr != NULL)        {           SLP_INSERT(attr, &(yyval.filter_filter->attrs));        }        else        {            SLPFreeFilter(yyval.filter_filter); yyval.filter_filter = NULL ;        }     }}    break;  case 18:#line 246 "slp_filter_y.y"    {     yyval.filter_int = yylval.filter_int; }    break;    }/* Line 991 of yacc.c.  */#line 1232 "slp_filter_y.c"  yyvsp -= yylen;  yyssp -= yylen;  YY_STACK_PRINT (yyss, yyssp);  *++yyvsp = yyval;  /* Now `shift' the result of the reduction.  Determine what state     that goes to, based on the state we popped back to and the rule     number reduced by.  */  yyn = yyr1[yyn];  yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;  if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)    yystate = yytable[yystate];  else    yystate = yydefgoto[yyn - YYNTOKENS];  goto yynewstate;/*------------------------------------.| yyerrlab -- here on detecting error |`------------------------------------*/yyerrlab:  /* If not already recovering from an error, report this error.  */  if (!yyerrstatus)    {      ++yynerrs;#if YYERROR_VERBOSE      yyn = yypact[yystate];      if (YYPACT_NINF < yyn && yyn < YYLAST)	{	  YYSIZE_T yysize = 0;	  int yytype = YYTRANSLATE (yychar);	  char *yymsg;	  int yyx, yycount;	  yycount = 0;	  /* Start YYX at -YYN if negative to avoid negative indexes in	     YYCHECK.  */	  for (yyx = yyn < 0 ? -yyn : 0;	       yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++)	    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)	      yysize += yystrlen (yytname[yyx]) + 15, yycount++;	  yysize += yystrlen ("syntax error, unexpected ") + 1;	  yysize += yystrlen (yytname[yytype]);	  yymsg = (char *) YYSTACK_ALLOC (yysize);	  if (yymsg != 0)	    {	      char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");	      yyp = yystpcpy (yyp, yytname[yytype]);	      if (yycount < 5)		{		  yycount = 0;		  for (yyx = yyn < 0 ? -yyn : 0;		       yyx < (int) (sizeof (yytname) / sizeof (char *));		       yyx++)		    if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)		      {			const char *yyq = ! yycount ? ", expecting " : " or ";			yyp = yystpcpy (yyp, yyq);			yyp = yystpcpy (yyp, yytname[yyx]);			yycount++;		      }		}	      yyerror (yymsg);	      YYSTACK_FREE (yymsg);	    }	  else	    yyerror ("syntax error; also virtual memory exhausted");	}      else#endif /* YYERROR_VERBOSE */	yyerror ("syntax error");    }  if (yyerrstatus == 3)    {      /* If just tried and failed to reuse lookahead token after an	 error, discard it.  */      /* Return failure if at end of input.  */      if (yychar == YYEOF)        {	  /* Pop the error token.  */          YYPOPSTACK;	  /* Pop the rest of the stack.  */	  while (yyss < yyssp)	    {	      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);	      yydestruct (yystos[*yyssp], yyvsp);	      YYPOPSTACK;	    }	  YYABORT;        }      YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);      yydestruct (yytoken, &yylval);      yychar = YYEMPTY;    }  /* Else will try to reuse lookahead token after shifting the error     token.  */  goto yyerrlab2;/*----------------------------------------------------.| yyerrlab1 -- error raised explicitly by an action.  |`----------------------------------------------------*/yyerrlab1:  /* Suppress GCC warning that yyerrlab1 is unused when no action     invokes YYERROR.  */#if defined (__GNUC_MINOR__) && 2093 <= (__GNUC__ * 1000 + __GNUC_MINOR__) \    && !defined __cplusplus  __attribute__ ((__unused__))#endif  goto yyerrlab2;/*---------------------------------------------------------------.| yyerrlab2 -- pop states until the error token can be shifted.  |`---------------------------------------------------------------*/yyerrlab2:  yyerrstatus = 3;	/* Each real token shifted decrements this.  */  for (;;)    {      yyn = yypact[yystate];      if (yyn != YYPACT_NINF)	{	  yyn += YYTERROR;	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)	    {	      yyn = yytable[yyn];	      if (0 < yyn)		break;	    }	}      /* Pop the current state because it cannot handle the error token.  */      if (yyssp == yyss)	YYABORT;      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);      yydestruct (yystos[yystate], yyvsp);      yyvsp--;      yystate = *--yyssp;      YY_STACK_PRINT (yyss, yyssp);    }  if (yyn == YYFINAL)    YYACCEPT;  YYDPRINTF ((stderr, "Shifting error token, "));  *++yyvsp = yylval;  yystate = yyn;  goto yynewstate;/*-------------------------------------.| yyacceptlab -- YYACCEPT comes here.  |`-------------------------------------*/yyacceptlab:  yyresult = 0;  goto yyreturn;/*-----------------------------------.| yyabortlab -- YYABORT comes here.  |`-----------------------------------*/yyabortlab:  yyresult = 1;  goto yyreturn;#ifndef yyoverflow/*----------------------------------------------.| yyoverflowlab -- parser overflow comes here.  |`----------------------------------------------*/yyoverflowlab:  yyerror ("parser stack overflow");  yyresult = 2;  /* Fall through.  */#endifyyreturn:#ifndef yyoverflow  if (yyss != yyssa)    YYSTACK_FREE (yyss);#endif  return yyresult;}#line 250 "slp_filter_y.y" SLPLDAPFilter *SLPAllocFilter(int operator){    SLPLDAPFilter *filter = (SLPLDAPFilter *)calloc(1, sizeof(SLPLDAPFilter));    if ( filter  != NULL )    {        filter->next = filter->prev = filter;        if ( operator == head )        {            filter->isHead = TRUE;        }        else        {            filter->children.next = filter->children.prev = &(filter->children);            filter->children.isHead = 1;            filter->attrs.next = filter->attrs.prev = &(filter->attrs);            filter->attrs.isHead = 1;            filter->operator = operator;        }    }    return(filter);}void SLPFreeFilter(SLPLDAPFilter *filter){    if ( filter->children.next != NULL )    {        while ( ! (SLP_IS_EMPTY((SLPLDAPFilter *)&(filter->children))) )        {            SLPLDAPFilter *child = (SLPLDAPFilter *)filter->children.next;           SLP_UNLINK(child);            SLPFreeFilter(child);        }    }    if ( filter->attrs.next != NULL )    {        while ( ! (SLP_IS_EMPTY(&(filter->attrs))) )        {            SLPAttrList *attrs = filter->attrs.next;           SLP_UNLINK(attrs);            SLPFreeAttr(attrs);        }    }}void SLPFreeFilterList(SLPLDAPFilter *head, int static_flag){    while ( ! (SLP_IS_EMPTY(head)) )    {        SLPLDAPFilter *temp = head->next;       SLP_UNLINK(temp);        SLPFreeFilter(temp);    }    if ( static_flag == TRUE )        SLPFreeFilter(head);    return;}void SLPFreeFilterTree(SLPLDAPFilter *root){    if ( !SLP_IS_EMPTY( &(root->children) ) )    {        SLPFreeFilterTree((SLPLDAPFilter *)root->children.next);    }    if ( ! (SLP_IS_HEAD(root->next)) && (!SLP_IS_EMPTY(root->next)) )    {        SLPFreeFilterTree(root->next);    }    if ( root->attrs.next != NULL )    {        while ( ! (SLP_IS_EMPTY(&(root->attrs))) )        {            SLPAttrList *attrs = root->attrs.next;           SLP_UNLINK(attrs);            SLPFreeAttr(attrs);        }    }}void SLPInitFilterList(void ){    reducedFilters.next = reducedFilters.prev = &reducedFilters;    reducedFilters.isHead = TRUE;    return;}void SLPCleanUpFilterList(void){    SLPFreeFilterList( (SLPLDAPFilter *)&reducedFilters, FALSE);}SLPLDAPFilter *SLPDecodeLDAPFilter(const char *filter){    SLPLDAPFilter *temp = NULL;    unsigned int lexer = 0;    SLPInitFilterList();    nesting_level = 1;    if ( 0 != (lexer = slp_filter_init_lexer(filter)) )    {        if ( slp_filter_parse() )        {            SLPCleanUpFilterList();        }        slp_filter_close_lexer(lexer);    }    if ( !SLP_IS_EMPTY(&reducedFilters) )    {        if ( NULL != (temp  = SLPAllocFilter(ldap_and)) )        {           SLP_LINK_HEAD(&(temp->children), &reducedFilters);        }    }    SLPCleanUpFilterList();    return(temp);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -