示例#1
0
void init_conf(struct v7 *v7) {
  /* TODO(alashkin): make the filename overridable */
  const char *conf_file_name = "smartjs.conf";
  FILE *fconf = NULL;
  struct stat st;
  char *buf = NULL;

  if ((fconf = fopen(conf_file_name, "r")) == NULL ||
      stat(conf_file_name, &st) == -1) {
    printf("Cannot open %s\n", conf_file_name);
    return;
  }

  buf = calloc(st.st_size + 1, 1);

  if (fread(buf, 1, st.st_size, fconf) != st.st_size) {
    printf("Cannot read %s\n", conf_file_name);
    goto cleanup;
  }

  sj_init_conf(v7, buf);

cleanup:
  if (fconf != NULL) {
    fclose(fconf);
  }

  if (buf != NULL) {
    free(buf);
  }
}
示例#2
0
void esp_init_conf(struct v7 *v7) {
#ifndef RTOS_TODO
  int valid;
  unsigned char sha[20];
  cs_sha1_ctx ctx;
  cs_sha1_init(&ctx);
  cs_sha1_update(&ctx, (unsigned char *) V7_DEV_CONF_STR,
                 strnlen(V7_DEV_CONF_STR, 0x1000 - 20));
  cs_sha1_final(sha, &ctx);

  valid = (memcmp(V7_DEV_CONF_SHA1, sha, 20) == 0);

  sj_init_conf(v7, valid ? V7_DEV_CONF_STR : NULL);
#else
  sj_init_conf(v7, NULL);
#endif
}