Ejemplo n.º 1
0
int		queue_flush(t_conf *conf, t_simple_list *client)
{
  t_list	*queue;
  t_list	*free_cell;

  queue = client->queue;
  if (!(free_cell = queue_find_empty_data_cell(client)))
    return (-1);
  while ((queue) && (queue->status == RECEIVED))
    {
      if (!free_cell)
	{
	  MYERROR("Queue design is too small\n");
	  queue_dump(client);
	  while (1);
	  return (-1);
	}
      queue_prepare_ack(free_cell,queue->info.num_seq);
      if (extract_data(conf, client, queue) == -1)
	return (-1);
      queue = queue->next;
      free_cell = free_cell->next;
    }
  if (queue == client->queue)
    return (-1);
  return (queue_change_root(client, queue));
}
Ejemplo n.º 2
0
void exec_cmd(FILE* w, bool first,  Disc* d, const string& basename) {
	
	for (auto i=cmds.begin();i!=cmds.end();i++)
	{
		switch((*i)[0]) 
		{
			case 'g':
				{

				int start_fad = atoi((++i)->c_str());
				int size = atoi((++i)->c_str());

				extract_data(w, first, d, start_fad, size);
				
			}
			break;

			case 'i':
				extract_info(w, first, d, basename);
				break;

			case 'h':
				printf("hashes not supported yet");
				break;

			case 'f':
				printf("fingerprint not supported yet");
				break;
		}
	}
}
Ejemplo n.º 3
0
static int do_request(PROGRAMMER * pgm, AVRMEM *m)
{
  struct ft245r_request *p;
  int addr, bytes, j, n;
  char buf[FT245R_FRAGMENT_SIZE+1+128];

  if (!req_head) return 0;
  p = req_head;
  req_head = p->next;
  if (!req_head) req_tail = req_head;

  addr = p->addr;
  bytes = p->bytes;
  n = p->n;
  memset(p, 0, sizeof(struct ft245r_request));
  p->next = req_pool;
  req_pool = p;

  ft245r_recv(pgm, buf, bytes);
  for (j=0; j<n; j++) {
     m->buf[addr++] = extract_data(buf , (j * 4 + 3));
  }
#if 0
if (n == 0) // paged_write
fprintf(stderr, "recv addr 0x%04x buf size %d \n",addr, bytes);
#endif
  return 1;
}
Ejemplo n.º 4
0
void marathon_dispatcher::dispatch()
{
	for (list::iterator it = m_messages.begin(); it != m_messages.end();)
	{
		extract_data(*it);
		it = m_messages.erase(it);
	}
}
Ejemplo n.º 5
0
void fortuna_get_bytes(unsigned len, uint8_t *dst)
{
	if (!initDone)
		init();

	if (!dst || !len)
		return;
	extract_data(&mainState, len, dst);
}
Ejemplo n.º 6
0
int		main(void)
{
	t_data	*rooms;
	t_env	env;

	rooms = NULL;
	env.room_count = -1;
	extract_data(&env, &rooms);
	ft_putchar('\n');
	lem_in(rooms, &env);
	return (0);
}
Ejemplo n.º 7
0
void
fortuna_get_bytes(unsigned len, uint8 *dst)
{
	if (!init_done)
	{
		init_state(&main_state);
		init_done = 1;
	}
	if (!dst || !len)
		return;
	extract_data(&main_state, len, dst);
}
Ejemplo n.º 8
0
/*
 * transmit an AVR device command and return the results; 'cmd' and
 * 'res' must point to at least a 4 byte data buffer
 */
static int ft245r_cmd(PROGRAMMER * pgm, const unsigned char *cmd,
                      unsigned char *res) {
    int i,buf_pos;
    unsigned char buf[128];

    buf_pos = 0;
    for (i=0; i<4; i++) {
        buf_pos += set_data(pgm, buf+buf_pos, cmd[i]);
    }
    buf[buf_pos] = 0;
    buf_pos++;

    ft245r_send (pgm, buf, buf_pos);
    ft245r_recv (pgm, buf, buf_pos);
    res[0] = extract_data(pgm, buf, 0);
    res[1] = extract_data(pgm, buf, 1);
    res[2] = extract_data(pgm, buf, 2);
    res[3] = extract_data(pgm, buf, 3);

    return 0;
}
Ejemplo n.º 9
0
Archivo: scene.c Proyecto: Elytum/rtv1
void			init_scene(int fd, t_scene *scene)
{
	t_header	header;

	if (!(read(fd, &header, sizeof(header)) == sizeof(header)) ||
		!valid_scene(header))
		exit(0);
	scene->materials = extract_data(fd,
		sizeof(t_material) * header.materials_nb);
	scene->lights = extract_data(fd, sizeof(t_light) * header.lights_nb);
	scene->planes = extract_data(fd, sizeof(t_plane) * header.planes_nb);
	scene->spheres = extract_data(fd, sizeof(t_sphere) * header.spheres_nb);
	scene->cylinders = extract_data(fd,
		sizeof(t_cylinder) * header.cylinders_nb);
	scene->cones = extract_data(fd, sizeof(t_cone) * header.cones_nb);
	if (!file_ended(fd))
		exit(0);
	scene->camera_x = header.camera_x;
	scene->camera_y = header.camera_y;
	scene->camera_z = header.camera_z;
	scene->view = header.view;
	scene->materials_nb = header.materials_nb;
	scene->lights_nb = header.lights_nb;
	scene->planes_nb = header.planes_nb;
	scene->spheres_nb = header.spheres_nb;
	scene->cylinders_nb = header.cylinders_nb;
	scene->cones_nb = header.cones_nb;
}
Ejemplo n.º 10
0
static void handle_oml_measure(uint8_t *data, size_t len, uint8_t *meas_buf,
        size_t meas_size, meas_handler_t handler, char *measure_str)
{
    struct timeval timestamp;
    size_t rlen;

    uint32_t t_ref_s;
    uint32_t t_us;
    uint8_t num_meas  = data[1];
    uint8_t *data_ptr = &data[2];

    // length == (header + time_ref_seconds) + n_measures * (t_us + len)
    rlen  = 2 + sizeof(uint32_t); // header
    rlen += num_meas * (sizeof(uint32_t) + meas_size); // measures
    if (len != rlen) {
        PRINT_ERROR("Invalid %s pkt len: %zu != expected %zu\n",
                measure_str, len, rlen);
        return;
    }

    /*
     * Handle payload
     */
    // copy basetime for seconds
    extract_data((uint8_t *)&t_ref_s, &data_ptr, sizeof(uint32_t));

    for (int i = 0; i < num_meas; i++) {
        // Time
        extract_data((uint8_t *)&t_us, &data_ptr, sizeof(uint32_t));
        calculate_time_extended(&timestamp, t_ref_s, t_us);

        // Measure
        extract_data(meas_buf, &data_ptr, meas_size);
        handler(meas_buf, &timestamp);
    }
}
Ejemplo n.º 11
0
static int main_work(FILE *inp, FILE *outp)
{
        struct bsid sid;
	while(!ensure_read(&sid, inp))
        {
		size_t s=0;
		s=(sid.Size)+(sid.dwStreamNameSize);
		if(sid.dwStreamId==1)
		{
			if(extract_data(inp, outp, s)) return 1;
			break;
		}
		else
		{
			if(skip_data(inp, s)) return -1;
		}
	}
	return 0;
}
Ejemplo n.º 12
0
/* XML stuff to extract the data we need from the Rubrica file */
static GSList *
extract_cards(xmlNodePtr card)
{
    GSList *addrlist = NULL;

    while (card) {
	if (!xmlStrcmp(card->name, CXMLCHARP("Card"))) {
	    LibBalsaAddress *address = libbalsa_address_new();
	    xmlNodePtr children;

	    address->full_name =
		xml_node_get_attr(card, CXMLCHARP("name"));
	    children = card->children;
	    while (children) {
		if (!xmlStrcmp(children->name, CXMLCHARP("Data")))
		    extract_data(children->children, &address->first_name,
				 &address->last_name, &address->nick_name);
		else if (!xmlStrcmp(children->name, CXMLCHARP("Work")))
		    extract_work(children->children,
				 &address->organization);
		else if (!xmlStrcmp(children->name, CXMLCHARP("Net")))
		    extract_net(children->children,
				&address->address_list);

		children = children->next;
	    }

	    if (address->address_list)
		addrlist = g_slist_prepend(addrlist, address);
	    else
		g_object_unref(address);
	}

	card = card->next;
    }

    return addrlist;
}
Ejemplo n.º 13
0
static int
fortuna_bytes(unsigned char *outdata, int size)
{
    int ret = 0;

    HEIMDAL_MUTEX_lock(&fortuna_mutex);

    if (!fortuna_init())
	goto out;

    resend_bytes += size;
    if (resend_bytes > FORTUNA_RESEED_BYTE || resend_bytes < size) {
	resend_bytes = 0;
	fortuna_reseed();
    }
    extract_data(&main_state, size, outdata);
    ret = 1;

out:
    HEIMDAL_MUTEX_unlock(&fortuna_mutex);

    return ret;
}
Ejemplo n.º 14
0
static int do_request(PROGRAMMER * pgm, AVRMEM *m) {
    struct ft245r_request *p;
    int addr, bytes, j, n;
    unsigned char buf[FT245R_FRAGMENT_SIZE+1+128];

    if (!req_head) return 0;
    p = req_head;
    req_head = p->next;
    if (!req_head) req_tail = req_head;

    addr = p->addr;
    bytes = p->bytes;
    n = p->n;
    memset(p, 0, sizeof(struct ft245r_request));
    p->next = req_pool;
    req_pool = p;

    ft245r_recv(pgm, buf, bytes);
    for (j=0; j<n; j++) {
        m->buf[addr++] = extract_data(pgm, buf , (j * 4 + 3));
    }
    return 1;
}
Ejemplo n.º 15
0
    void partition3d::init(std::string const& datafilename,
        dimension const& dimx, dimension const& dimy, dimension const& dimz)
    {
        init_dimension(datafilename, dimension::ye, dimx, "ye", ye_values_);
        init_dimension(datafilename, dimension::temp, dimy, "logtemp", logtemp_values_);
        init_dimension(datafilename, dimension::rho, dimz, "logrho", logrho_values_);

        // Initialize the energy shift.
        extract_data(datafilename, "energy_shift", &energy_shift_, 0, 1);

        // Read our slice of data.
        std::size_t array_size = dim_[dimension::ye].count_ *
            dim_[dimension::temp].count_ * dim_[dimension::rho].count_;

        init_data(datafilename, "logpress", logpress_values_, array_size);
        init_data(datafilename, "logenergy", logenergy_values_, array_size);
        init_data(datafilename, "entropy", entropy_values_, array_size);
        init_data(datafilename, "munu", munu_values_, array_size);
        init_data(datafilename, "cs2", cs2_values_, array_size);
        init_data(datafilename, "dedt", dedt_values_, array_size);
        init_data(datafilename, "dpdrhoe", dpdrhoe_values_, array_size);
        init_data(datafilename, "dpderho", dpderho_values_, array_size);
#if SHENEOS_SUPPORT_FULL_API
        init_data(datafilename, "muhat", muhat_values_, array_size);
        init_data(datafilename, "mu_e", mu_e_values_, array_size);
        init_data(datafilename, "mu_p", mu_p_values_, array_size);
        init_data(datafilename, "mu_n", mu_n_values_, array_size);
        init_data(datafilename, "Xa", xa_values_, array_size);
        init_data(datafilename, "Xh", xh_values_, array_size);
        init_data(datafilename, "Xp", xp_values_, array_size);
        init_data(datafilename, "Xn", xn_values_, array_size);
        init_data(datafilename, "Abar", abar_values_, array_size);
        init_data(datafilename, "Zbar", zbar_values_, array_size);
        init_data(datafilename, "gamma", gamma_values_, array_size);
#endif
    }
Ejemplo n.º 16
0
    void partition::init(std::string datafilename, dimension const& dim,
        std::size_t num_nodes)
    {
        // store all parameters
        dim_ = dim;

        // account for necessary overlap
        std::size_t ghost_width_left = 0, ghost_width_right = 0;
        if (dim_.offset_ + dim_.count_ < dim_.size_-1)
            ++ghost_width_right;

        if (dim_.offset_ > 0)
            ++ghost_width_left;

        // extract the full data range
        extract_data_range(datafilename, min_value_, max_value_, delta_,
            dim_.offset_, dim_.offset_+dim_.count_);

        // read the slice of our data
        values_.reset(new double[dim_.count_ + ghost_width_left + ghost_width_right]);
        extract_data(datafilename, values_.get(),
            dim_.offset_ - ghost_width_left,
            dim_.count_ + ghost_width_left + ghost_width_right);
    }
Ejemplo n.º 17
0
int main(int argc, char *argv[])
{
   int c;

   if (install_allegro(SYSTEM_NONE, &errno, atexit) != 0)
      return 1;

   for (c=1; c<argc; c++) {
      if (argv[c][0] == '-') {
	 switch (utolower(argv[c][1])) {

	    case 'a':
	       opt_allegro = TRUE; 
	       break;

	    case 'b':
	       opt_binary = TRUE;
	       break;

	    case 'c':
	       opt_compress = TRUE;
	       break;

	    case 'd':
	       opt_delete = TRUE;
	       break;

	    case 'x':
	       opt_extract = TRUE;
	       break;

	    case '0':
	       if ((opt_password) || (c >= argc-1)) {
		  usage();
		  return 1;
	       }
	       opt_password = argv[++c];
	       break;

	    default:
	       printf("Unknown option '%s'\n", argv[c]);
	       return 1;
	 }
      }
      else {
	 if (!opt_filename)
	    opt_filename = argv[c];
	 else if (!opt_dataname)
	    opt_dataname = argv[c];
	 else {
	    usage();
	    return 1;
	 }
      }
   }

   if ((!opt_filename) || 
       ((opt_allegro) && (opt_binary)) || 
       ((opt_delete) && (opt_extract))) {
      usage();
      return 1;
   }

   if (opt_password)
      packfile_password(opt_password);

   if (opt_delete) {
      if (opt_dataname) {
	 usage();
	 return 1;
      }
      update_file(opt_filename, NULL);
   }
   else if (opt_extract) {
      if (!opt_dataname) {
	 usage();
	 return 1;
      }
      if ((!opt_allegro) && (!opt_binary)) {
	 printf("The -x option must be used together with -a or -b\n");
	 return 1;
      }
      extract_data();
   }
   else {
      if (opt_dataname)
	 update_file(opt_filename, opt_dataname);
      else
	 show_stats();
   }

   return err;
}
Ejemplo n.º 18
0
static void
mode_in(struct cpio *cpio)
{
	struct archive *a;
	struct archive_entry *entry;
	struct archive *ext;
	const char *destpath;
	int r;

	ext = archive_write_disk_new();
	if (ext == NULL)
		lafe_errc(1, 0, "Couldn't allocate restore object");
	r = archive_write_disk_set_options(ext, cpio->extract_flags);
	if (r != ARCHIVE_OK)
		lafe_errc(1, 0, "%s", archive_error_string(ext));
	a = archive_read_new();
	if (a == NULL)
		lafe_errc(1, 0, "Couldn't allocate archive object");
	archive_read_support_compression_all(a);
	archive_read_support_format_all(a);

	if (archive_read_open_file(a, cpio->filename, cpio->bytes_per_block))
		lafe_errc(1, archive_errno(a),
		    "%s", archive_error_string(a));
	for (;;) {
		r = archive_read_next_header(a, &entry);
		if (r == ARCHIVE_EOF)
			break;
		if (r != ARCHIVE_OK) {
			lafe_errc(1, archive_errno(a),
			    "%s", archive_error_string(a));
		}
		if (lafe_excluded(cpio->matching, archive_entry_pathname(entry)))
			continue;
		if (cpio->option_rename) {
			destpath = cpio_rename(archive_entry_pathname(entry));
			archive_entry_set_pathname(entry, destpath);
		} else
			destpath = archive_entry_pathname(entry);
		if (destpath == NULL)
			continue;
		if (cpio->verbose)
			fprintf(stdout, "%s\n", destpath);
		if (cpio->uid_override >= 0)
			archive_entry_set_uid(entry, cpio->uid_override);
		if (cpio->gid_override >= 0)
			archive_entry_set_gid(entry, cpio->gid_override);
		r = archive_write_header(ext, entry);
		if (r != ARCHIVE_OK) {
			fprintf(stderr, "%s: %s\n",
			    archive_entry_pathname(entry),
			    archive_error_string(ext));
		} else if (archive_entry_size(entry) > 0) {
			r = extract_data(a, ext);
			if (r != ARCHIVE_OK)
				cpio->return_value = 1;
		}
	}
	r = archive_read_close(a);
	if (r != ARCHIVE_OK)
		lafe_errc(1, 0, "%s", archive_error_string(a));
	r = archive_write_close(ext);
	if (r != ARCHIVE_OK)
		lafe_errc(1, 0, "%s", archive_error_string(ext));
	if (!cpio->quiet) {
		int64_t blocks = (archive_position_uncompressed(a) + 511)
			      / 512;
		fprintf(stderr, "%lu %s\n", (unsigned long)blocks,
		    blocks == 1 ? "block" : "blocks");
	}
	archive_read_finish(a);
	archive_write_finish(ext);
	exit(cpio->return_value);
}
Ejemplo n.º 19
0
/* Insert a request in the backend */
static void apm_driver_mysql_insert_request(TSRMLS_D)
{
	APM_DEBUG("[MySQL driver] ======apm_driver_mysql_insert_request \n");
	char *application_esc = NULL, *script_esc = NULL, *uri_esc = NULL, *host_esc = NULL, *cookies_esc = NULL, *post_vars_esc = NULL, *referer_esc = NULL, *method_esc = NULL, *status_esc = NULL, *sql = NULL;
	unsigned int application_len = 0, script_len = 0, uri_len = 0, host_len = 0, ip_int = 0, cookies_len = 0, post_vars_len = 0, referer_len = 0, method_len = 0, status_len = 0;
	struct in_addr ip_addr;
	MYSQL *connection;

	extract_data();

	APM_DEBUG("[MySQL driver] Begin insert request\n");
	if (APM_G(mysql_is_request_created)) {
		APM_DEBUG("[MySQL driver] SKIPPED, request already created.\n");
		return;
	}

	MYSQL_INSTANCE_INIT

	if (APM_G(application_id)) {
		application_len = strlen(APM_G(application_id));
		application_esc = emalloc(application_len * 2 + 1);
		application_len = mysql_real_escape_string(connection, application_esc, APM_G(application_id), application_len);
	}
	
	APM_MYSQL_ESCAPE_STR(script);
	APM_MYSQL_ESCAPE_STR(uri);
	APM_MYSQL_ESCAPE_STR(host);
	APM_MYSQL_ESCAPE_STR(referer);
	APM_MYSQL_ESCAPE_STR(method);
	APM_MYSQL_ESCAPE_STR(status);
	APM_MYSQL_ESCAPE_SMART_STR(cookies);
	APM_MYSQL_ESCAPE_SMART_STR(post_vars);

	if (APM_RD(ip_found) && (inet_pton(AF_INET, APM_RD_STRVAL(ip), &ip_addr) == 1)) {
		ip_int = ntohl(ip_addr.s_addr);
	}

	sql = emalloc(166 + application_len + script_len + uri_len + host_len + cookies_len + post_vars_len + referer_len + method_len);
	sprintf(
		sql,
		"INSERT INTO request (application, script, uri, host, ip, cookies, post_vars, referer, method, status) VALUES ('%s', '%s', '%s', '%s', %u, '%s', '%s', '%s', '%s', '%s')",
		application_esc ? application_esc : "",
		APM_RD(script_found) ? script_esc : "",
		APM_RD(uri_found) ? uri_esc : "",
		APM_RD(host_found) ? host_esc : "",
		ip_int, APM_RD(cookies_found) ? cookies_esc : "",
		APM_RD(post_vars_found) ? post_vars_esc : "",
		APM_RD(referer_found) ? referer_esc : "",
		APM_RD(method_found) ? method_esc : "",
		APM_RD(status_found) ? status_esc : "");

	APM_DEBUG("[MySQL driver] Sending: %s\n", sql);
	if (mysql_query(connection, sql) != 0)
		APM_DEBUG("[MySQL driver] Error: %s\n", mysql_error(APM_G(mysql_event_db)));

	mysql_query(connection, "SET @request_id = LAST_INSERT_ID()");

	efree(sql);
	if (application_esc)
		efree(application_esc);
	if (script_esc)
		efree(script_esc);
	if (uri_esc)
		efree(uri_esc);
	if (host_esc)
		efree(host_esc);
	if (cookies_esc)
		efree(cookies_esc);
	if (post_vars_esc)
		efree(post_vars_esc);
	if (referer_esc)
		efree(referer_esc);
	if (method_esc)
		efree(method_esc);
	if (status_esc)
		efree(status_esc);

	APM_G(mysql_is_request_created) = 1;
	APM_DEBUG("[MySQL driver] End insert request\n");
}
Ejemplo n.º 20
0
void Listfiles::get_lineduration(void){
	
	card.openFile(card.filename, true);
	//memset(comandline, '\0', sizeof(char)*65 );
	//memset(comandline2, '\0', sizeof(char)*65 );
	dias=-1, horas=-1, minutos=-1;
	char serial_char='\0';
	//comandline="";
	int posi = 0;
	int linecomepoint=0;
	simplify3D=-1;
	int exit = 0;
	while(linecomepoint < 5 && !card.isEndFile()){
		memset(comandline, '\0', sizeof(comandline) );
		while(comandline[0]!=';' && !card.isEndFile()){
			serial_char='\0';
			posi = 0;
			while(serial_char != '\n' && posi < 49 && !card.isEndFile()){
				
				int16_t n=card.get();
				serial_char = (char)n;
				comandline[posi]=serial_char;
				
				posi++;
			}
			exit++;
			if(exit>20){
				linecomepoint = 5;
			}
		}
		if(linecomepoint == 0){
			if (extract_data_Symplify() !=-1 ){
				linecomepoint = 5;
				simplify3D = 1;
				//Serial.println("Simplify");
			}
			
			else{
				simplify3D = 0;
				//Serial.println("CURA");
			}
		}else{
			extract_data();
			if (minutos !=-1 ){
				linecomepoint = 5;
				//Serial.println("Simplify");
			}
		}
		linecomepoint++;
	}
	
	Serial.println(simplify3D);
	if(simplify3D == 0){
		//Serial.println("CURA-1");
		//extract_data();
		memset(comandline, '\0', sizeof(comandline) );
		posi = 0;
		serial_char='\0';
		
		while(serial_char != '\n' && posi < 49 && !card.isEndFile()){
			
			int16_t n=card.get();
			serial_char = (char)n;
			comandline[posi]=serial_char;
			
			
			posi++;
		}
		extract_data1();
		card.closefile();
		memset(comandline, '\0', sizeof(comandline) );
	}
	else if (simplify3D == 1){
		//Serial.println("Simplify-1");
		card.sdfinalline();
		memset(comandline, '\0', sizeof(comandline) );
		
		
		
		linecomepoint=0;
		while(linecomepoint < 2 && !card.isEndFile()){
			memset(comandline, '\0', sizeof(comandline) );
			while(comandline[0]!=';' && !card.isEndFile()){
				serial_char='\0';
				posi = 0;
				while(serial_char != '\n' && posi < 49 && !card.isEndFile()){
					
					int16_t n=card.get();
					serial_char = (char)n;
					comandline[posi]=serial_char;
					
					
					posi++;
				}
				//Serial.println(comandline);
			}
			//Serial.println(comandline);
			linecomepoint++;
		}
		extract_data();
		memset(comandline, '\0', sizeof(comandline) );
		posi = 0;
		serial_char='\0';
		linecomepoint = 0;
		while(linecomepoint < 3 && !card.isEndFile()){
			memset(comandline, '\0', sizeof(comandline) );
			while(comandline[0]!=';' && !card.isEndFile()){
				serial_char='\0';
				posi = 0;
				while(serial_char != '\n' && posi < 49 && !card.isEndFile()){
					
					int16_t n=card.get();
					serial_char = (char)n;
					comandline[posi]=serial_char;
					
					
					posi++;
				}
				//Serial.println(comandline);
			}
			linecomepoint++;
		}
		extract_data1();
		card.closefile();
		memset(comandline, '\0', sizeof(comandline) );
	}
	
	
}
Ejemplo n.º 21
0
/*
	type :
		as define function TM_WRS_MAIL, TRAFFIC_CONTROL_MAIL, etc.

	path :
		attachment file or some information in file, if no file, path will be NULL
*/
static
void am_send_mail(int type, char *path)
{
	FILE *fp;
	char title[64], smtp_auth_pass[256];
	char date[30];
	time_t now;
	int status = 0;

	memset(title, 0, sizeof(title));
	memset(date, 0, sizeof(date));
	memset(smtp_auth_pass, 0, sizeof(smtp_auth_pass));

	// get current date
	time(&now);
	StampToDate(now, date);

	// email server conf setting
	mkdir_if_none("/etc/email");
	if((fp = fopen(MAIL_CONF, "w")) == NULL){
		_dprintf("fail to open %s\n", MAIL_CONF);
		return;
	}

#ifdef RTCONFIG_HTTPS
	strncpy(smtp_auth_pass,pwdec(nvram_get("PM_SMTP_AUTH_PASS")),256);
#else
	strncpy(smtp_auth_pass,nvram_get("PM_SMTP_AUTH_PASS"),256);
#endif

	fprintf(fp,"SMTP_SERVER = '%s'\n", nvram_safe_get("PM_SMTP_SERVER"));
	fprintf(fp,"SMTP_PORT = '%s'\n", nvram_safe_get("PM_SMTP_PORT"));
	fprintf(fp,"MY_NAME = 'Administrator'\n");
	fprintf(fp,"MY_EMAIL = '%s'\n", nvram_safe_get("PM_MY_EMAIL"));
	fprintf(fp,"USE_TLS = 'true'\n");
	fprintf(fp,"SMTP_AUTH = 'LOGIN'\n");
	fprintf(fp,"SMTP_AUTH_USER = '******'\n", nvram_safe_get("PM_SMTP_AUTH_USER"));
	fprintf(fp,"SMTP_AUTH_PASS = '******'\n", smtp_auth_pass);
	fclose(fp);

	// mail title
#ifdef RTCONFIG_BWDPI
	if(type == TM_WRS_MAIL)
		sprintf(title, "AiProtection alert! %s", date);
#endif
#ifdef RTCONFIG_TRAFFIC_CONTROL
	if(type == TRAFFIC_CONTROL_MAIL)
		sprintf(title, "Traffic control alert! %s", date);
#endif

	// create command (attachment or not)
	char cmd[512];
	memset(cmd, 0, sizeof(cmd));
	if (path != NULL){
		sprintf(cmd, "email -V -s \"%s\" %s -a \"%s\"", title, nvram_safe_get("PM_MY_EMAIL"), path);
	}
	else{
		sprintf(cmd, "email -V -s \"%s\" %s", title, nvram_safe_get("PM_MY_EMAIL"));
	}

	// create popen
	if((fp = popen(cmd, "w")) == NULL){
		_dprintf("%s : popen() error\n", __FUNCTION__);
		return;
	}

	// email content use popen (pipe open) ... 
	// write mail content
#ifdef RTCONFIG_BWDPI
	if(type == TM_WRS_MAIL)
	{
		// extract mail log into seperated event information
		extract_data(path, fp);

		fprintf(fp, "Suggest action: Your client devices has been detected suspicious networking behavior and blocked connection with destination server to protect your sensitive information.\nBased on our recommendation, you can\n");
		fprintf(fp, "1. Remove app that access this site and don't visit this website to prevent any personal information leak.\n");
		fprintf(fp, "2. Check your router security setting.\n");
		fprintf(fp, "3. Update security patch for your client or new firmware for your router.\n");
		fprintf(fp, "Please refer to attached log file for detail information. You also can link to trend micro website to download security trial software for your client device protection.\n");
		fprintf(fp, "\n");
		fprintf(fp, "http://www.trendmicro.com/\n");
		logmessage("alert mail", "AiProtection send mail");
	}
#endif
#ifdef RTCONFIG_TRAFFIC_CONTROL
	if(type == TRAFFIC_CONTROL_MAIL)
	{
		int count = nvram_get_int("traffic_control_count");
		fprintf(fp, "Dear user,\n\n");
		fprintf(fp, "Traffic Control configuration as below:\n\n");
		if((count & 1) == 1){
			fprintf(fp, "\t<Primary WAN>\n");
			fprintf(fp, "\tRouter Current Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_realtime_0")));
			fprintf(fp, "\tAlert Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_alert_max")));
			fprintf(fp, "\tMAX Traffic: %.2f GB\n\n", atof(nvram_safe_get("traffic_control_limit_max")));
		}
		if((count & 2) == 2){
			fprintf(fp, "\t<Secondary WAN>\n");
			fprintf(fp, "\tRouter Current Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_realtime_1")));
			fprintf(fp, "\tAlert Traffic: %.2f GB\n", atof(nvram_safe_get("traffic_control_alert_max")));
			fprintf(fp, "\tMAX Traffic: %.2f GB\n\n", atof(nvram_safe_get("traffic_control_limit_max")));
		}
		fprintf(fp, "Your internet traffic usage have reached the alert vlaue. If you are in limited traffic usage, please get more attention.\n\n");
		fprintf(fp, "Thanks,\n");
		fprintf(fp, "ASUSTeK Computer Inc.\n");
		logmessage("alert mail", "Traffic control send mail");
	}
#endif
	status = pclose(fp);
	if(status == -1) _dprintf("%s : errno %d (%s)\n", __FUNCTION__, errno, strerror(errno));
}
Ejemplo n.º 22
0
static value_ptr extract_object(bplist_info_ptr bplist, uint64_t objectRef)
{
    uint64_t offset;
    value_ptr result = NULL;
    uint8_t objectTag;
    
    if (objectRef >= bplist->object_count) {
        // Out-of-range object reference.
        bplist_log("Bad binary plist: object index is out of range.\n");
        return NULL;
    }
        
    // Use cached object if it exists
    result = cache_lookup(bplist->cache, objectRef);
    if (result != NULL)  return result;
        
    // Otherwise, find object in file.
    offset = read_offset(bplist, objectRef);
    if (offset > bplist->length) {
        // Out-of-range offset.
        bplist_log("Bad binary plist: object outside container.\n");
        return NULL;
    }
    objectTag = *(bplist->data_bytes + offset);
    switch (objectTag & 0xF0) {
    case kTAG_SIMPLE:
        result = extract_simple(bplist, offset);
        break;
                
    case kTAG_INT:
        result = extract_int(bplist, offset);
        break;
                        
    case kTAG_REAL:
        result = extract_real(bplist, offset);
        break;
                        
    case kTAG_DATE:
        result = extract_date(bplist, offset);
        break;
                        
    case kTAG_DATA:
        result = extract_data(bplist, offset);
        break;
                        
    case kTAG_ASCIISTRING:
        result = extract_ascii_string(bplist, offset);
        break;
                        
    case kTAG_UNICODESTRING:
        result = extract_unicode_string(bplist, offset);
        break;
        
    case kTAG_UID:
        result = extract_uid(bplist, offset);
        break;
        
    case kTAG_ARRAY:
        result = extract_array(bplist, offset);
        break;
        
    case kTAG_DICTIONARY:
        result = extract_dictionary(bplist, offset);
        break;
        
    default:
        // Unknown tag.
        bplist_log("Bad binary plist: unknown tag 0x%X.\n", 
                   (objectTag & 0x0F) >> 4);
        result = NULL;
    }
    
    // Cache and return result.
    if (result != NULL)  
        cache_insert(&bplist->cache, objectRef, result);
    return result;
}