Ejemplo n.º 1
0
void MainObject::ReadRmlSocket(QSocketDevice *dev,RDMacro::Role role,
			       bool echo)
{
  char buffer[RD_RML_MAX_LENGTH];
  char cmd[RD_RML_MAX_LENGTH+4];
  QString output;
  int n;
  QHostAddress peer_addr;
  RDMacro macro;

  while((n=dev->readBlock(buffer,RD_RML_MAX_LENGTH))>0) {
    buffer[n]=0;
    if(macro.parseString(buffer,n)) {
      macro.setRole(role);
      macro.setAddress(dev->peerAddress());
      macro.setEchoRequested(echo);
      macro.generateString(buffer,RD_RML_MAX_LENGTH);
      switch(role) {
	  case RDMacro::Cmd:
	    sprintf(cmd,"MS %s %d %s",(const char *)macro.address().toString(),
		    echo,buffer);
	    RunLocalMacros(&macro);
	    BroadcastCommand(cmd);
	    break;

	  case RDMacro::Reply:
	    sprintf(cmd,"ME %s %d %s",(const char *)macro.address().toString(),
		    echo,buffer);
	    break;

	  default:
	    break;
      }
    }
    else {
      LogLine(RDConfig::LogWarning,
	      QString().sprintf("received malformed rml: \"%s\" from %s:%u",
				buffer,
				(const char *)dev->peerAddress().toString(),
				dev->peerPort()));
      if(echo) {
	macro.setRole(RDMacro::Reply);
	macro.setCommand(RDMacro::NN);
	macro.setArg(0,"-");
	macro.setArgQuantity(1);
	macro.setAddress(dev->peerAddress());
	sendRml(&macro);
      }
    }
  }
}
Ejemplo n.º 2
0
void MainObject::DispatchCommand(int ch)
{
  QString default_name;
  char str[RD_RML_MAX_LENGTH];
  RDMacro macro;
  char buffer[RD_RML_MAX_LENGTH];
  char cmd[RD_RML_MAX_LENGTH+4];
  int echo=0;
  QHostAddress addr;

  //
  // Common Commands
  // Authentication not required to execute these!
  //
  if(!strcmp(args[ch][0],"DC")) {  // Drop Connection
    socket[ch]->close();
    KillSocket(ch);
    return;
  }
  if(!strcmp(args[ch][0],"PW")) {  // Password Authenticate
    if(!strcmp(args[ch][1],ripcd_config->password())) {
      auth[ch]=true;
      EchoCommand(ch,"PW +!");
      return;
    }
    else {
      auth[ch]=false;
      EchoCommand(ch,"PW -!");
      return;
    }
  }

  //
  // Priviledged Commands
  // Authentication required to execute these!
  //
  if(!auth[ch]) {
    EchoArgs(ch,'-');
    return;
  }

  if(!strcmp(args[ch][0],"RU")) {  // Request User
    EchoCommand(ch,(const char *)QString().
		sprintf("RU %s!",(const char *)rdstation->userName()));
    return;
  }

  if(!strcmp(args[ch][0],"SU")) {  // Set User
    SetUser(args[ch][1]);
  }

  if(!strcmp(args[ch][0],"MS")) {  // Send RML Command
    if(argnum[ch]<4) {
      return;
    }
    strcpy(str,args[ch][3]);
    for(int i=4;i<argnum[ch];i++) {
      strcat(str," ");
      strcat(str,args[ch][i]);
    }
    strcat(str,"!");
  }
  if(macro.parseString(str,strlen(str))) {
    addr.setAddress(args[ch][1]);
    macro.setAddress(addr);
    macro.setRole(RDMacro::Cmd);

/*
  char temp[RD_RML_MAX_LENGTH];
  macro.generateString(temp,RD_RML_MAX_LENGTH);
  LogLine(QString().sprintf("RECEIVED: %s  ADDR: %s\n",temp,(const char *)macro.address().toString()));
*/

    if(!macro.address().isNull()) {
      if(macro.address()==rdstation->address()) {  // Local Loopback
	macro.generateString(buffer,RD_RML_MAX_LENGTH);
	if(macro.echoRequested()) {
	  echo=1;
	}
	sprintf(cmd,"MS %s %d %s",(const char *)macro.address().toString(),
		echo,buffer);
	RunLocalMacros(&macro);
	BroadcastCommand(cmd);
      }
      else {
	sendRml(&macro);
      }
    }
  }

  if(!strcmp(args[ch][0],"ME")) {  // Send RML Reply
    if(argnum[ch]<4) {
      return;
    }
    strcpy(str,args[ch][3]);
    for(int i=4;i<argnum[ch];i++) {
      strcat(str," ");
      strcat(str,args[ch][i]);
    }
    strcat(str,"!");
  }
  if(macro.parseString(str,strlen(str))) {
    QHostAddress addr;
    addr.setAddress(args[ch][1]);
    macro.setAddress(addr);
    macro.setRole(RDMacro::Reply); 
    if(macro.address()==rdstation->address()) {  // Local Loopback
      macro.generateString(buffer,RD_RML_MAX_LENGTH);
      sprintf(cmd,"ME %s 0 %s",(const char *)macro.address().toString(),
	      buffer);
      BroadcastCommand(cmd);
    }
    else {
      sendRml(&macro);
    }
  }

  if(!strcmp(args[ch][0],"RG")) {  // Reload the GPI Table
    LoadGpiTable();
  }

  if(!strcmp(args[ch][0],"GI")) {  // Send Complete GPI Status
    int matrix;
    sscanf(args[ch][1],"%d",&matrix);
    SendGpi(ch,matrix);
  }

  if(!strcmp(args[ch][0],"GO")) {  // Send Complete GPO Status
    int matrix;
    sscanf(args[ch][1],"%d",&matrix);
    SendGpo(ch,matrix);
  }

  if(!strcmp(args[ch][0],"GM")) {  // Send Complete GPI Mask States
    int matrix;
    sscanf(args[ch][1],"%d",&matrix);
    SendGpiMask(ch,matrix);
  }

  if(!strcmp(args[ch][0],"GN")) {  // Send Complete GPI Mask States
    int matrix;
    sscanf(args[ch][1],"%d",&matrix);
    SendGpoMask(ch,matrix);
  }

  if(!strcmp(args[ch][0],"GC")) {  // Send Complete GPI Cart Assignments
    int matrix;
    sscanf(args[ch][1],"%d",&matrix);
    SendGpiCart(ch,matrix);
  }

  if(!strcmp(args[ch][0],"GD")) {  // Send Complete GPO Cart Assignments
    int matrix;
    sscanf(args[ch][1],"%d",&matrix);
    SendGpoCart(ch,matrix);
  }

  if(!strcmp(args[ch][0],"TA")) {  // Send Onair Flag State
    EchoCommand(ch,QString().sprintf("TA %d!",ripc_onair_flag));
  }
}