Exemplo n.º 1
0
irom app_action_t application_function_ota_finish(const string_t *src, string_t *dst)
{
	static uint8_t md5_result[16];
	string_new(static, local_md5_string, 34);
	string_new(static, remote_md5_string, 34);
	app_action_t action;

	if((ota_state != state_write) && (ota_state != state_verify))
	{
		string_cat(dst, "OTA: not active\n");
		ota_state = state_inactive;
		return(app_action_error);
	}

	string_clear(&remote_md5_string);

	if((parse_string(1, src, &remote_md5_string)) != parse_ok)
	{
		string_copy(dst, "OTA: missing md5sum string\n");
		ota_state = state_inactive;
		return(app_action_error);
	}

	if((string_length(&buffer_4k) > 0) &&
			((action = flash_write_verify(src, dst)) != app_action_normal))
	{
		ota_state = state_inactive;
		return(action);
	}

	if(remote_file_length != received)
	{
		string_format(dst, "OTA: file size differs: %u != %u\n", remote_file_length, received);
		ota_state = state_inactive;
		return(app_action_error);
	}

	string_clear(&local_md5_string);

	MD5Final(md5_result, &md5);
	string_bin_to_hex(&local_md5_string, md5_result, 16);
	string_clear(dst);

	if(!string_match_string(&local_md5_string, &remote_md5_string))
	{
		string_format(dst, "OTA: invalid md5sum: \"%s\" != \"%s\"\n",
				string_to_const_ptr(&local_md5_string), string_to_ptr(&remote_md5_string));
		ota_state = state_inactive;
		return(app_action_error);
	}

	string_format(dst, "%s %s %s %d %d\n", ota_state == state_verify ? "VERIFY_OK" : "WRITE_OK",
			string_to_const_ptr(&local_md5_string),
			string_to_const_ptr(&remote_md5_string),
			written, skipped);

	ota_state = state_successful;

	return(app_action_normal);
}
irom static app_action_t application_function_wlan_ap_configure(const string_t *src, string_t *dst)
{
	string_clear(&ssid);
	string_clear(&passwd);
	int channel;

	if((parse_string(1, src, &ssid) == parse_ok) && (parse_string(2, src, &passwd) == parse_ok) &&
			(parse_int(3, src, &channel, 0) == parse_ok))
	{
		if((channel < 1) || (channel > 13))
		{
			string_format(dst, "wlan-ap-configure: channel %d out of range (1-13)\n", channel);
			return(app_action_error);
		}

		if(string_length(&passwd) < 8)
		{
			string_format(dst, "wlan-ap-configure: passwd \"%s\" too short (length must be >= 8)\n",
					string_to_ptr(&passwd));
			return(app_action_error);
		}

		strlcpy(config.ap_wlan.ssid, string_to_const_ptr(&ssid), sizeof(config.ap_wlan.ssid));
		strlcpy(config.ap_wlan.passwd, string_to_const_ptr(&passwd), sizeof(config.ap_wlan.passwd));
		config.ap_wlan.channel = channel;
	}

	string_format(dst, "wlan-ap-configure: ssid: \"%s\", passwd: \"%s\", channel: %d\n",
			config.ap_wlan.ssid, config.ap_wlan.passwd, config.ap_wlan.channel);

	return(app_action_normal);
}
Exemplo n.º 3
0
void dolines(SQLHSTMT *stmt, SQLSMALLINT ncol, char format)
{
	int j;
	long ans;

	string *str, *tstr;

	char istr[256];
	long sb = 0;

	SQLLEN si;

	str = new_string();
	tstr = new_string();

	for(;;)
	{
		ans = SQLFetch(*stmt);

		/*
		 * I assume error here is EOF...
		 */
		if((ans != SQL_SUCCESS) && ( ans != SQL_SUCCESS_WITH_INFO))
			break;

		for(j=0;j<ncol;j++)
		{

			si = 0;

			for(;;)
			{
				ans = SQLGetData(stmt, j+1, SQL_C_CHAR, istr, 256, &si);
				if(ans == SQL_NO_DATA) break;

				if(si == SQL_NO_TOTAL)
				{
					sb += 255;	
				}
				else
				{
					sb += si;
				}

				string_cat(tstr, istr);
		
				if(si != SQL_NO_TOTAL) break;
			}
			dolitem(str, string_s(tstr), (j == ncol - 1), format);
			string_clear(tstr);
		}
		string_cat_c(str, '\n');
		if(message_send(mes, str, 0, MES_SERVER_TO_CLIENT) < 0) return;
		string_clear(str);
	}
	string_delete(str);
	string_delete(tstr);
	return;
}
Exemplo n.º 4
0
/*
 * input : uname(STR) aname(STR)
 * return: NORMAL
 * reply : NULL
 */
static NEOERR* aic_cmd_appuserin(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    STRING str; string_init(&str);
    char *aname, *uname;
    int aid, uid;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname);
    aid = hash_string(aname);
    uid = hash_string(uname);

    hdf_set_int_value(q->hdfrcv, "uid", uid);
    hdf_set_int_value(q->hdfrcv, "aid", aid);

    err = aic_cmd_appusers(q, cd, db);
    if (err != STATUS_OK) return nerr_pass(err);

    if (hdf_get_valuef(q->hdfsnd, "userlist.%s.uname", uname))
        return STATUS_OK;

    err = mcs_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.userinfo"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_EXEC(db, NULL, "INSERT INTO userinfo %s", NULL, str.buf);
    string_clear(&str);
    
    cache_delf(cd, PREFIX_USERLIST"%d", aid);

    return STATUS_OK;
}
Exemplo n.º 5
0
static NEOERR* aux_cmd_inboxadd(struct aux_entry *e, QueueEntry *q)
{
    STRING str; string_init(&str);
    NEOERR *err;
    mdb_conn *db = e->db;

    HDF *node = hdf_get_child(q->hdfrcv, "mmid");

insert:
    if (node) hdf_set_value(q->hdfrcv, "mid", hdf_obj_value(node));
    
    err = mdb_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.inbox"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "INSERT INTO inbox %s", NULL, str.buf);
    string_clear(&str);

    if (node) {
        node = hdf_obj_next(node);
        if (node) goto insert;
    }

    return STATUS_OK;
}
Exemplo n.º 6
0
static NEOERR* aux_cmd_emailadd(struct aux_entry *e, QueueEntry *q)
{
    STRING str; string_init(&str);
    char sum[LEN_MD5], *content;
    NEOERR *err;
    mdb_conn *db = e->db;

    REQ_GET_PARAM_STR(q->hdfrcv, "content", content);
    
    mstr_md5_str(content, sum);
    hdf_set_value(q->hdfrcv, "checksum", sum);

    HDF *node = hdf_get_child(q->hdfrcv, "mto");

insert:
    if (node) hdf_set_value(q->hdfrcv, "to", hdf_obj_value(node));
    
    err = mdb_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.email"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "INSERT INTO email %s", NULL, str.buf);
    string_clear(&str);

    if (node) {
        node = hdf_obj_next(node);
        if (node) goto insert;
    }

    return STATUS_OK;
}
Exemplo n.º 7
0
static NEOERR* aux_cmd_cmtadd(struct aux_entry *e, QueueEntry *q)
{
	STRING str; string_init(&str);
    int type, oid;
    NEOERR *err;

    REQ_GET_PARAM_INT(q->hdfrcv, "type", type);
    REQ_GET_PARAM_INT(q->hdfrcv, "oid", oid);

    mdb_conn *db = e->db;
    struct cache *cd = e->cd;

    err = mdb_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.comment"),
                          &str);
	if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "INSERT INTO comment %s", NULL, str.buf);
    
    string_clear(&str);
    
    cache_delf(cd, PREFIX_COMMENT"%d:%d_0", type, oid);
    
    return STATUS_OK;
}
Exemplo n.º 8
0
NEOERR* system_who_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    STRING str; string_init(&str);
    mdb_conn *db = hash_lookup(dbh, "trace");
    char *mname;
    NEOERR *err;

    MCS_NOT_NULLB(cgi->hdf, db);
    
    MEMBER_CHECK_ADMIN();
    SET_DASHBOARD_ACTION(cgi->hdf);

    hdf_set_int_value(cgi->hdf, PRE_QUERY".type", TRACE_TYPE_PAGEVIEW);
    err = mdb_build_querycond(hdf_get_obj(cgi->hdf, PRE_QUERY),
                              hdf_get_obj(g_cfg, "Db.QueryCond.system.who"),
                              &str, NULL);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_QUERY_RAW(db, "emap", _COL_EMAP_WHO,
                  " %s GROUP BY sender ORDER BY min(intime) DESC LIMIT 100",
                  NULL, str.buf);
    err = mdb_set_rows(cgi->hdf, db, _COL_EMAP_WHO, PRE_OUTPUT".who",
                       NULL, MDB_FLAG_EMPTY_OK);
    if (err != STATUS_OK) return nerr_pass(err);

    string_clear(&str);

    hdf_set_attr(cgi->hdf, PRE_OUTPUT".who", "type", "array");

    return STATUS_OK;
}
Exemplo n.º 9
0
NEOERR* system_view_detail_data_get(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    STRING str; string_init(&str);
    mdb_conn *db = hash_lookup(dbh, "trace");
    char *mname;
    NEOERR *err;

    MCS_NOT_NULLB(cgi->hdf, db);
    
    MEMBER_CHECK_ADMIN();
    SET_DASHBOARD_ACTION(cgi->hdf);

    err = mdb_build_querycond(hdf_get_obj(cgi->hdf, PRE_QUERY),
                              hdf_get_obj(g_cfg, "Db.QueryCond.system.viewdetail"),
                              &str, NULL);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_QUERY_RAW(db, "emap", _COL_EMAP_VIEW_DETAIL,
                  " %s ORDER BY intime LIMIT 100", NULL, str.buf);
    err = mdb_set_rows(cgi->hdf, db, _COL_EMAP_VIEW_DETAIL, PRE_OUTPUT".details",
                       NULL, MDB_FLAG_EMPTY_OK);
    if (err != STATUS_OK) return nerr_pass(err);

    string_clear(&str);

    hdf_set_attr(cgi->hdf, PRE_OUTPUT".details", "type", "array");

    return STATUS_OK;
}
Exemplo n.º 10
0
void save_dialog_ok(char *filename)
{
/*	gtk_widget_set_sensitive(GTK_WIDGET(file_selection), 0);
	
	while(gtk_events_pending())
		gtk_main_iteration_do(0);
*/	
	stop_working();
	
	int r = 0;
	
	if(!map_filename->text[0])
		r = 1;

	string_clear(map_filename);
	char *cc = filename;
		
	while(*cc && *cc != '.')
		string_cat_char(map_filename, *cc++);

	string_cat_text(map_filename, ".map");


	set_map_path();
	
	if(r)
		make_wall_texture_paths_relative();
	
	map_save();
	
	start_working();
}
Exemplo n.º 11
0
void set_map_path()
{
	string_clear(map_path);
	
	// count how many '/'s are in map_filename
	
	int slashes = 0;
	char *cc = map_filename->text;
	
	while(*cc)
	{
		if(*cc++ == '/')
			slashes++;
	}
	
	cc = map_filename->text;
	
	while(slashes)
	{
		string_cat_char(map_path, *cc);
		
		if(*cc++ == '/')
			slashes--;
	}
}
Exemplo n.º 12
0
Arquivo: lerr.c Projeto: kingiol/cmoon
void lerr_opfinish_json(NEOERR *err, HDF *hdf)
{
    if (err == STATUS_OK) {
        hdf_set_value(hdf, PRE_SUCCESS, "1");
        return;
    }
    
    hdf_remove_tree(hdf, PRE_SUCCESS);
    
    char buf[1024], errname[128];
    NEOERR *neede = mcs_err_valid(err);
    if (!neede) neede = err;
    snprintf(buf, sizeof(buf), "%s:%d %s",
             neede->file, neede->lineno,
             _lookup_errname(neede, errname, sizeof(errname)));
    /* set PRE_ERRXXX with the most recently err */
    if (!hdf_get_obj(hdf, PRE_ERRMSG)) {
        hdf_set_value(hdf, PRE_ERRMSG, buf);
    }
    hdf_set_int_value(hdf, PRE_ERRCODE, neede->error);

    STRING str; string_init(&str);
    nerr_error_traceback(err, &str);
    mtc_err("%s", str.buf);
    hdf_set_value(hdf, PRE_ERRTRACE, str.buf);
    nerr_ignore(&err);
    string_clear(&str);
}
Exemplo n.º 13
0
Arquivo: lerr.c Projeto: bigml/mgate
void lerr_opfinish_json(NEOERR *err, HDF *hdf)
{
    if (err == STATUS_OK) {
        hdf_set_value(hdf, PRE_SUCCESS, "1");
        mcs_set_int_attr(hdf, PRE_SUCCESS, "type", CNODE_TYPE_INT);
        return;
    }

    hdf_remove_tree(hdf, PRE_SUCCESS);

    NEOERR *neede = mcs_err_valid(err);
    /* set PRE_ERRXXX with the most recently err */
    mcs_set_int_value_with_type(hdf, PRE_ERRCODE, neede->error, CNODE_TYPE_INT);
    if (!hdf_get_obj(hdf, PRE_ERRMSG)) {
        hdf_set_valuef(hdf, "%s=%s:%d %s",
                       PRE_ERRMSG, neede->file, neede->lineno, neede->desc);
    }

    STRING str; string_init(&str);
    nerr_error_traceback(err, &str);
    mtc_err("%s", str.buf);
    hdf_set_value(hdf, PRE_ERRTRACE, str.buf);
    nerr_ignore(&err);
    string_clear(&str);
}
Exemplo n.º 14
0
void dolines(PGresult *pgr, char format)
{
	int i, j, ncol = 0, nrow = 0;

	string *str;
	char *s;

	nrow = PQntuples(pgr);
	ncol = PQnfields(pgr);

	str = new_string();

	for(i=0;i<nrow;i++)
	{
		for(j=0;j<ncol;j++)
		{
			s = PQgetvalue(pgr, i, j);

			dolitem(str, s, (j == ncol - 1), format);
		}
		string_cat_c(str, '\n');
		if(message_send(mes, str, 0, MES_SERVER_TO_CLIENT) < 0) return;
		string_clear(str);
	}
	string_delete(str);
	return;
}
Exemplo n.º 15
0
void dolines(MYSQL_RES *res, char format)
{
	int j;
	unsigned int ncol = 0;

	string *str;
	char *s;

	MYSQL_ROW row;

	ncol = mysql_num_fields(res);

	str = new_string();

	while((row = mysql_fetch_row(res)) != NULL)
	{
		for(j=0;j<ncol;j++)
		{
			s = row[j];
			dolitem(str, s, (j == ncol - 1), format);
		}
		string_cat_c(str, '\n');
		if(message_send(mes, str, 0, MES_SERVER_TO_CLIENT) < 0) return;
		string_clear(str);
	}
	string_delete(str);
	return;
}
Exemplo n.º 16
0
static NEOERR* dyn_cmd_addtrack(struct queue_entry *q, struct cache *cd, mdb_conn *db)
{
    STRING str; string_init(&str);
    char *aname, *uname, *oname;
    int aid, uid, oid = 0;
    NEOERR *err;

    REQ_GET_PARAM_STR(q->hdfrcv, "uname", uname);
    REQ_GET_PARAM_STR(q->hdfrcv, "aname", aname);
    REQ_FETCH_PARAM_STR(q->hdfrcv, "oname", oname);
    uid = hash_string(uname);
    aid = hash_string(aname);
    if (oname) oid = hash_string(oname);

    hdf_set_int_value(q->hdfrcv, "aid", aid);
    hdf_set_int_value(q->hdfrcv, "uid", uid);
    hdf_set_int_value(q->hdfrcv, "oid", oid);
    
    err = mcs_build_incol(q->hdfrcv,
                          hdf_get_obj(g_cfg, CONFIG_PATH".InsertCol.track"),
                          &str);
    if (err != STATUS_OK) return nerr_pass(err);
    
    MDB_EXEC(db, NULL, "INSERT INTO track %s", NULL, str.buf);
    string_clear(&str);

    return STATUS_OK;
}
Exemplo n.º 17
0
NEOERR* blog_data_mod(CGI *cgi, HASH *dbh, HASH *evth, session_t *ses)
{
    mdb_conn *conn = (mdb_conn*)hash_lookup(dbh, "aux");
    mevent_t *evt = (mevent_t*)hash_lookup(evth, "aic");
    char *aname;
    int bid;
    NEOERR *err;

    LPRE_DBOP(cgi->hdf, conn);

    HDF_GET_INT(cgi->hdf, PRE_QUERY".bid", bid);

    APP_CHECK_LOGIN();
    
    if (hdf_get_int_value(evt->hdfrcv, "state", 0) < LCS_ST_ADMIN)
        return nerr_raise(LERR_LIMIT, "%s wan't be admin", aname);

    STRING str;
    string_init(&str);
    err = mcs_build_upcol(hdf_get_obj(cgi->hdf, PRE_QUERY),
                          hdf_get_obj(g_cfg, "Db.UpdateCol.blog"), &str);
    if (err != STATUS_OK) return nerr_pass(err);

    MDB_EXEC(conn, NULL, "UPDATE blog SET %s WHERE id=%d AND author=$1",
             "s", str.buf, bid, aname);
    string_clear(&str);

    char command[1024];
    snprintf(command, sizeof(command), PATH_PAGER"blg -b %d", bid);
    mtc_dbg("%s", command);
    system(command);

    return STATUS_OK;
}
Exemplo n.º 18
0
/**
 * Get one line from specific stream with delimiter.
 */
bool_t string_getline_delimiter(string_t* pstr_string, FILE* fp_stream, char c_delimiter)
{
    int n_char = EOF;

    assert(pstr_string != NULL);
    assert(fp_stream != NULL);

    if(c_delimiter == '\n')
    {
        return string_getline(pstr_string, fp_stream);
    }
    else
    {
        clearerr(fp_stream);
        string_clear(pstr_string);
        while(!feof(fp_stream) && !ferror(fp_stream) && (char)n_char != c_delimiter &&
              string_size(pstr_string) < string_max_size(pstr_string))
        {
            n_char = fgetc(fp_stream);
            if((char)n_char != c_delimiter && n_char != EOF)
            {
                string_push_back(pstr_string, (char)n_char);
            }
        }

        if((char)n_char == c_delimiter)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
Exemplo n.º 19
0
bool file_getLine(FILE *file, string_t *str)
{
    string_clear(str);
    bool v = file_readLine(file, str);
    string_cstr(str);
    return v;
}
Exemplo n.º 20
0
bool file_getLine_delim(FILE *file, string_t *str, char delim)
{
    string_clear(str);
    bool v = file_readLine_delim(file, str, delim);
    string_cstr(str);
    return v;
}
Exemplo n.º 21
0
NEOERR *hdf_write_string (HDF *hdf, char **s)
{
  STRING str;
  NEOERR *err;

  *s = NULL;

  string_init (&str);

  err = hdf_dump_str (hdf, NULL, 1, &str);
  if (err)
  {
    string_clear (&str);
    return nerr_pass(err);
  }
  if (str.buf == NULL)
  {
    *s = strdup("");
    if (*s == NULL) return nerr_raise(NERR_NOMEM, "Unable to allocate empty string");
  }
  else
  {
    *s = str.buf;
  }

  return STATUS_OK;
}
irom static app_action_t application_function_wlan_client_configure(const string_t *src, string_t *dst)
{
	string_clear(&ssid);
	string_clear(&passwd);

	if((parse_string(1, src, &ssid) == parse_ok) && (parse_string(2, src, &passwd) == parse_ok))
	{
		strlcpy(config.client_wlan.ssid, string_to_const_ptr(&ssid), sizeof(config.client_wlan.ssid));
		strlcpy(config.client_wlan.passwd, string_to_const_ptr(&passwd), sizeof(config.client_wlan.passwd));
	}

	string_format(dst, "wlan-client-configure: ssid: \"%s\", passwd: \"%s\"\n",
			config.client_wlan.ssid, config.client_wlan.passwd);

	return(app_action_normal);
}
Exemplo n.º 23
0
void clear_map()		// always called when not working
{
	delete_all_nodes();
	delete_all_conns();
	delete_all_curves();
	delete_all_points();
	delete_all_fills();
	delete_all_lines();
	delete_all_tiles();
	delete_all_objects();

	map_saved = 1;
	string_clear(map_filename);
	string_clear(map_path);
	char *cwd =  get_current_dir_name();
	string_cat_text(map_path, cwd);
	free(cwd);
}
Exemplo n.º 24
0
irom void config_dump(string_t *dst, const config_t *cfg)
{
	string_new(static, ntp_server, 32);

	string_clear(&ntp_server);
	string_ip(&ntp_server, cfg->ntp.server);

	string_format(dst, 
			"> config magic: %04x\n"
			"> config version: %d\n"
			"> wlan client ssid: %s\n"
			"> wlan client passwd: %s\n"
			"> wlan ap ssid: %s\n"
			"> wlan ap passwd: %s\n"
			"> wlan ap channel: %d\n"
			"> wlan mode: %s mode\n"
			"> bridge tcp port: %u\n"
			"> bridge tcp timeout: %u\n"
			"> command tcp port: %u\n"
			"> command tcp timeout: %u\n"
			"> ntp server: %s\n"
			"> ntp time zone: GMT%c%u\n"
			"> display flip timeout: %u\n"
			"> display default message: %s\n"
			"> status trigger gpio (-1 is disabled): %d/%d\n"
			"> wlan association trigger gpio (-1 is disabled): %d/%d\n"
			"> flags: ", 
		cfg->magic,
		cfg->version,
		cfg->client_wlan.ssid,
		cfg->client_wlan.passwd,
		cfg->ap_wlan.ssid,
		cfg->ap_wlan.passwd,
		cfg->ap_wlan.channel,
		cfg->wlan_mode == config_wlan_mode_client ? "client" : "ap",
		cfg->bridge.port,
		cfg->bridge.timeout,
		cfg->command.port,
		cfg->command.timeout,
		string_to_ptr(&ntp_server),
		cfg->ntp.timezone >= 0 ? '+' : '-',
		cfg->ntp.timezone >= 0 ? cfg->ntp.timezone : 0 - cfg->ntp.timezone,
		cfg->display.flip_timeout,
		cfg->display.default_msg,
		cfg->status_trigger.io,
		cfg->status_trigger.pin,
		cfg->assoc_trigger.io,
		cfg->assoc_trigger.pin);

	config_flags_to_string(dst, 0, 0, cfg->flags);

	string_cat(dst, "\n> uart: ");
	uart_parameters_to_string(dst, &cfg->uart);
	string_cat(dst, "\n> gpios:\n");
	io_config_dump(dst, cfg, -1, -1, false);
}
Exemplo n.º 25
0
NEOERR * hdf_read_string (HDF *hdf, const char *str)
{
  NEOERR *err;
  int lineno = 0;
  STRING line;
  string_init(&line);
  err = _hdf_read_string(hdf, &str, &line, "<string>", &lineno, INCLUDE_ERROR);
  string_clear(&line);
  return nerr_pass(err);
}
Exemplo n.º 26
0
irom static app_action_t flash_write_verify(const string_t *src, string_t *dst)
{
	char *verify_buffer = string_to_ptr(dst);
	char *write_buffer = string_to_ptr(&buffer_4k);
	int write_buffer_length = string_length(&buffer_4k);

	if(string_size(dst) < 0x1000)
	{
		string_format(dst, "OTA: string verify buffer too small: %d\n", string_size(dst));
		return(app_action_error);
	}

	if(ota_state == state_write)
	{
		spi_flash_read(flash_sector * 0x1000, (void *)verify_buffer, write_buffer_length);

		if(ets_memcmp(write_buffer, verify_buffer, write_buffer_length))
		{
			spi_flash_erase_sector(flash_sector);
			spi_flash_write(flash_sector * 0x1000, (void *)write_buffer, write_buffer_length);
			written++;
		}
		else
			skipped++;
	}

	spi_flash_read(flash_sector * 0x1000, (void *)verify_buffer, write_buffer_length);
	MD5Update(&md5, verify_buffer, write_buffer_length);

	if(ets_memcmp(write_buffer, verify_buffer, write_buffer_length))
	{
		string_copy(dst, "OTA: verify mismatch\n");
		return(app_action_error);
	}

	flash_sector++;
	received += write_buffer_length;

	string_clear(&buffer_4k);
	string_clear(dst);

	return(app_action_normal);
}
Exemplo n.º 27
0
static void
openvpn_plugin_string_list_item_free (struct openvpn_plugin_string_list *l)
{
  if (l)
    {
      free (l->name);
      string_clear (l->value);
      free (l->value);
      free (l);
    }
}
Exemplo n.º 28
0
NEOERR * hdf_read_string_ignore (HDF *hdf, const char *str, int ignore)
{
  NEOERR *err;
  int lineno = 0;
  STRING line;
  string_init(&line);
  err = _hdf_read_string(hdf, &str, &line, "<string>", &lineno,
                         (ignore ? INCLUDE_IGNORE : INCLUDE_ERROR));
  string_clear(&line);
  return nerr_pass(err);
}
Exemplo n.º 29
0
extern char* file_read_line(xString *const line , FILE* fp)
{
   char *result = NULL;
   
   string_clear(line);

   if ( NULL == fp )
         error(FATAL, "NULL file pointer");
   else{
      boolean re_readline;

      do {
         char *const pLastChar = get_string_value(line) + get_string_size (line) -2;
			fpos_t startOfLine;

			fgetpos (fp, &startOfLine);
			re_readline = FALSE;
			*pLastChar = '\0';
			result = fgets (get_string_value(line), (int) get_string_size(line), fp);
			if (result == NULL)
			{
				if (! feof(fp))
					error (FATAL | ERROR, "Failure on attempt to read file");
			}
			else if (*pLastChar != '\0'  &&
					 *pLastChar != '\n'  &&  *pLastChar != '\r')
			{
				/*  buffer overflow */
				re_readline = string_auto_resize(line);
				if (re_readline)
					fsetpos (fp, &startOfLine);
				else
					error (FATAL | ERROR, "input line too big; out of memory");
			}
			else
			{
				char* eol;
            line->length = strlen (line->buffer);

				/* canonicalize new line */
				eol = get_string_value(line) + get_string_length(line) - 1;
				if (*eol == '\r')
					*eol = '\n';
				else if (*(eol - 1) == '\r'  &&  *eol == '\n')
				{
					*(eol - 1) = '\n';
					*eol = '\0';
					--line->length;
				}
			}
      }while(re_readline);
   }
   return result;
}
Exemplo n.º 30
0
static void
vpnconnect_plugin_string_list_item_free (struct vpnconnect_plugin_string_list *l)
{
  if (l)
    {
      free (l->name);
      string_clear (l->value);
      free (l->value);
      free (l);
    }
}