Beispiel #1
0
void user_init(void)
{
    spiffs_fs1_init();

	ssc_attach(SSC_BR_74880);
    ssc_register(sscCmdSet, SSC_CMD_N, spiffs_test_help);
}
static void sofsip_handle_input_cb(char *input)
{
  //printf("INPUT: %s", input);
  char *rest, *command = input;
  cli_t *cli = global_cli_p;
  int n = command ? (int)strlen(command) : 0;
  char msgbuf[160] = "";

  /* see readline(2) */
  if (input == NULL) {
    ssc_shutdown(cli->cli_ssc);
    return;
  }

#define is_ws(c) ((c) != '\0' && strchr(" \t\r\n", (c)) != NULL)

  /* Skip whitespace at the end of line */
  while (n > 0 && is_ws(command[n - 1]))
    n--;
  command[n] = 0;
  /* Skip whitespace at the beginning of line */
  while (is_ws(*command))
    command++;

  ssc_input_add_history(command);

  /* Search first whitespace character */
  for (rest = command; *rest && !is_ws(*rest); rest++)
    ;
  /* Search non-whitespace and zero the whitespace */
  while (rest < command + n && is_ws(*rest)) {
    *rest = 0;
    rest += 1;
  }
  if (rest >= command + n || !*rest)
    rest = NULL;

#define MATCH(c) (strcmp(command, c) == 0)
#define match(c) (strcasecmp(command, c) == 0)

  cli->cli_prompt = 0;

  if (match("a") || match("answer")) {
    ssc_answer(cli->cli_ssc, SIP_200_OK);
  }
  else if (match("addr")) {
    ssc_set_public_address(cli->cli_ssc, rest);
  }
  else if (match("b") || match("bye")) {
    ssc_bye(cli->cli_ssc);
  }
  else if (match("c") || match("cancel")) {
    ssc_cancel(cli->cli_ssc);
  }
  else if (MATCH("d")) {
    ssc_answer(cli->cli_ssc, SIP_480_TEMPORARILY_UNAVAILABLE);
  }
  else if (MATCH("D")) {
    ssc_answer(cli->cli_ssc, SIP_603_DECLINE);
  }
  else if (match("h") || match("help")) {
    sofsip_help(cli);
  }
  else if (match("i") || match("invite")) {
    ssc_invite(cli->cli_ssc, rest);
  }
  else if (match("info")) {
    ssc_input_set_prompt("Enter INFO message> ");
    ssc_input_read_string(msgbuf, sizeof(msgbuf));
    ssc_info(cli->cli_ssc, rest, msgbuf);
  }
  else if (match("hold")) {
    ssc_hold(cli->cli_ssc, rest, 1);
  }   
  else if (match("unhold")) {
    ssc_hold(cli->cli_ssc, rest, 0);
  }   
  else if (match("k") || match("key")) {
    ssc_auth(cli->cli_ssc, rest);
  }
  else if (match("l") || match("list")) {
    ssc_list(cli->cli_ssc);
  }
  else if (match("m") || match("message") || match("webrtc-sdp") || match("webrtc-sdp-called")) {
    // 'rest' contains the destination and the message, delimited by a whitespace
    char * token, * dest = NULL;
    int pos = 0;
    while ((token = strsep(&rest, " ")) != NULL) {
        if (pos == 0) {
            dest = token;
            break;
        }
        printf("%s\n", token);
       pos++;
    }
    if (match("m") || match("message")) {
       ssc_message(cli->cli_ssc, dest, rest);
    }
#if HAVE_MEDIA_WEBRTC_IMPL
    if (match("webrtc-sdp")) {
       void * op_context = NULL;
       // convert address string to pointer, which is the Sofia operation handle
       sscanf(dest, "%p", (void **)&op_context);
       ssc_webrtc_sdp(op_context, rest);
    }
    if (match("webrtc-sdp-called")) {
       void * op_context = NULL;
       // convert address string to pointer, which is the Sofia operation handle
       sscanf(dest, "%p", (void **)&op_context);
       ssc_webrtc_sdp_called(op_context, rest);


    }
#endif
  }
  else if (match("set")) {
    ssc_print_settings(cli->cli_ssc);
  }
  else if (match("s") || match("subscribe")) {
    ssc_subscribe(cli->cli_ssc, rest);
  }
  else if (match("w") || match("watch")) {
    ssc_watch(cli->cli_ssc, rest);
  }
  else if (match("o") || match("options")) {
    ssc_options(cli->cli_ssc, rest);
  }
  else if (match("p") || match("publish")) {
    ssc_publish(cli->cli_ssc, rest);
  }
  else if (match("up") || match("unpublish")) {
    ssc_unpublish(cli->cli_ssc);
  }
  else if (match("r") || match("register")) {
    /* XXX: give AOR as param, and optionally a different registrar */
    ssc_register(cli->cli_ssc, rest);
  }
  else if (MATCH("u") || match("unregister")) {
    ssc_unregister(cli->cli_ssc, rest);
  }
  else if (match("ref") || match("refer")) {
    ssc_input_set_prompt("Enter refer_to address: ");
    ssc_input_read_string(msgbuf, sizeof(msgbuf));
    ssc_refer(cli->cli_ssc, rest, msgbuf);
  }
  else if (MATCH("U") || match("us") || match("unsubscribe")) {
    ssc_unsubscribe(cli->cli_ssc, rest);
  }
  else if (match("z") || match("zap")) {
    ssc_zap(cli->cli_ssc, rest);
  }
  else if (match("q") || match("x") || match("exit")) {
    ssc_shutdown(cli->cli_ssc);
  } 
  else if (command[strcspn(command, " \t\n\r=")] == '=') {
    /* Test assignment: foo=bar  */
    if ((rest = strchr(command, '='))) {
      cli->cli_prompt = 0;
      *rest++ = '\0';
      ssc_param(cli->cli_ssc, command, rest);
    }
  } 
  else if (match("?") || match("h") || match("help")) {
    sofsip_help(cli);
  }
  else {
    printf("Unknown command. Type \"help\" for help\n");
  }

  ssc_input_set_prompt(SOFSIP_PROMPT);
  free(input);
}