Esempio n. 1
0
// =======================================================
// translate full phone number to work one
	void translate_phone_number(char *phone)
// =======================================================
{
char str[100];
int	 lpref;

// replace country prefix
	strcpy(str,get_cfg(CFG_PREFIX,"CountryPref",""));
	lpref=strlen(str);
	if (*str && !strncmp(phone,str,lpref))
	{
		strcpy(str,get_cfg(CFG_PREFIX,"CountryRepl",""));
		strcat(str,phone+lpref);
		strcpy(phone,str);
	}
// remove city prefix
	strcpy(str,get_cfg(CFG_PREFIX,"CityPref",""));
	lpref=strlen(str);
	if (*str && !strncmp(phone,str,lpref))
	{
		strcpy(str,phone+lpref);
		strcpy(phone,str);
	}
// add international prefix
	strcpy(str,get_cfg(CFG_PREFIX,"InternatPref",""));
	strcat(str,phone);
	strcpy(phone,str);
}
Esempio n. 2
0
static int console_flush_buffer(struct cache *cache) {
  LOG(LL_DEBUG, ("file id=%d", (int) s_last_file_id));
  int ret = 0, fn_len, files_count;
  FILE *file = NULL;

  files_count = cache->file_names.len / FILENAME_LEN;
  if (files_count >= get_cfg()->console.file_cache_max) {
    LOG(LL_ERROR, ("Out of space"));

    ret = -1;
    /* Game is over, no space to flash buffer */
    if (files_count == get_cfg()->console.file_cache_max) {
      mbuf_free(&cache->logs);
      mbuf_append(&cache->logs, s_out_of_space_msg,
                  sizeof(s_out_of_space_msg) - 1);
      /* Let write last phrase */
    } else {
      goto clean;
    }
  }

  char file_name[sizeof(LOG_FILENAME_BASE) + FILE_ID_LEN];
  fn_len = c_snprintf(file_name, sizeof(file_name), FILENAME_PATTERN,
                      LOG_FILENAME_BASE, s_last_file_id);

  if (fn_len != FILENAME_LEN - 1) {
    LOG(LL_ERROR, ("Wrong file name")); /* Internal error, should not happen */
    ret = -1;
    goto clean;
  }

  file = fopen(file_name, "w");
  if (file == NULL) {
    LOG(LL_ERROR, ("Failed to open %s", file_name));
    ret = -1;
    goto clean;
  }

  /* Put data */
  if (fwrite(cache->logs.buf, 1, cache->logs.len, file) != cache->logs.len) {
    LOG(LL_ERROR,
        ("Failed to write %d bytes to %s", (int) cache->logs.len, file_name));
    ret = -1;
    goto clean;
  }

  /* Using mbuf here instead of list to avoid memory overhead */
  mbuf_append(&cache->file_names, file_name, FILENAME_LEN);
  mbuf_free(&cache->logs);

  s_last_file_id++;
clean:
  if (file != NULL) {
    fclose(file);
  }
  return ret;
}
Esempio n. 3
0
ub_val_t clubby_proto_create_frame_base(struct ub_ctx *ctx, const char *dst) {
  ub_val_t frame = ub_create_object(ctx);
  ub_add_prop(ctx, frame, "src",
              ub_create_string(ctx, get_cfg()->clubby.device_id));
  ub_add_prop(ctx, frame, "key",
              ub_create_string(ctx, get_cfg()->clubby.device_psk));
  ub_add_prop(ctx, frame, "dst", ub_create_string(ctx, dst));

  return frame;
}
Esempio n. 4
0
/*
Perform general optimizaitions.
Basis step to do:
    1. Build control flow.
    2. Compute data flow dependence.
    3. Compute live expression info.

Optimizations to be performed:
    1. GCSE
    2. DCE
    3. RVI(register variable recog)
    4. IVR(induction variable elimination)
    5. CP(constant propagation)
    6. CP(copy propagation)
    7. SCCP (Sparse Conditional Constant Propagation).
    8. PRE (Partial Redundancy Elimination) with strength reduction.
    9. Dominator-based optimizations such as copy propagation,
        constant propagation and redundancy elimination using
        value numbering.
    10. Must-alias analysis, to convert pointer de-references
        into regular variable references whenever possible.
    11. Scalar Replacement of Aggregates, to convert structure
        references into scalar references that can be optimized
        using the standard scalar passes.
*/
bool Region::MiddleProcess(OptCtx & oc)
{
    if (g_opt_level != NO_OPT) {
        PassMgr * passmgr = get_pass_mgr();
        ASSERT0(passmgr);

        //Perform scalar optimizations.
        passmgr->performScalarOpt(oc);
    }

    ASSERT0(verifyRPO(oc));

    BBList * bbl = get_bb_list();
    if (bbl->get_elem_count() == 0) { return true; }

    SimpCtx simp;
    simp.set_simp_cf();
    simp.set_simp_array();
    simp.set_simp_select();
    simp.set_simp_land_lor();
    simp.set_simp_lnot();
    simp.set_simp_ild_ist();
    simp.set_simp_to_lowest_height();
    simplifyBBlist(bbl, &simp);
    if (g_cst_bb_list && SIMP_need_recon_bblist(&simp)) {
        if (reconstructBBlist(oc) && g_do_cfg) {
            //Before CFG building.
            get_cfg()->removeEmptyBB(oc);

            get_cfg()->rebuild(oc);

            //After CFG building, it is perform different
            //operation to before building.
            get_cfg()->removeEmptyBB(oc);

            get_cfg()->computeExitList();

            if (g_do_cdg) {
                ASSERT0(get_pass_mgr());
                CDG * cdg = (CDG*)get_pass_mgr()->registerPass(PASS_CDG);
                cdg->rebuild(oc, *get_cfg());
            }
        }
    }

    ASSERT0(verifyIRandBB(bbl, this));
    if (g_do_refine) {
        RefineCtx rf;
        refineBBlist(bbl, rf);
        ASSERT0(verifyIRandBB(bbl, this));
    }
    return true;
}
Esempio n. 5
0
int main(int argc, char *argv[]) {
    /* Simple forced bounds
    */
    char cfg_def[99][99];
    char cfg_stats[99][99];
    int n_cfg_def;
    int n_cfg_stats;
    
    get_cfg(cfg_def, &n_cfg_def);
    get_cfg(cfg_stats, &n_cfg_stats);
    verify_cfg(cfg_def, n_cfg_def, cfg_stats, n_cfg_stats);

    return 0;
}
Esempio n. 6
0
void Region::lowerIRTreeToLowestHeight(OptCtx & oc)
{
    SimpCtx simp;
    if (g_is_lower_to_pr_mode) {
        simp.set_simp_to_pr_mode();
    }

    if (g_do_ssa) {
        //Note if this flag enable,
        //AA may generate imprecise result.
        //TODO: use SSA info to improve the precision of AA.
        simp.set_simp_land_lor();
        simp.set_simp_lnot();
        simp.set_simp_cf();
    }

    //Simplify IR tree if it is needed.
    simplifyBBlist(get_bb_list(), &simp);

    if (SIMP_need_recon_bblist(&simp)) {
        //New BB boundary IR generated, rebuilding CFG.
        if (reconstructBBlist(oc)) {
            get_cfg()->rebuild(oc);
            get_cfg()->removeEmptyBB(oc);
            get_cfg()->computeExitList();
        }
    }

    if (SIMP_changed(&simp)) {
        //We perfer flow sensitive analysis as default.
        get_aa()->set_flow_sensitive(true);
        get_aa()->perform(oc);

        //The primary actions must do are computing IR reference
        //and reach def.
        UINT action = SOL_REACH_DEF|SOL_REF;

        if (g_do_ivr) {
            //IVR needs available reach def.
            action |= SOL_AVAIL_REACH_DEF;
        }

        //DU mananger may use the context info supplied by AA.
        get_du_mgr()->perform(oc, action);

        //Compute the DU chain.
        get_du_mgr()->computeMDDUChain(oc);
    }
}
Esempio n. 7
0
int sj_app_init(struct v7 *v7) {

  { /* Print a message using a value from config. */
    printf("Hello, %s!\n", get_cfg()->hello.who);
  }

  { /* Turn on LED. */
    sj_gpio_set_mode(GPIO, GPIO_MODE_OUTPUT, GPIO_PULL_FLOAT);
    sj_gpio_write(GPIO, GPIO_LEVEL_HIGH);
  }

  { /* Read a file. */
    FILE *fp = fopen("README.txt", "r");
    if (fp != NULL) {
      char buf[100];
      int n = fread(buf, 1, sizeof(buf), fp);
      if (n > 0) {
        fwrite(buf, 1, n, stdout);
      }
      fclose(fp);
    }
  }

  (void) v7;
  return MG_APP_INIT_SUCCESS;
}
Esempio n. 8
0
//write status message to heartbeat log file (if configured):
void heartbeat(const wxString& msg, bool always)
{
    static bool first = TRUE;
//    debug(1, "hb(%s) first? %d, always? %d", msg, first, always);
    if (first)
    {
        get_cfg();
        first = FALSE;
        //wxMessageBox("heartbeat first log="+cfg.logpath);
    }

    wxDateTime now = wxDateTime::Now();
//    debug(1, "cfg: path '%s', intv %d, max %d", cfg.logpath.c_str(), cfg.interval, cfg.maxents);
    if (cfg.logpath.IsEmpty()) return; //no logging
    if (!always)
    {
        wxTimeSpan elapsed = now.Subtract(state.latest);
        if (elapsed.GetMilliseconds() < cfg.interval) return; //not time to log yet
    }
    wxString linebuf = now.Format("[%F %T] ") + msg;
    append(linebuf);

    wxFile f;
    if (f.Open(cfg.logpath,wxFile::OpenMode::write))
    {
        f.Write(state.fifo);
        f.Close();
    }
    state.latest = now;
}
Esempio n. 9
0
void cc3200_console_putc(int fd, char c) {
  MAP_UARTCharPut(CONSOLE_UART, c);
#ifdef SJ_ENABLE_CLUBBY
  if (fd == 1 && get_cfg()->console.send_to_cloud) cc3200_console_cloud_putc(c);
#endif
  (void) fd;
}
Esempio n. 10
0
void cc3200_console_cloud_putc(char c) {
  if (s_cctx.in_console || !s_cctx.initialized) return;
  s_cctx.in_console = 1;
  /* If console is overfull, drop old message(s). */
  int max_buf = get_cfg()->console.mem_cache_size;
  while (s_cctx.buf.len >= max_buf) {
    int l = cc3200_console_next_msg_len();
    if (l == 0) {
      l = s_cctx.buf.len;
      s_cctx.msg_in_progress = 0;
    }
    mbuf_remove(&s_cctx.buf, l);
  }
  /* Construct valid JSON from the get-go. */
  if (!s_cctx.msg_in_progress) {
    /* Skip empty lines */
    if (c == '\n') goto out;
    mbuf_append(&s_cctx.buf, "{\"msg\":\"", 8);
    s_cctx.msg_in_progress = 1;
  }
  if (c == '"' || c == '\\') {
    mbuf_append(&s_cctx.buf, "\\", 1);
  }
  if (c >= 0x20) mbuf_append(&s_cctx.buf, &c, 1);
  if (c == '\n') {
    mbuf_append(&s_cctx.buf, "\"}\n", 3);
    s_cctx.msg_in_progress = 0;
  }
out:
  s_cctx.in_console = 0;
}
Esempio n. 11
0
struct mg_connection *clubby_proto_connect(
    struct mg_mgr *mgr, const char *server_address, const char *ssl_server_name,
    const char *ssl_ca_file, const char *ssl_client_cert_file, void *context) {
  LOG(LL_DEBUG, ("Connecting to %s", server_address));
  struct mg_connect_opts opts;
  memset(&opts, 0, sizeof(opts));

#ifdef MG_ENABLE_SSL
  if (strlen(server_address) > 6 && strncmp(server_address, "wss://", 6) == 0) {
    opts.ssl_server_name = (ssl_server_name && strlen(ssl_server_name) != 0)
                               ? ssl_server_name
                               : get_cfg()->clubby.ssl_server_name;
    opts.ssl_ca_cert = (ssl_ca_file && strlen(ssl_ca_file) != 0)
                           ? ssl_ca_file
                           : get_cfg()->clubby.ssl_ca_file;
    if (opts.ssl_ca_cert == NULL) {
      /* Use global CA file if clubby specific one is not set */
      opts.ssl_ca_cert = get_cfg()->tls.ca_file;
    }
    opts.ssl_cert = (ssl_client_cert_file && strlen(ssl_client_cert_file) != 0)
                        ? ssl_client_cert_file
                        : get_cfg()->clubby.ssl_client_cert_file;
  }
#else
  (void) ssl_server_name;
  (void) ssl_ca_file;
  (void) ssl_client_cert_file;
#endif

  struct mg_connection *nc =
      mg_connect_ws_opt(mgr, clubby_proto_handler, opts, server_address,
                        WS_PROTOCOL, "Sec-WebSocket-Extensions: " WS_PROTOCOL
                                     "-encoding; in=json; out=ubjson\r\n");
  if (nc == NULL) {
    LOG(LL_DEBUG, ("Cannot connect to %s", server_address));
    struct clubby_event evt;
    evt.ev = CLUBBY_NET_CONNECT;
    evt.net_connect.success = 0;
    evt.context = context;
    s_clubby_cb(&evt);
    return NULL;
  }

  nc->user_data = context;

  return nc;
}
Esempio n. 12
0
struct mg_str upload_fname(struct mg_connection *nc, struct mg_str fname) {
  struct mg_str res = {NULL, 0};
  if (sj_conf_check_access(fname, get_cfg()->http.upload_acl)) {
    res = fname;
  }
  return res;
  (void) nc;
}
 int insmodDevice(void)
{ 
        if(!get_cfg()){
                ALOGD("open fail!\n");
        }
               
        return 0;
}
Esempio n. 14
0
// ========================================================================
	BOOL cfg_ring::OnInitDialog()
// ========================================================================
{
CString str;
int  lng[]={
			IDC_STATIC1,
			IDC_STATIC2,
			IDC_STATIC3,
			IDC_STATIC4,
			IDC_STATIC5,
			IDC_DISABLE,
			IDC_STATIC6,
			IDC_STATIC7,
			IDC_STATIC9,
			IDC_STATIC11,
			IDC_STATIC8,
			IDC_STATIC10,
			IDC_FOR1,
			IDC_FOR2,
			IDC_STATIC12,
			};

    CDialog::OnInitDialog();
    set_dlg_language(this,DlgName,lng,sizeof(lng)/sizeof(int));

	str=get_cfg(CFG_INCOMIN,"Modem1","3,10");
	get_token(str,0,m_nr_m1,',');
	get_token(str,1,m_pause_m1,',');

	str=get_cfg(CFG_INCOMIN,"Modem2","3,10");
	get_token(str,0,m_nr_m2,',');
	get_token(str,1,m_pause_m2,',');

	str=get_cfg(CFG_INCOMIN,"ISDN","3,10");
	get_token(str,0,m_nr_isdn,',');
	get_token(str,1,m_pause_isdn,',');
	
	m_disable.SetCheck(income_times.defaultindex);
	m_for1=income_times.reserved3 & 1;
	m_for2=income_times.reserved3 & 2;
	m_from.Format("%d",income_times.reserved4);
	m_to.Format("%d",income_times.reserved5);
	UpdateData(0);
	return TRUE;
}
Esempio n. 15
0
void guard::OnBnClickedOk()
{
UINT m=0;

	UpdateData(1);
	m_password+="Phoenix";
	for(int i=0;i<=m_password.GetLength();i++)	m=(m<<1)+m_password[i];
	m_allow= get_cfg(CFG_COMMON,"Entry",0)==m;
	OnOK();
}
Esempio n. 16
0
static int get_cfg_string(const struct sr_dev_inst *sdi, char *cmd, char **buf)
{

	if (!(*buf = g_try_malloc0(256)))
		return SR_ERR_MALLOC;

	if (get_cfg(sdi, cmd, *buf) != SR_OK)
		return SR_ERR;

	return SR_OK;
}
Esempio n. 17
0
	combobox_pad(cfg_location&& _loc, wxComboBox*& ptr)
		: cfg_adapter(std::move(_loc))
		, ptr(ptr)
	{
		for (const auto& v : get_cfg().to_list())
		{
			ptr->Append(fmt::FromUTF8(v));
		}

		ptr->SetValue(fmt::FromUTF8(get_node(loaded).Scalar()));
	}
Esempio n. 18
0
static void ai_attach(void)
{
    unsigned int i;

    for (i = 0; i < 2; i++) {
        get_cfg(i + 1);
        if ((CTX != NULL) && (joy_id[i] != -1)) {
            ai_handle[i] = AIN_ObtainDevice(CTX, joy_id[i]);
        }
    }
}
Esempio n. 19
0
static int get_cfg_float(const struct sr_dev_inst *sdi, char *cmd, float *f)
{
	char buf[256], *e;

	if (get_cfg(sdi, cmd, buf) != SR_OK)
		return SR_ERR;
	*f = strtof(buf, &e);
	if (e == buf || (fpclassify(*f) & (FP_ZERO | FP_NORMAL)) == 0) {
		sr_dbg("failed to parse response to '%s': '%s'", cmd, buf);
		return SR_ERR;
	}

	return SR_OK;
}
Esempio n. 20
0
static int do_http_connect(struct update_context *ctx, const char *url) {
  LOG(LL_DEBUG, ("Connecting to: %s", url));

  struct mg_connect_opts opts;
  memset(&opts, 0, sizeof(opts));

#ifdef MG_ENABLE_SSL
  if (strlen(url) > 8 && strncmp(url, "https://", 8) == 0) {
    opts.ssl_server_name = get_cfg()->update.ssl_server_name;
    opts.ssl_ca_cert = get_cfg()->update.ssl_ca_file;
#ifndef cc3200
    if (opts.ssl_ca_cert == NULL) {
      /* Use global CA file if updater specific one is not set */
      opts.ssl_ca_cert = get_cfg()->tls.ca_file;
    }
#else
/*
 * SimpleLink only accepts one cert in DER format as a CA file so we can't
 * use a pre-packaged bundle and expect it to work, sadly.
 */
#endif
    opts.ssl_cert = get_cfg()->update.ssl_client_cert_file;
  }
#endif

  struct mg_connection *c = mg_connect_http_opt(&sj_mgr, fw_download_ev_handler,
                                                opts, url, NULL, NULL);

  if (c == NULL) {
    CONSOLE_LOG(LL_ERROR, ("Failed to connect to %s", url));
    return -1;
  }

  c->user_data = ctx;

  return 1;
}
Esempio n. 21
0
	radiobox_pad(radiobox_pad_helper&& helper, wxRadioBox*& ptr)
		: cfg_adapter(std::move(helper.location))
		, ptr(ptr)
	{
		const auto& value = get_node(loaded).Scalar();
		const auto& values = get_cfg().to_list();

		for (int i = 0; i < values.size(); i++)
		{
			if (value == values[i])
			{
				ptr->SetSelection(i);
				return;
			}
		}
	}
Esempio n. 22
0
SJ_PRIVATE enum v7_err sj_Wifi_setup(struct v7 *v7, v7_val_t *res) {
  enum v7_err rcode = V7_OK;
  v7_val_t ssidv = v7_arg(v7, 0);
  v7_val_t passv = v7_arg(v7, 1);
  v7_val_t extrasv = v7_arg(v7, 2);

  const char *ssid, *pass;
  size_t ssid_len, pass_len;
  int permanent = 1, ret = 0;

  if (!v7_is_string(ssidv) || !v7_is_string(passv)) {
    printf("ssid/pass are not strings\n");
    *res = V7_UNDEFINED;
    goto clean;
  }

  if (v7_is_object(extrasv)) {
    permanent = v7_is_truthy(v7, v7_get(v7, extrasv, "permanent", ~0));
  }

  ssid = v7_get_string(v7, &ssidv, &ssid_len);
  pass = v7_get_string(v7, &passv, &pass_len);

  struct sys_config_wifi_sta cfg;
  memset(&cfg, 0, sizeof(cfg));
  cfg.ssid = (char *) ssid;
  cfg.pass = (char *) pass;

  LOG(LL_INFO, ("WiFi: connecting to '%s'", ssid));

  ret = sj_wifi_setup_sta(&cfg);

  if (ret && permanent) {
    struct sys_config *cfg = get_cfg();
    cfg->wifi.sta.enable = 1;
    sj_conf_set_str(&cfg->wifi.sta.ssid, ssid);
    sj_conf_set_str(&cfg->wifi.sta.pass, pass);
  }

  *res = v7_mk_boolean(v7, ret);

  goto clean;

clean:
  return rcode;
}
Esempio n. 23
0
int clubby_proto_connect(struct mg_mgr *mgr) {
  if (s_clubby_conn != NULL) {
    /* We support only one connection to cloud */
    LOG(LL_ERROR, ("Clubby already connected"));

    /* TODO(alashkin): handle this */
    return 1;
  }

  LOG(LL_DEBUG, ("Connecting to %s", get_cfg()->clubby.server_address));

  s_clubby_conn =
      mg_connect(mgr, get_cfg()->clubby.server_address, clubby_proto_handler);
  if (s_clubby_conn == NULL) {
    LOG(LL_DEBUG, ("Cannot connect to %s", get_cfg()->clubby.server_address));
    struct clubby_event evt;
    evt.ev = CLUBBY_CONNECT;
    evt.net_connect.success = 0;
    s_clubby_cb(&evt);
    return 0;
  }

#ifdef SSL_KRYPTON
  if (s_cfg->tls_ena) {
    char *ca_file =
        get_cfg()->tls->tls_ca_file[0] ? get_cfg()->tls->tls_ca_file : NULL;
    char *server_name = get_cfg()->tls->tls_server_name;
    mg_set_ssl(s_clubby_conn, NULL, ca_file);
    if (server_name[0] == '\0') {
      char *p;
      server_name = strdup(get_cfg()->tls->server_address);
      p = strchr(server_name, ':');
      if (p != NULL) *p = '\0';
    }
    SSL_CTX_kr_set_verify_name(s_clubby_conn->ssl_ctx, server_name);
    if (server_name != get_cfg()->tls->tls_server_name) free(server_name);
  }
#endif

  mg_set_protocol_http_websocket(s_clubby_conn);

  return 1;
}
Esempio n. 24
0
//write status message to heartbeat log file (if configured):
void heartbeat(const char* msg, bool always)
{
    static bool first = TRUE;
//    debug(1, "hb(%s) first? %d, always? %d", msg, first, always);
    if (first) get_cfg();
    first = FALSE;

    time_t now; time(&now);
//    debug(1, "cfg: path '%s', intv %d, max %d", cfg.logpath.c_str(), cfg.interval, cfg.maxents);
    if (cfg.logpath.empty()) return; //no logging
    if (!always)
    {
//        wxTimeSpan elapsed = wxDateTime::Now().Subtract(state.latest); //msec
        int elapsed = now - state.latest;
//            if ( dt.ParseDateTime(Line, &end) )
//        debug(1, "last age: %d vs. %d", elapsed, cfg.interval);
        if (elapsed < cfg.interval) return; //not time to log yet
    }
    std::string linebuf;
//    wxDateTime now& = wxDateTime::Now();
    struct tm* nowtm = localtime(&now);
    linebuf.resize(24);
    linebuf.resize(snprintf((char*)linebuf.c_str(), 20, "[%d/%d/%2d %d:%.2d:%.2d] ", nowtm->tm_mon + 1, nowtm->tm_mday, nowtm->tm_year - 2000 + 1900, nowtm->tm_hour, nowtm->tm_min, nowtm->tm_sec));
//    linebuf.resize(strlen(linebuf.c_str()));
    linebuf += msg;
//    debug(1, "wr ent '%s'", linebuf.c_str());
    append(state.fifo, linebuf.c_str());

    FILE* hbfile = fopen(cfg.logpath.c_str(), "wt");
//    debug(1, "wr file len %d, #ents %d", hbfile? linebuf.size(): -1, state.numents);
    if (hbfile)
    {
        fputs(state.fifo.c_str(), hbfile); //CAUTION: must be atomic
        fflush(hbfile);
        fclose(hbfile);
    }
    state.latest = now;
}
Esempio n. 25
0
enum v7_err fill_ssl_connect_opts(struct v7 *v7, v7_val_t opts, int force_ssl,
                                  struct mg_connect_opts *copts) {
  enum v7_err rcode = V7_OK;

  v7_val_t v_use_ssl = v7_get(v7, opts, "use_ssl", ~0);
  v7_val_t v_ca_cert = v7_get(v7, opts, "ssl_ca_cert", ~0);
  v7_val_t v_cert = v7_get(v7, opts, "ssl_cert", ~0);
  v7_val_t v_server_name = v7_get(v7, opts, "ssl_server_name", ~0);

  if (!v7_is_undefined(v_ca_cert) && !v7_is_string(v_ca_cert)) {
    rcode = v7_throwf(v7, "TypeError", "ssl_ca_cert must be a string");
    goto clean;
  }
  if (!v7_is_undefined(v_cert) && !v7_is_string(v_cert)) {
    rcode = v7_throwf(v7, "TypeError", "ssl_cert must be a string");
    goto clean;
  }
  if (!v7_is_undefined(v_server_name) && !v7_is_string(v_server_name)) {
    rcode = v7_throwf(v7, "TypeError", "ssl_server_name must be a string");
    goto clean;
  }

  copts->ssl_ca_cert = v7_get_cstring(v7, &v_ca_cert);
  copts->ssl_cert = v7_get_cstring(v7, &v_cert);
  copts->ssl_server_name = v7_get_cstring(v7, &v_server_name);

  if ((force_ssl ||
       (v7_is_boolean(v_use_ssl) && v7_get_bool(v7, v_use_ssl) != 0)) &&
      copts->ssl_ca_cert == NULL) {
    /* Defaults to configuration */
    copts->ssl_ca_cert = get_cfg()->tls.ca_file;
  }

clean:
  return rcode;
}
Esempio n. 26
0
	void save() override
	{
		get_node(saved) = get_cfg().to_list()[ptr->GetSelection()];
	}
Esempio n. 27
0
int init_device(struct v7 *v7) {
  int result = 1;
  uint8_t mac[6] = "";

  /* Load system defaults - mandatory */
  memset(&s_cfg, 0, sizeof(s_cfg));
  if (!load_config_defaults(&s_cfg)) {
    LOG(LL_ERROR, ("Failed to load config defaults"));
    return 0;
  }

#ifndef SJ_DISABLE_GPIO
  /*
   * Check factory reset GPIO. We intentionally do it before loading CONF_FILE
   * so that it cannot be overridden by the end user.
   */
  if (s_cfg.debug.factory_reset_gpio >= 0) {
    int gpio = s_cfg.debug.factory_reset_gpio;
    sj_gpio_set_mode(gpio, GPIO_MODE_INPUT, GPIO_PULL_PULLUP);
    if (sj_gpio_read(gpio) == GPIO_LEVEL_LOW) {
      LOG(LL_WARN, ("Factory reset requested via GPIO%d", gpio));
      if (remove(CONF_FILE) == 0) {
        LOG(LL_WARN, ("Removed %s", CONF_FILE));
      }
      /* Continue as if nothing happened, no reboot necessary. */
    }
  }
#endif

  /* Successfully loaded system config. Try overrides - they are optional. */
  load_config_file(CONF_FILE, s_cfg.conf_acl, 0, &s_cfg);

  REGISTER_RO_VAR(fw_id, &build_id);
  REGISTER_RO_VAR(fw_timestamp, &build_timestamp);
  REGISTER_RO_VAR(fw_version, &build_version);
  REGISTER_RO_VAR(arch, &s_architecture);

  /* Init mac address readonly var - users may use it as device ID */
  device_get_mac_address(mac);
  snprintf(s_mac_address, sizeof(s_mac_address), "%02X%02X%02X%02X%02X%02X",
           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  REGISTER_RO_VAR(mac_address, &mac_address_ptr);
  LOG(LL_INFO, ("MAC: %s", s_mac_address));

  if (get_cfg()->wifi.ap.ssid != NULL) {
    expand_mac_address_placeholders((char *) get_cfg()->wifi.ap.ssid);
  }

  result = device_init_platform(v7, get_cfg());
  if (result != 0) {
    if (get_cfg()->http.enable) {
      result = init_web_server(get_cfg());
    }
  } else {
    LOG(LL_ERROR, ("Platform init failed"));
  }

#ifndef CS_DISABLE_JS
  /* NOTE(lsm): must be done last */
  export_read_only_vars_to_v7(v7);
#endif

  return result;
}
Esempio n. 28
0
/* Perform high-level optimizaitions.
Basis step to do:
    1. Build control flow graph.
    2. Compute POINT-TO info.
    3. Compute DEF-USE info.
    4. Compute Lived Expression info.

Optimizations to be performed:
    1. Auto Parallel
    2. Loop interchange
    3. Loop reverese(may be a little helpful)
    4. Loop tiling
    5. Loop fusion
    6. Loop unrolling */
bool Region::HighProcess(OptCTX & oc)
{
    g_indent = 0;
    note("\n\n==== Region:%s HIGHEST LEVEL FARMAT ====\n\n", get_ru_name());

    SimpCTX simp;
    if (g_do_cfs_opt) {
        IR_CFS_OPT co(this);
        co.perform(simp);
        ASSERT0(verify_irs(get_ir_list(), NULL, this));
    }

    PassMgr * passmgr = initPassMgr();
    ASSERT0(passmgr);

    if (g_build_cfs) {
        SIMP_is_record_cfs(&simp) = true;
        CfsMgr * cfsmgr = (CfsMgr*)passmgr->registerPass(PASS_CFS_MGR);
        ASSERT0(cfsmgr);
        SIMP_cfs_mgr(&simp) = cfsmgr;
    }

    simp.set_simp_cf();
    set_ir_list(simplifyStmtList(get_ir_list(), &simp));
    ASSERT0(verify_simp(get_ir_list(), simp));
    ASSERT0(verify_irs(get_ir_list(), NULL, this));

    if (g_cst_bb_list) {
        constructIRBBlist();
        ASSERT0(verifyIRandBB(get_bb_list(), this));
        set_ir_list(NULL); //All IRs have been moved to each IRBB.
    }

    if (g_do_cfg) {
        ASSERT0(g_cst_bb_list);
        IR_CFG * cfg = (IR_CFG*)passmgr->registerPass(PASS_CFG);
        ASSERT0(cfg);
        cfg->initCfg(oc);
        if (g_do_loop_ana) {
            ASSERT0(g_do_cfg_dom);
            cfg->LoopAnalysis(oc);
        }
    }

    if (g_do_ssa) {
        //Note lowering IR now may be too early and will be
        //a hindrance to optmizations.
        //low_to_pr_mode(oc);
        IR_SSA_MGR * ssamgr = (IR_SSA_MGR*)passmgr->registerPass(PASS_SSA_MGR);
        ASSERT0(ssamgr);
        ssamgr->construction(oc);
    }

    if (g_do_aa) {
        ASSERT0(g_cst_bb_list && OC_is_cfg_valid(oc));
        IR_AA * aa = (IR_AA*)passmgr->registerPass(PASS_AA);
        ASSERT0(aa);
        aa->initAliasAnalysis();
        aa->perform(oc);
    }

    if (g_do_du_ana) {
        ASSERT0(g_cst_bb_list && OC_is_cfg_valid(oc) && OC_is_aa_valid(oc));
        IR_DU_MGR * dumgr = (IR_DU_MGR*)passmgr->registerPass(PASS_DU_MGR);
        ASSERT0(dumgr);

        UINT f = SOL_REACH_DEF|SOL_REF;
        //f |= SOL_AVAIL_REACH_DEF|SOL_AVAIL_EXPR|SOL_RU_REF;

        if (g_do_ivr) {
            f |= SOL_AVAIL_REACH_DEF|SOL_AVAIL_EXPR;
        }

        if (g_do_compute_available_exp) {
            f |= SOL_AVAIL_EXPR;
        }

        dumgr->perform(oc, f);
        dumgr->computeMDDUChain(oc);
    }

    if (g_do_expr_tab) {
        ASSERT0(g_cst_bb_list);
        IR_EXPR_TAB * exprtab =
            (IR_EXPR_TAB*)passmgr->registerPass(PASS_EXPR_TAB);
        ASSERT0(exprtab);
        exprtab->perform(oc);
    }

    if (g_do_cdg) {
        ASSERT0(g_cst_bb_list && OC_is_cfg_valid(oc));
        CDG * cdg = (CDG*)passmgr->registerPass(PASS_CDG);
        ASSERT0(cdg);
        cdg->build(oc, *get_cfg());
    }

    if (g_opt_level == NO_OPT) {
        return false;
    }

    /* Regenerate high level IR, and do high level optimizations.
    Now, I get one thing: We cannot or not very easy
    construct High Level Control IR,
    (IF,DO_LOOP,...) via analysing CFG.
        e.g:

            if (i > j) { //BB1
                ...
            } else {
                return 2; //S1
            }
        BB1 does not have a ipdom, so we can not find the indispensible 3 parts:
            True body, False body, and the Sibling node.

    Solution: We can scan IF stmt first, in order to mark
    start stmt and end stmt of IF.

    //AbsNode * an = REGION_analysis_instrument(this)->m_cfs_mgr->construct_abstract_cfs();
    //Polyhedra optimization.
    //IR_POLY * poly = newPoly();
    //if (poly->construct_poly(an)) {
    //    poly->perform_poly_trans();
    //}
    //delete poly;
    */
    return true;
}
Esempio n. 29
0
	cfg::entry_base& get_cfg() const
	{
		return get_cfg(cfg::root, location.cbegin(), location.cend());
	}
Esempio n. 30
0
	static cfg::entry_base& get_cfg(cfg::entry_base& root, cfg_location::const_iterator begin, cfg_location::const_iterator end)
	{
		return begin == end ? root : get_cfg(root[*begin], begin + 1, end);
	}