Пример #1
0
int
boot_(Module m)
{
  char* dummy = NULL;

  controller_init(&rwcli_controller);

  // Authenticate in case of RW.MSG mode
  rwcli_user_mode_t user_mode = RWCLI_USER_MODE_NONE;
  if (rwcli_controller.agent_type == RWCLI_TRANSPORT_MODE_RWMSG) {
    user_mode = rift_authenticate(&rift_cmdargs);
    if (user_mode == RWCLI_USER_MODE_INVALID) {
      printf("\nERROR: Invalid username/password\n");
      exit(-1);
    }
  }

  rwcli_zsh_plugin_init(rwcli_controller.agent_type, user_mode);
  rwcli_set_messaging_hook(messaging_hook);
  rwcli_set_history_hook(history_hook);

  // Always load the rwmsg_agent module, If netconf is enabled then 
  // this module will only receive logging notifications
  if (load_module("zsh/rwmsg_agent", NULL, 0) != 0) {
    printf("\nCRITICAL: Loading the messaging agent module failed\n");
    fflush(stdout);
    return -1;
  }

  // Load the agent that is required
  if (rwcli_controller.agent_type == RWCLI_TRANSPORT_MODE_NETCONF) {
    if (load_module("zsh/rwnetconf_agent", NULL, 0) != 0) {
      printf("\nCRITICAL: Loading the netconf agent module failed\n");
      fflush(stdout);
      return -1;
    }
    rwcli_controller.is_netconf_agent_loaded = true;
  }

  /* Register the completion widget */
  rwcli_controller.w_comp = addzlefunction("rift-complete", rift_complete, 0);
  Keymap km = openkeymap("main");
  rwcli_controller.t_orig_tab_bind = keybind(km, "\t", &dummy);
  bindkey(km, "\t", refthingy(rwcli_controller.w_comp->first), NULL);

  /* Bind ? to generate help */
  rwcli_controller.w_gen_help = addzlefunction("rift-gen-help", 
                                      rift_generate_help, 0);
  bindkey(km, "?", refthingy(rwcli_controller.w_gen_help->first), NULL);

  /* Set the lookup hook */
  rw_lookup_fn = rift_lookup;

  /* Set the prompt hook */
  addprepromptfn(rift_prompt);

  return 0;
}
Пример #2
0
int
boot_(Module m)
{
  char* dummy = NULL;

  // Initialize the trace module and set appropriate severity
  rift_init_trace();

  recv_buf = (uint8_t*)calloc(sizeof(uint8_t), RW_CLI_MAX_BUF);
  recv_buf_len = RW_CLI_MAX_BUF;
  
  // Decide the RW.CLI communication mode with RW.MgmtAgent
  if (rift_cmdargs.use_netconf == -1) {
    const char* agent_mode = rw_getenv("RWMGMT_AGENT_MODE");
    if (agent_mode && strcmp(agent_mode, "XML") == 0) {
      // If the agent mode is XML only RW.MSG mode is possible. Override the
      // command line option for netconf and opt for RW.MSG mode.
      rift_cmdargs.use_netconf = 0;
    } else {
      // Transport mode not chosen in command line and not XML mode. Choose
      // Netconf mode by default.
      rift_cmdargs.use_netconf = 1;
    }
  }

  // Authenticate in case of RW.MSG mode
  rwcli_transport_mode_t transport_mode =  RWCLI_TRANSPORT_MODE_NETCONF;
  rwcli_user_mode_t user_mode = RWCLI_USER_MODE_NONE;
  if (!rift_cmdargs.use_netconf) {
    user_mode = rift_authenticate(&rift_cmdargs);
    if (user_mode == RWCLI_USER_MODE_INVALID) {
      printf("\nERROR: Invalid username/password\n");
      exit(-1);
    }
    transport_mode = RWCLI_TRANSPORT_MODE_RWMSG;
  }

  rwcli_zsh_plugin_init(transport_mode, user_mode);
  rwcli_set_messaging_hook(messaging_hook);
  rwcli_set_history_hook(history_hook);

  // To support background processes and job control, there should
  // be multiple channels available
  msg_channel_init(&rwcli_agent_ch);
  msg_channel_create(&rwcli_agent_ch);

  // Always load the rwmsg_agent module, If netconf is enabled then 
  // this module will only receive logging notifications
  if (load_module("zsh/rwmsg_agent", NULL, 0) != 0) {
    printf("\nCRITICAL: Loading the messaging agent module failed\n");
    fflush(stdout);
    return -1;
  }

  // Load the agent that is required
  if (rift_cmdargs.use_netconf) {
    if (load_module("zsh/rwnetconf_agent", NULL, 0) != 0) {
      printf("\nCRITICAL: Loading the netconf agent module failed\n");
      fflush(stdout);
      return -1;
    }
  }
  /* Register the completion widget */
  w_comp = addzlefunction("rift-complete", rift_complete, 0);
  Keymap km = openkeymap("main");
  t_orig_tab_bind = keybind(km, "\t", &dummy);
  bindkey(km, "\t", refthingy(w_comp->first), NULL);

  /* Bind ? to generate help */
  w_gen_help = addzlefunction("rift-gen-help", rift_generate_help, 0);
  bindkey(km, "?", refthingy(w_gen_help->first), NULL);

  /* Set the lookup hook */
  rw_lookup_fn = rift_lookup;

  /* Set the prompt hook */
  addprepromptfn(rift_prompt);

  return 0;
}