void comando(void)
{
        
	atribuicao();	    

	chamada_de_funcao2(); //Verificar a possibilidade de testar diretamente em comando...para evitar erros.
	 
	comando_condicional();
	 
	comando_repetitivo();
	

	
	//Verifica se o proximo token й GET
    if((tk.cat == PR) && (tk.p_reservada == GET)){
		tk = analex();
		//Verifica se o proximo token й '('
		if((tk.cat == SN) && (tk.cod == OPP)){
			tk = analex();
			if(tk.cat == ID){               
				tk = analex();
				
				if((tk.cat == SN) && (tk.cod == CLP)){
					tk = analex();
					
					if((tk.cat == SN) && (tk.cod == SMC)){               
   					tk = analex();
   					comando();
					} else erro(lin, 8); //Chama erro caso nгo venha ';'
					
				} else erro(lin, 3); //Chama erro caso nгo venha ')'
				
			} else erro(lin, 1);
			
		} else erro(lin, 2);		
	}
	
	else if((tk.cat == PR) && (tk.p_reservada == PUT)){
		tk = analex();
		if((tk.cat == SN) && (tk.cod == OPP)){
			tk = analex();
			literal();
			expressao_simples();
			//Verifica se o proximo token й um ')'
			if((tk.cat == SN) && (tk.cod == CLP)){
				tk = analex();
				if((tk.cat == SN) && (tk.cod == SMC)){
					tk = analex();
					comando();
				} else erro(lin, 8); //Chama erro caso nгo venha ';'
				
			} else erro(lin, 3); //Chama erro caso nгo venha ')'
			
		} else erro(lin, 2);//Chama erro caso nгo venha '('
		
	}else	if((tk.cat == SN) && (tk.cod == SMC)){
        tk = analex();
        comando();     
   }
}
void comando_repetitivo(void)
{
	//Verifica se o proximo token й um WHILE
	if((tk.cat == PR) && (tk.p_reservada == WHILE)){
		tk = analex();
		//Verifica se o proximo token й '('
		if((tk.cat == SN) && (tk.cod == OPP)){
			tk = analex();
			expressao();
			//Verifica se o proximo token й um ')'
			if((tk.cat == SN) && (tk.cod == CLP)){
				tk = analex();
				//Verifica se o proximo token й '{'
				if((tk.cat == SN) && (tk.cod == OPB)){
					tk = analex();
					comando();
					//Verifica se o proximo token й '}'
					if((tk.cat == SN) && (tk.cod == CLB)){
						tk = analex();
						comando();
					} else erro(lin, 5);//Chama erro caso nгo venha '}'
					
				} else erro(lin, 4); //chama erro caso nгo venha '{'
				
			} else erro(lin, 3); //Chama erro caso nгo venha ')'
			
		} else erro(lin, 2);//Chama erro caso nгo venha '('
	}
}
Example #3
0
/*** Função que confere o comando else ***/
int else_opc() {
    //printf("ELSE_OPC\n");
    if(match(ELSE)) {
        if(comando()) {
            return 1;
        } else return 0;
    } else return 1;
}
void comando_condicional(void)
{
	//Verifica se o proximo token й um IF
	if((tk.cat == PR) && (tk.p_reservada == IF)){
		tk = analex();
		//Verifica se o proximo token й um '('
		if((tk.cat == SN) && (tk.cod == OPP)){
			tk = analex();
			expressao();
			//verifica se o proximo token й um ')'
			if((tk.cat == SN) && (tk.cod == CLP)){
				tk = analex();
				//Verifica se o proximo token й um '{'
				if((tk.cat == SN) && (tk.cod == OPB)){
					tk = analex();
					comando();
					//Verifica se o proximo token й um '}'
					if((tk.cat == SN) && (tk.cod == CLB)){
						tk = analex();
						comando();
					} else erro( lin, 5); //chama erro caso nгo venha '}'
					
				} else erro(lin, 4); // chama err caso nгo venha '{'
				
			} else erro(lin, 3); // chama erro caso nгo venha ')'
			
		} else erro(lin, 2); // chama o erro caso nгo venha um '('
	
	}
	
	//Verifica se o proximo token й um ELSE
	else if((tk.cat == PR) && (tk.p_reservada == ELSE)){
		tk = analex();
		//Verifica se o proximo token й um '{'
		if((tk.cat == SN) && (tk.cod == OPB)){
			tk = analex();
			comando();
			//Verifica se o proximo token й um '}'
			if((tk.cat == SN) && (tk.cod == CLB)){
				tk = analex();
				comando();
			} else erro(lin, 5); //chama erro caso nгo venha '}'
			
		} else erro(lin, 4); //chama erro caso nгo venha '{'
	}
}
Example #5
0
/*** Função que confere os comandos ***/
int comandos() {
    if(comando()) {
        if(match(PONTOVIRGULA)) {
            if(comandos()) {
                return 1;
            } else return 0;
        } else return 1;
    } else return 1;
}
void chamada_de_funcao1(void)
{
	if(aux.sit == PEN){
		if((tk.cat == SN) && (tk.cod == OPP)){
			tk = analex();
			lista_de_expressoes();
			//Verifica se o proximo token й um ')'
			if((tk.cat == SN) && (tk.cod == CLP)){
				tk = analex();
				//Verifica se o proximo token й um ';'
				if((tk.cat == SN) && (tk.cod == SMC)){
					tk = analex();
					aux.sit = LIV;
					comando();
				} else erro(lin, 8); // Chmama mensagem de erro caso nгo venha ';'
			} else erro(lin, 3); // Chama mensagem de erro caso nгo venha ')'
			
		} else 	erro(lin, 2);
		
	} else {	
		if(tk.cat == ID){
			tk = analex();
			//Verifica se o procximo token й um '('
			if((tk.cat == SN) && (tk.cod == OPP)){
				tk = analex();
				lista_de_expressoes();
				//Verifica se o proximo token й um ')'
				if((tk.cat == SN) && (tk.cod == CLP)){
					tk = analex();
					//Verifica se o proximo token й um ';'
					if((tk.cat == SN) && (tk.cod == SMC)){
						tk = analex();
						comando();
					} else erro(lin, 8); // Chmama mensagem de erro caso nгo venha ';'
					
				} else erro(lin, 3); // Chama mensagem de erro caso nгo venha ')'
			}
		}
	}
}
Example #7
0
void Request_Command_Local(string s_comando) {
  string cmd;
  
  s_comando.erase(0,1);
  istringstream comando(s_comando);
  comando >> cmd;
  
  if (cmd == "cd" )
  {
    s_comando.erase(0,3);               // Separa o 'path' 'do comando'.
    if (chdir(s_comando.c_str()))
      cout << "Erro na mudanca local de diretorio. " << endl;
  }
  else
    system(s_comando.c_str());
}
void atribuicao(void)
{
    int tipo1, tipo2;
    char id[50];
    tipo1 = tipo2 = 0;
     
	if(tk.cat == ID){
        
      strcpy(id, tk.lexema);       
		strcpy(aux.id, tk.lexema);
		tk = analex();
				
		//Verifica se o proximo token й um '='
		if((tk.cat == SN) && (tk.cod == ATB)){
                   
         tipo1 = verifica_tabela(id);      
			tk = analex();			
			tipo2 = expressao();
			
			if(tipo1 != tipo2){
                
              erro(lin, 12);           
            }
         			
			//Verifica se o proximo token й um ';'
			if((tk.cat == SN) && (tk.cod == SMC)){
				tk = analex();
			             			
				comando();
				
			} else erro(lin, 8); //Chama mensagem de erro caso nгo venha um ';'
			
		} else{
			aux.sit = PEN;
		}
	}
}
Example #9
0
/*** Função que confere um comando ***/
int comando() {
    if(match(PRINT)) {
        if(match(LPARENT)) {
            if(lista_argumentos()) {
                if(match(RPARENT)) {
                    return 1;
                } else return 0;
            } else return 0;
        } else return 0;
    } else if(match(IF)) {
        if(match(NOT)) return 1;
        if(expr_relacional()) {
            if(match(OR)||match(AND)) return 1;
            if(match(THEN)) {
                if(comando()) {
                    if(else_opc()) {
                        return 1;
                    } else return 0;
                } else return 0;
            } else return 0;
        } else if(match(LPARENT)) {
            if(expr_relacional()) {
                if(match(RPARENT)) {
                    if(match(OR)||match(AND)) return 1;
                    if(match(THEN)) {
                        if(comando()) {
                            if(else_opc()) {
                                return 1;
                            } else return 0;
                        } else return 0;
                    } else return 0;
                } else return 0;
            } else return 0;
        } else return 0;
    } else if(ident()) {
        if(match(ASSIGN)) {
            if(expr()) {
                if(match(PONTOVIRGULA)) {
                    if(comando()) {
                        if(comandos()) return 1;
                        return 1;
                    } else return 1;
                } else return 0;
            } else if(match(NUM)) {
                return 1;
            } else return 0;
        } else return 0;
    } else if(match(FOR)) {
        if(ident()) {
            if(match(ASSIGN)) {
                if(expr()) {
                    if(match(TO) || match(DOWNTO)) {
                        if(expr()) {
                            if(match(DO)) {
                                if(comando()) {
                                    if(comandos()) return 1;
                                    return 1;
                                } else return 0;
                            } else return 0;
                        } else return 0;
                    } else return 0;
                } else return 0;
            } else return 0;
        } else return 0;
    } else if(chamada_proc()) {
        return 1;
    } else if(bloco()) {
        return 1;
    } else if(match(WRITELN)||match(WRITE)) {
        if(match(LPARENT)) {
            if(literal()) {
                while(match(VIRGULA)) {
                    if(expr()) {
                        continue;
                    } else if(literal()) {
                        continue;
                    } else if(expr()) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
                if(match(RPARENT)) {
                    return 1;
                } else return 0;
            } else if(ident()) {
                while(match(VIRGULA)) {
                    if(ident()) {
                        continue;
                    } else if(literal()) {
                        continue;
                    } else if(expr()) {
                        return 1;
                    } else {
                        return 0;
                    }
                }
                if(match(RPARENT)) {
                    return 1;
                } else return 0;
            } else if(match(RPARENT)) {
                return 1;
            } else return 0;
        } else return 0;
    } else if(match(READLN)) {
        if(match(LPARENT)) {
            if(lista_ident()) {
                if(match(RPARENT)) {
                    return 1;
                } else return 0;
            } else return 0;
        } else return 0;
    } else if(match(BREAK)||match(READKEY)) {
        if(match(PONTOVIRGULA)) {
            return 1;
        } else return 0;
    } else if(match(WHILE)) {
        if(match(LPARENT)) {
            if(expr_relacional()) {
                if(match(RPARENT)) {
                    if(match(DO)) {
                        if(comando()) {
                            if(comandos()) return 1;
                            return 1;
                        } else return 0;
                    } else return 0;
                } else return 0;
            } else return 0;
        } else if(expr_relacional()) {
            if(match(DO)) {
                if(comando()) {
                    return 1;
                } else return 0;
            } else return 0;
        } else return 0;
    } else return 1;
}
int AtiendeCliente(int socket, struct sockaddr_in addr)
{

     char buffer[BUFFERSIZE];
     char aux[BUFFERSIZE];
     int bytecount;
     int fin=0;
     int code=0;         /* Código de salida por defecto */
     time_t t;
     struct tm *tmp;

     while (!fin)
       {

     memset(buffer, 0, BUFFERSIZE);
     if((bytecount = recv(socket, buffer, BUFFERSIZE, 0))== -1)
       error(5, "No puedo recibir información");
     

     //verificamos si lo que mandan es una ip y entonces la cambiamos por MAC
     if (strncmp(buffer, "IP", 2)==0)
     {
         printf("Se trata de in IPHONE\n");
         std::string comando(buffer);
         comando=comando.substr(3);
         comando="weon:"+GetMac(comando);
         
         printf("El comando dice:");
         printf(comando.c_str());
         
         comando.copy(buffer,comando.length(),0);         
     }
     ///////////////////////////////////////
     /* Evaluamos los comandos */
     /* El sistema de gestión de comandos es muy rudimentario, pero nos vale */
     /* Comando TIME - Da la hora */
     //weon:mac
     if (strncmp(buffer, "weon", 4)==0)
       {
         t = time(NULL);
         tmp = localtime(&t);
         //separo la mac address
         std::string mac(buffer);
         mac=mac.substr(5,17);
         
         
         //registro el inicio de sesion, talvez solo registro todos
         
         memset(buffer, 0, 7);
         strftime(buffer, BUFFERSIZE, "echo '%H|", tmp);
         std::string txt(buffer);
         txt.append(mac);
         txt.append("' >> /etc/weon/InciosSesion.txt");
         memset(buffer, 0, txt.length());
         txt.copy(buffer,txt.length(),0);
         system(buffer);
         printf(buffer);
         //coloco la regla que logea
         //se registrara todo, esta linea no es necesaria
         
         txt="iptables -A FORWARD -p tcp --dport 443 -m mac --mac-source ";
         txt.append(mac);
         txt.append(" -m state --state NEW -j LOG --log-prefix 'weon:");
         txt.append(mac);
         txt.append("' --log-level 4 ");
         memset(buffer, 0, BUFFERSIZE);
         txt.copy(buffer,txt.length(),0);
         system(buffer);
         printf(buffer);
         
         //coloco la regla que concede permisos
         //std::string txt;
         txt="/sbin/iptables -A FORWARD -m mac --mac-source ";
         txt.append(mac);
         txt.append(" -j ACCEPT");
         memset(buffer, 0,BUFFERSIZE);
         txt.copy(buffer,txt.length(),0);
         system(buffer); 
         printf(buffer);
         
         //regla que manda todo a squid
         txt="/sbin/iptables -t nat -I PREROUTING 2 -m mac --mac-source ";
         txt.append(mac);
         txt.append(" -p tcp --dport 80 -j DNAT --to-destination 192.168.1.250:3128");
         memset(buffer, 0,BUFFERSIZE);
         txt.copy(buffer,txt.length(),0);
         system(buffer); 
         printf(buffer);
         //esta regla deja saliro todo el trafico que no va al 80
         txt="/sbin/iptables -t nat -I PREROUTING 3 -m mac --mac-source ";
         txt.append(mac);
         txt.append(" -j ACCEPT");
         memset(buffer, 0,BUFFERSIZE);
         txt.copy(buffer,txt.length(),0);
         system(buffer); 
         printf(buffer);
         
         //regreso mesage de concedido
         txt="OK:"+mac;
         memset(buffer, 0, BUFFERSIZE);
         txt.copy(buffer,txt.length(),0);
         fin=1;
       }
     
     else if (strncmp(buffer, "check", 5)==0)
     {
         
         std::string cmd(buffer);
         cmd=cmd.substr(6);
         memset(buffer,0,BUFFERSIZE);
         cmd.copy(buffer,cmd.length(),0);
         system(buffer);
         fin=1;
     }
     /* Comando DATE - Da la fecha */
     else if (strncmp(buffer, "DATE", 4)==0)
       {
         memset(buffer, 0, BUFFERSIZE);

         t = time(NULL);
         tmp = localtime(&t);

         strftime(buffer, BUFFERSIZE, "Hoy es %d/%m/%Y\n", tmp);
       }
     /* Comando HOLA - Saluda y dice la IP */
     else if (strncmp(buffer, "HOLA", 4)==0)
       {
         memset(buffer, 0, BUFFERSIZE);
         sprintf(buffer, "Hola %s, ¿cómo estás?\n", inet_ntoa(addr.sin_addr));
       }
     /* Comando EXIT - Cierra la conexión actual */
     else if (strncmp(buffer, "E", 1)==0)
       {
         memset(buffer, 0, BUFFERSIZE);
         sprintf(buffer, "Hasta luego. Vuelve pronto %s\n", inet_ntoa(addr.sin_addr));
         fin=1;
       }
     /* Comando CERRAR - Cierra el servidor */
     else if (strncmp(buffer, "Q",1)==0)
       {
         memset(buffer, 0, BUFFERSIZE);
         sprintf(buffer, "Adiós. Cierro el servidor\n");
         fin=1;
         code=99;        /* Salir del programa */
       }
     else
       {     
         sprintf(aux, "ECHO: %s\n", buffer);
         strcpy(buffer, aux);
       }

     if((bytecount = send(socket, buffer, strlen(buffer), 0))== -1)
       error(6, "No puedo enviar información");
       }

     close(socket);
     return code;
}
Example #11
0
void bloco_de_funcao(void)
{
	declaracao_variaveis();
	comando();
}