Exemplo n.º 1
0
int main(int argc, char **argv) {
    char *cmd;
    char **args;

    printf("------Welcome to Shelldon------\n");
    printf("use \"help\" to see list of available features\n");

    while(1) {
        printf("%s=> ",getlogin());
        cmd = readCmd();
        args = splitCmd(cmd);

        if(args[0]!=NULL&&!runCmd(args)) //need to skip if blank command
            break;

        //printf("%s\n%s\n%s\n",args[0],args[1],args[2]);
        free(cmd);
        free(args);
    }

    free(cmd);
    free(args);

    return 0;
}
Exemplo n.º 2
0
DSMCondition* DSMCoreModule::getCondition(const string& from_str) {
  string cmd;
  string params;
  splitCmd(from_str, cmd, params);

  if (cmd == "keyPress") {
    DSMCondition* c = new DSMCondition();
    c->name = "key pressed: " + params;
    c->type = DSMCondition::Key;
    c->params["key"] = params;
    return c;
  }

  if (cmd == "test")
    return new TestDSMCondition(params, DSMCondition::Any);

  if (cmd == "keyTest") 
    return new TestDSMCondition(params, DSMCondition::Key);

  if (cmd == "timerTest") 
    return new TestDSMCondition(params, DSMCondition::Timer);

  if (cmd == "noAudioTest") 
    return new TestDSMCondition(params, DSMCondition::NoAudio);

  if (cmd == "hangup") 
    return new TestDSMCondition(params, DSMCondition::Hangup);  

  ERROR("could not find condition for '%s'\n", cmd.c_str());
  return NULL;
}
Exemplo n.º 3
0
DSMAction* CurlModule::getAction(const string& from_str) {
  string cmd;
  string params;
  splitCmd(from_str, cmd, params);

  DEF_CMD("curl.get", SCJCurlGetAction);
  DEF_CMD("curl.getDiscardResult", SCJCurlGetNoresultAction);
  DEF_CMD("curl.getFile", SCJCurlGetFileAction);
  DEF_CMD("curl.getForm", SCJCurlGetFormAction);
  DEF_CMD("curl.post", SCJCurlPOSTGetResultAction);
  DEF_CMD("curl.postDiscardResult", SCJCurlPOSTAction);

  return NULL;
}
Exemplo n.º 4
0
DSMAction* DSMCoreModule::getAction(const string& from_str) {
  string cmd;
  string params;
  splitCmd(from_str, cmd, params);

#define DEF_CMD(cmd_name, class_name) \
				      \
  if (cmd == cmd_name) {	      \
    class_name * a =		      \
      new class_name(params);	      \
    a->name = from_str;		      \
    return a;			      \
  }

  DEF_CMD("repost", SCRepostAction);
  DEF_CMD("jumpFSM", SCJumpFSMAction);
  DEF_CMD("callFSM", SCCallFSMAction);
  DEF_CMD("returnFSM", SCReturnFSMAction);

  DEF_CMD("stop", SCStopAction);

  DEF_CMD("playPrompt", SCPlayPromptAction);
  DEF_CMD("playFile", SCPlayFileAction);
  DEF_CMD("recordFile", SCRecordFileAction);
  DEF_CMD("stopRecord", SCStopRecordAction);
  DEF_CMD("closePlaylist", SCClosePlaylistAction);

  DEF_CMD("set", SCSetAction);
  DEF_CMD("append", SCAppendAction);
  DEF_CMD("log", SCLogAction);

  DEF_CMD("setTimer", SCSetTimerAction);

  if (cmd == "DI") {
    SCDIAction * a = new SCDIAction(params, false);
    a->name = from_str;
    return a;
  }  

  if (cmd == "DIgetResult") {
    SCDIAction * a = new SCDIAction(params, true);
    a->name = from_str;
    return a;
  }  

  ERROR("could not find action named '%s'\n", cmd.c_str());
  return NULL;
}
Exemplo n.º 5
0
DSMAction* MonitoringModule::getAction(const string& from_str) {
  string cmd;
  string params;
  splitCmd(from_str, cmd, params);

#define DEF_CMD(cmd_name, class_name) \
				      \
  if (cmd == cmd_name) {	      \
    class_name * a =		      \
      new class_name(params);	      \
    a->name = from_str;		      \
    return a;			      \
  }

  DEF_CMD("monitoring.log", MonLogAction);
  DEF_CMD("monitoring.logAdd", MonLogAddAction);
  DEF_CMD("monitoring.logVars", MonLogVarsAction);

  return NULL;
}
Exemplo n.º 6
0
int main(int argc, char *argv[])
{

    char* arguments[MAX_ARGS];
    pipe(pipefd);

    signal(SIGCHLD, sig_chld_handler); //catching sigchld signal, for showing approporiate message when a child process has terminated

    printf("Basic Shell >");
    int counter = 0;
    int is_blocking;
    char** commands;
    while ((flagwhile==1)&&(fgets(s,in,stdin)!=NULL))                /// command to reading from stdin 80 char in S
    {
        commands = splitCmd(s);

        if( overflowecheck() == 1)
        {
            printf("Overflowe!!!");
        }
        else
        {
            counter =0;
            while(commands[counter]!= '\0')
            {
                is_blocking = parseCommand(commands[counter], arguments); // convert command string to an array
                if(arguments[0] !='\0') // check whether the input was an empty string or not
                {
                    if (strcmp(arguments[0], "exit") == 0)
                    {
                        exit(EXIT_SUCCESS);
                    }
                    else if(strcmp(arguments[0], "cd") == 0)
                    {

                        if(chdir(arguments[1]) == -1)
                        {
                            //on error
                            printf("%s\n",strerror(errno));

                        }
                    } else if(strcmp(arguments[0], "source") == 0)
                    {
                        FILE * f;
                        char * fline = NULL;
                        size_t flen = 0;
                        ssize_t read;
                        f = fopen(arguments[1], "r");
                        if (f == NULL)
                        {
                            printf("file open error\n");
                            return EXIT_FAILURE;
                        }
                        while ((read = getline(&fline, &flen, f)) != -1) 
                        {
                            char* arguments2[MAX_ARGS];
                            is_blocking = parseCommand(fline, arguments2);
                            execLauncher(arguments2, is_blocking);
                        }
                        free(fline);    
                        // return EXIT_SUCCESS;
                    }
                    else
                    {
                            execLauncher(arguments, is_blocking);
                    }
                }
                counter++;
            }
        }
        free(commands);// free the memory which allocated for the buffer
        clear_s();
        redirect_stdout = false;
		redirect_stdin = false;
        piping = false;
        printf("Basic Shell >");

   }//end while

    return 0;

}// end main
Exemplo n.º 7
0
DSMAction* DSMCoreModule::getAction(const string& from_str) {
  string cmd;
  string params;
  splitCmd(from_str, cmd, params);

  DEF_CMD("repost", SCRepostAction);
  DEF_CMD("jumpFSM", SCJumpFSMAction);
  DEF_CMD("callFSM", SCCallFSMAction);
  DEF_CMD("returnFSM", SCReturnFSMAction);

  DEF_CMD("throw", SCThrowAction);
  DEF_CMD("throwOnError", SCThrowOnErrorAction);

  DEF_CMD("stop", SCStopAction);

  DEF_CMD("playPrompt", SCPlayPromptAction);
  DEF_CMD("playPromptLooped", SCPlayPromptLoopedAction);
  DEF_CMD("playFile", SCPlayFileAction);
  DEF_CMD("playFileFront", SCPlayFileFrontAction);
  DEF_CMD("recordFile", SCRecordFileAction);
  DEF_CMD("stopRecord", SCStopRecordAction);
  DEF_CMD("getRecordLength", SCGetRecordLengthAction);
  DEF_CMD("getRecordDataSize", SCGetRecordDataSizeAction);
  DEF_CMD("closePlaylist", SCClosePlaylistAction);
  DEF_CMD("setInOutPlaylist", SCSetInOutPlaylistAction);
  DEF_CMD("addSeparator", SCAddSeparatorAction);
  DEF_CMD("connectMedia", SCConnectMediaAction);
  DEF_CMD("disconnectMedia", SCDisconnectMediaAction);
  DEF_CMD("mute", SCMuteAction);
  DEF_CMD("unmute", SCUnmuteAction);
  DEF_CMD("enableDTMFDetection", SCEnableDTMFDetection);
  DEF_CMD("disableDTMFDetection", SCDisableDTMFDetection);

  DEF_CMD("set", SCSetAction);
  DEF_CMD("sets", SCSetSAction);
  DEF_CMD("eval", SCEvalAction);
  DEF_CMD("setVar", SCSetVarAction);
  DEF_CMD("var", SCGetVarAction);
  DEF_CMD("append", SCAppendAction);
  DEF_CMD("substr", SCSubStrAction);
  DEF_CMD("inc", SCIncAction);
  DEF_CMD("log", SCLogAction);
  DEF_CMD("clear", SCClearAction);
  DEF_CMD("logVars", SCLogVarsAction);
  DEF_CMD("logParams", SCLogParamsAction);
  DEF_CMD("logSelects", SCLogSelectsAction);
  DEF_CMD("logAll", SCLogAllAction);

  DEF_CMD("setTimer", SCSetTimerAction);
  DEF_CMD("removeTimer", SCRemoveTimerAction);
  DEF_CMD("removeTimers", SCRemoveTimersAction);

  DEF_CMD("setPrompts", SCSetPromptsAction);

  DEF_CMD("postEvent", SCPostEventAction);

  if (cmd == "DI") {
    SCDIAction * a = new SCDIAction(params, false);
    a->name = from_str;
    return a;
  }  

  if (cmd == "DIgetResult") {
    SCDIAction * a = new SCDIAction(params, true);
    a->name = from_str;
    return a;
  }  

  DEF_CMD("B2B.connectCallee", SCB2BConnectCalleeAction);
  DEF_CMD("B2B.terminateOtherLeg", SCB2BTerminateOtherLegAction);
  DEF_CMD("B2B.sendReinvite", SCB2BReinviteAction);
  DEF_CMD("B2B.addHeader", SCB2BAddHeaderAction);
  DEF_CMD("B2B.clearHeaders", SCB2BClearHeadersAction);
  DEF_CMD("B2B.setHeaders", SCB2BSetHeadersAction);

  return NULL;
}
Exemplo n.º 8
0
DSMCondition* DSMCoreModule::getCondition(const string& from_str) {
  string cmd;
  string params;
  splitCmd(from_str, cmd, params);

  if (cmd == "keyPress") {
    DSMCondition* c = new DSMCondition();
    c->name = "key pressed: " + params;
    c->type = DSMCondition::Key;
    c->params["key"] = params;
    return c;
  }

  if (cmd == "test")
    return new TestDSMCondition(params, DSMCondition::Any);

  if (cmd == "keyTest") 
    return new TestDSMCondition(params, DSMCondition::Key);

  if (cmd == "timerTest") 
    return new TestDSMCondition(params, DSMCondition::Timer);

  if (cmd == "noAudioTest") 
    return new TestDSMCondition(params, DSMCondition::NoAudio);

  if (cmd == "separatorTest") 
    return new TestDSMCondition(params, DSMCondition::PlaylistSeparator);

  if (cmd == "hangup") 
    return new TestDSMCondition(params, DSMCondition::Hangup);  

  if (cmd == "eventTest") 
    return new TestDSMCondition(params, DSMCondition::DSMEvent);  

  if (cmd == "invite") 
    return new TestDSMCondition(params, DSMCondition::Invite);  

  if (cmd == "sessionStart") 
    return new TestDSMCondition(params, DSMCondition::SessionStart);  

  if (cmd == "ringing") 
    return new TestDSMCondition(params, DSMCondition::Ringing);

  if (cmd == "early") 
    return new TestDSMCondition(params, DSMCondition::EarlySession);

  if (cmd == "failed") 
    return new TestDSMCondition(params, DSMCondition::FailedCall);  

  if (cmd == "B2B.otherReply") 
    return new TestDSMCondition(params, DSMCondition::B2BOtherReply);  

  if (cmd == "B2B.otherBye") 
    return new TestDSMCondition(params, DSMCondition::B2BOtherBye);  

  if (cmd == "sipRequest") 
    return new TestDSMCondition(params, DSMCondition::SipRequest);  

  if (cmd == "sipReply") 
    return new TestDSMCondition(params, DSMCondition::SipReply);  

  return NULL;
}
DSMCondition* DSMCoreModule::getCondition(const string& from_str) {
  string cmd;
  string params;
  splitCmd(from_str, cmd, params);

  if (cmd == "keyPress") {
    DSMCondition* c = new DSMCondition();
    c->name = "key pressed: " + params;
    c->type = DSMCondition::Key;
    c->params["key"] = params;
    return c;
  }

  if (cmd == "test")
    return new TestDSMCondition(params, DSMCondition::Any);

  if ((cmd == "keyTest") || (cmd == "key"))
    return new TestDSMCondition(params, DSMCondition::Key);

  if ((cmd == "timerTest") || (cmd == "timer"))
    return new TestDSMCondition(params, DSMCondition::Timer);

  if ((cmd == "noAudioTest") || (cmd == "noAudio"))
    return new TestDSMCondition(params, DSMCondition::NoAudio);

  if ((cmd == "separatorTest") || (cmd == "separator"))
    return new TestDSMCondition(params, DSMCondition::PlaylistSeparator);

  if (cmd == "hangup") 
    return new TestDSMCondition(params, DSMCondition::Hangup);  

  if ((cmd == "eventTest") || (cmd == "event"))
    return new TestDSMCondition(params, DSMCondition::DSMEvent);  

  if (cmd == "invite") 
    return new TestDSMCondition(params, DSMCondition::Invite);  

  if (cmd == "earlySession")
    return new TestDSMCondition(params, DSMCondition::EarlySession);

  if (cmd == "sessionStart") 
    return new TestDSMCondition(params, DSMCondition::SessionStart);  

  if (cmd == "ringing") 
    return new TestDSMCondition(params, DSMCondition::Ringing);

  if (cmd == "early") 
    return new TestDSMCondition(params, DSMCondition::EarlySession);

  if (cmd == "failed") 
    return new TestDSMCondition(params, DSMCondition::FailedCall);  

  if (cmd == "B2B.otherReply") 
    return new TestDSMCondition(params, DSMCondition::B2BOtherReply);  

  if (cmd == "B2B.otherBye") 
    return new TestDSMCondition(params, DSMCondition::B2BOtherBye);  

  if (cmd == "sipRequest") 
    return new TestDSMCondition(params, DSMCondition::SipRequest);  

  if (cmd == "sipReply") 
    return new TestDSMCondition(params, DSMCondition::SipReply);  

  if (cmd == "remoteDisappeared") 
    return new TestDSMCondition(params, DSMCondition::RemoteDisappeared);  

  if (cmd == "sessionTimeout")
    return new TestDSMCondition(params, DSMCondition::SessionTimeout);

  if (cmd == "rtpTimeout")
    return new TestDSMCondition(params, DSMCondition::RtpTimeout);

  if (cmd == "jsonRpcRequest") 
    return new TestDSMCondition(params, DSMCondition::JsonRpcRequest);  

  if (cmd == "jsonRpcResponse") 
    return new TestDSMCondition(params, DSMCondition::JsonRpcResponse);  

  if (cmd == "subscription")
    return new TestDSMCondition(params, DSMCondition::SIPSubscription);

  if (cmd == "startup")
    return new TestDSMCondition(params, DSMCondition::Startup);

  if (cmd == "reload")
    return new TestDSMCondition(params, DSMCondition::Reload);

  if (cmd == "system")
    return new TestDSMCondition(params, DSMCondition::System);

  if (cmd == "rtpTimeout")
    return new TestDSMCondition(params, DSMCondition::RTPTimeout);

  return NULL;
}
Exemplo n.º 10
0
/*
 * getCommand
 *
 * arguments:
 *   char *cmdLine: pointer to the command line string
 *
 * returns: commandT*: pointer to the commandT struct generated by
 *                     parsing the cmdLine string
 *
 * This parses the command line string, and returns a commandT struct,
 * as defined in runtime.h.  You must free the memory used by commandT
 * using the freeCommand function after you are finished.
 *
 * This function tokenizes the input, preserving quoted strings. It
 * supports escaping quotes and the escape character, '\'.
 */
commandT*
getCommand(char* cmdLine)
{
  //printf("here");
  char* restOfLine = (char*)malloc(sizeof(char)*BUFSIZE);
  //char* restCmdLine = (char*)malloc(sizeof(char)*BUFSIZE);

  commandT* cmd = malloc(sizeof(commandT) + sizeof(char*) * MAXARGS);
  cmd->argv[0] = 0;
  cmd->name = 0;
  cmd->argc = 0;
  cmd->piped = FALSE;
  cmd->next=NULL;
 
  int i, inArg = 0;
  char quote = 0;
  char escape = 0;

  // Set up the initial empty argument
  char* tmp = malloc(sizeof(char*) * BUFSIZE);
  int tmpLen = 0;
  tmp[0] = 0;

  //For aliasing:
  //aliasL* alias;
  char* keptString = 0; 
  //printf("parsing:%s\n", cmdLine);

  for (i = 0; cmdLine[i] != 0; i++)
    {
      //printf("\tindex %d, char %c\n", i, cmdLine[i]);

      // Check for whitespace
      if (cmdLine[i] == ' ')
        {
          if (inArg == 0)
            continue;
          if (quote == 0)
            {
              // End of an argument
              cmd->argv[cmd->argc] = malloc(sizeof(char) * (tmpLen + 1));
              strcpy(cmd->argv[cmd->argc], tmp);
              
	      //Get rest of command to add on to expanded command of alias
              if(cmd->argc==0){
                 if(isAlias(cmd->argv[0])){
                     alias=getAlias(cmd->argv[0]);
                     if(alias->found == FALSE){
                     keptString = splitCmd(cmdLine, i, restOfLine);
                     //printf("The rest of the string is: %s\n", keptString);
                     } 
                 }
              }
              

              inArg = 0;
              tmp[0] = 0;
              tmpLen = 0;
              cmd->argc++;
              cmd->argv[cmd->argc] = 0;
              continue;
            }
        }

      // If we get here, we're in text or a quoted string
      inArg = 1;

      // Start or end quoting.
      if (cmdLine[i] == '\'' || cmdLine[i] == '"')
        {
          if (escape != 0 && quote != 0 && cmdLine[i] == quote)
            {
              // Escaped quote. Add it to the argument.
              tmp[tmpLen++] = cmdLine[i];
              tmp[tmpLen] = 0;
              escape = 0;
              continue;
            }

          if (quote == 0)
            {
              //printf("\t\tstarting quote around %c\n", cmdLine[i]);
              quote = cmdLine[i];
              continue;
            }
          else
            {
              if (cmdLine[i] == quote)
                {
                  //printf("\t\tfound end quote %c\n", quote);
                  quote = 0;
                  continue;
                }
            }
        }

      // Handle escape character repeat
      if (cmdLine[i] == '\\' && escape == '\\')
        {
          escape = 0;
          tmp[tmpLen++] = '\\';
          tmp[tmpLen] = 0;
          continue;
        }

      // Handle single escape character followed by a non-backslash or quote character
      if (escape == '\\')
        {
          if (quote != 0)
            {
              tmp[tmpLen++] = '\\';
              tmp[tmpLen] = 0;
            }
          escape = 0;
        }

      // Set the escape flag if we have a new escape character sequence.
      if (cmdLine[i] == '\\')
        {
          escape = '\\';
          continue;
        }
      
      if(cmdLine[i] =='|'){
          cmd->piped =TRUE;
          i+=2;
          char* nextCmd = splitCmd(cmdLine, i, restOfLine);
          pipeSeq(nextCmd, cmd);
          //printf("%s\n",nextCmd);
          //cmd->piped =TRUE;
          //printf("Piped is %b\n", cmd->piped);
          break;
      }
      
      tmp[tmpLen++] = cmdLine[i];
      tmp[tmpLen] = 0;
    }

  
  // End the final argument, if any.
  if (tmpLen > 0)
    {
      //printf("\t\tend of argument %d, got:%s\n", cmd.argc, tmp);
      cmd->argv[cmd->argc] = malloc(sizeof(char) * (tmpLen + 1));
      strcpy(cmd->argv[cmd->argc], tmp);
      //cmd->next=0;
      inArg = 0;
      tmp[0] = 0;
      tmpLen = 0;
      cmd->argc++;
      cmd->argv[cmd->argc] = 0;
      //If input is an alias call expanded command
      if(isAlias(cmd->argv[0])){
         alias=getAlias(cmd->argv[0]);
         if(alias->found == FALSE){
        
	  char* concat = concatCmd(alias->origName, keptString); 
	  alias->found=TRUE;      
	  cmd = getCommand(concat);
	  alias->found=FALSE;
	  //free(concat);
         }
            
        // alias->found=FALSE;
      }
      
    }

  free(tmp);
  //TODO Maybe we Need the cmd Line?
  free(restOfLine);
  //free(restCmdLine);
  cmd->name = cmd->argv[0];

  return cmd;
} /* getCommand */