コード例 #1
0
ファイル: datastore_cmd.c プロジェクト: 1514louluo/lagopus
static inline lagopus_result_t
s_current_all(lagopus_dstring_t *result) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  char *bindaddr_str = NULL;
  const char *protocol = NULL;
  const char *tls_str = NULL;

  ret = lagopus_ip_address_str_get(s_bindaddr, &bindaddr_str);
  if (ret == LAGOPUS_RESULT_OK) {
    if (session_type_is_tcp(s_protocol) == true) {
      protocol = "tcp";
    } else if (session_type_is_tcp6(s_protocol) == true) {
      protocol = "tcp6";
    } else {
      return datastore_json_result_setf(result,
                                        LAGOPUS_RESULT_NOT_DEFINED,
                                        "Can't get protocol value: %x",
                                        s_protocol);
    }

    if (s_tls == true) {
      tls_str = "true";
    } else {
      tls_str = "false";
    }

    ret = datastore_json_result_setf(result,
                                     LAGOPUS_RESULT_OK,
                                     "[{\"addr\":\"%s\",\n"
                                     "\"port\":\"%u\",\n"
                                     "\"protocol\":\"%s\",\n"
                                     "\"tls\":\"%s\"}]",
                                     bindaddr_str,
                                     s_port,
                                     protocol,
                                     tls_str);

    free((void *) bindaddr_str);
    return ret;
  } else {
    return datastore_json_result_setf(result,
                                      ret,
                                      "Can't get addr value.");
  }
}
コード例 #2
0
ファイル: datastore_cmd.c プロジェクト: 1514louluo/lagopus
static inline lagopus_result_t
s_current_addr(lagopus_dstring_t *result) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  char *bindaddr_str = NULL;

  ret = lagopus_ip_address_str_get(s_bindaddr, &bindaddr_str);
  if (ret != LAGOPUS_RESULT_OK) {
    ret = datastore_json_result_setf(result,
                                     ret,
                                     "Can't get addr.");
  }
  ret = datastore_json_result_setf(result, ret,
                                   "[{\"addr\":\"%s\"}]",
                                   bindaddr_str);

  free((void *) bindaddr_str);
  return ret;
}
コード例 #3
0
ファイル: datastore_cmd.c プロジェクト: 1514louluo/lagopus
static inline lagopus_result_t
s_current_port(lagopus_dstring_t *result) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;

  ret = datastore_json_result_setf(result,
                                   LAGOPUS_RESULT_OK,
                                   "[{\"port\":%u}]",
                                   s_port);

  return ret;
}
コード例 #4
0
ファイル: datastore_cmd.c プロジェクト: 1514louluo/lagopus
static inline lagopus_result_t
s_current_protocol(lagopus_dstring_t *result) {
  const char *protocol = NULL;

  if (session_type_is_tcp(s_protocol) == true) {
    protocol = "tcp";
  } else if (session_type_is_tcp6(s_protocol) == true) {
    protocol = "tcp6";
  } else {
    return datastore_json_result_setf(result,
                                      LAGOPUS_RESULT_NOT_DEFINED,
                                      "Can't get protocol value: %x",
                                      s_protocol);
  }

  return datastore_json_result_setf(result,
                                    LAGOPUS_RESULT_OK,
                                    "[{\"protocol\":\"%s\"}]",
                                    protocol);
}
コード例 #5
0
ファイル: datastore_cmd.c プロジェクト: 1514louluo/lagopus
static inline lagopus_result_t
s_current_tls(lagopus_dstring_t *result) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  const char *tls_str = NULL;

  if (s_tls == true) {
    tls_str = "true";
  } else {
    tls_str = "false";
  }
  ret = datastore_json_result_setf(result,
                                   LAGOPUS_RESULT_OK,
                                   "[{\"tls\":\"%s\"}]",
                                   tls_str);

  return ret;
}
コード例 #6
0
ファイル: snmp_cmd.c プロジェクト: JackieXie168/lagopus
static inline lagopus_result_t
s_parse_snmp_internal(const char *const argv[],
                      lagopus_dstring_t *result) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  char *agentx_sock = NULL;
  char *esc_agentx = NULL;
  char *ping = NULL;

  while (IS_VALID_STRING(*argv) == true) {
    if (strcmp(*argv, "-master-agentx-socket") == 0) {
      if (IS_VALID_STRING(*(argv + 1)) == true) {
        argv++;
        if ((ret = lagopus_str_unescape(*argv, "\"'", &agentx_sock))
            > 0) {

          if ((ret = lagopus_snmp_set_agentx_sock(agentx_sock))
              != LAGOPUS_RESULT_OK) {
            ret = datastore_json_result_string_setf(result, ret,
                                                    "Can't set %s.",
                                                    agentx_sock);
            goto done;
          }

        } else if (ret == 0) {
          ret = datastore_json_result_string_setf(result,
                                                  LAGOPUS_RESULT_INVALID_ARGS,
                                                  "Bad opt val = %s ",
                                                  *argv);
          goto done;
        } else {
          ret = datastore_json_result_string_setf(result, ret,
                                                  "Can't convert to an "
                                                  "unescaped strings.");
          goto done;
        }
      } else {

        if ((ret = lagopus_snmp_get_agentx_sock(&agentx_sock))
            == LAGOPUS_RESULT_OK) {
          ret = datastore_json_string_escape(agentx_sock,
                                             (char **)&esc_agentx);
          if (ret == LAGOPUS_RESULT_OK) {
            ret = datastore_json_result_setf(result, ret, "[{"
                                             "\"master-agentx-socket\":\"%s\""
                                             "}]", esc_agentx);
            goto done;
          } else {
            ret = datastore_json_result_string_setf(result, ret,
                                                    "Can't convert to "
                                                    "an escaped strings.");
            goto done;
          }
        } else {
          ret = datastore_json_result_string_setf(result, ret,
                                                  "Can't get "
                                                  "master-agentx-socket.");
          goto done;
        }
      }

    } else if (strcmp(*argv, "-ping-interval-second") == 0) {

      if (IS_VALID_STRING(*(argv + 1)) == true) {
        argv++;
        ret = lagopus_str_unescape(*argv, "\"'", &ping);
        if (ret > 0) {
          uint16_t new_ping;
          ret = lagopus_str_parse_uint16(ping, &new_ping);
          if (ret == LAGOPUS_RESULT_OK) {
            if ((ret = lagopus_snmp_set_ping_interval(new_ping))
                != LAGOPUS_RESULT_OK) {
              ret = datastore_json_result_string_setf(result, ret,
                                                      "Can't set "
                                                      "ping-interval.");

              goto done;
            }
          } else {
            ret = datastore_json_result_string_setf(result, ret,
                                                    "Can't parse string "
                                                    "to uint16_t.");
            goto done;
          }
        } else if (ret == 0) {
          ret = datastore_json_result_string_setf(result,
                                                  LAGOPUS_RESULT_INVALID_ARGS,
                                                  "Bad opt val = %s ",
                                                  *argv);
          goto done;
        } else {
          ret = datastore_json_result_string_setf(result, ret,
                                                  "Can't convert to an "
                                                  "unescaped strings.");
          goto done;
        }
      } else {
        uint16_t ping_interval;
        ret = lagopus_snmp_get_ping_interval(&ping_interval);
        if (ret == LAGOPUS_RESULT_OK) {
          ret = datastore_json_result_setf(result, ret, "[{"
                                           "\"ping-interval-second\":%d"
                                           "}]", ping_interval);
          goto done;
        } else {
          ret = datastore_json_result_string_setf(result, ret,
                                                  "Can't get "
                                                  "ping-interval-second.");
          goto done;
        }
      }

    } else if (strcmp(*argv, "enable") == 0) {
      if ((ret = lagopus_snmp_set_enable(true))
          != LAGOPUS_RESULT_OK) {
        ret = datastore_json_result_string_setf(result, ret,
                                                "Can't set enable.");
        goto done;
      }
    } else {
      char *esc_str = NULL;
      ret = datastore_json_string_escape(*argv, (char **)&esc_str);
      if (ret == LAGOPUS_RESULT_OK) {
        ret = datastore_json_result_string_setf(result, LAGOPUS_RESULT_NOT_FOUND,
                                                "option = %s",
                                                esc_str);
      }
      free((void *)esc_str);
    }

 done:
    free((void *)agentx_sock);
    free((void *)esc_agentx);
    free((void *)ping);
    agentx_sock = NULL;
    esc_agentx = NULL;
    ping = NULL;

    if (ret != LAGOPUS_RESULT_OK) {
      break;
    }
    argv++;
  }

  if (ret == LAGOPUS_RESULT_OK &&
      lagopus_dstring_empty(result)) {
    ret = lagopus_dstring_appendf(result, "{\"ret\":\"OK\"}");
    if (ret != LAGOPUS_RESULT_OK) {
      ret = datastore_json_result_string_setf(result, ret,
                                              "Can't add strings "
                                              "to dstring.");
    }
  }

  return ret;
}
コード例 #7
0
ファイル: snmp_cmd.c プロジェクト: JackieXie168/lagopus
static inline lagopus_result_t
s_parse_snmp_show(lagopus_dstring_t *result) {
  lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES;
  bool enable = false;
  uint16_t ping_interval;
  char *agentx_sock = NULL;
  char *esc_sock = NULL;

  if ((ret = lagopus_snmp_get_agentx_sock(&agentx_sock))
      == LAGOPUS_RESULT_OK) {
    ret = datastore_json_string_escape(agentx_sock,
                                       (char **)&esc_sock);
    if (ret != LAGOPUS_RESULT_OK) {
      ret = datastore_json_result_string_setf(result, ret,
                                              "Can't convert "
                                              "to an unescaped strings.");
      goto done;
    }
  } else {
    ret = datastore_json_result_string_setf(result, ret,
                                            "Can't get "
                                            "master-agentx-socket.");
    goto done;
  }

  if ((ret = lagopus_snmp_get_ping_interval(&ping_interval))
      == LAGOPUS_RESULT_OK) {
    if (ping_interval > MAXIMUM_PING_SEC) {
      ret = datastore_json_result_string_setf(result,
                                              LAGOPUS_RESULT_TOO_LONG,
                                              "ping-interval-second "
                                              "must be smaller than 256.");
      goto done;
    } else if (ping_interval < MINIMUM_PING_SEC) {
      ret = datastore_json_result_string_setf(result,
                                              LAGOPUS_RESULT_TOO_SHORT,
                                              "ping-interval-second "
                                              "must be greater than zero.");
      goto done;
    } else {
      if ((ret = lagopus_snmp_get_enable(&enable))
          == LAGOPUS_RESULT_OK) {
        ret = datastore_json_result_setf(result, ret, "[{"
                                         "\"master-agentx-socket\":\"%s\",\n"
                                         "\"ping-interval-second\":%d,\n"
                                         "\"is-enabled\":%s"
                                         "}]",
                                         esc_sock,
                                         ping_interval,
                                         IS_ENABLED(enable));
      } else {
        ret = datastore_json_result_string_setf(result, ret,
                                                "Can't get enable.");
      }
    }
  } else {
    ret = datastore_json_result_string_setf(result, ret,
                                            "Can't get "
                                            "ping-interval-second.");
  }

done:
  free((void *)agentx_sock);
  free((void *)esc_sock);

  return ret;
}