コード例 #1
0
ファイル: fs.c プロジェクト: colinporth/radioPlus
//}}}
//{{{
void fs_close (struct fs_file* file) {

#if LWIP_HTTPD_CUSTOM_FILES
  if (file->is_custom_file) {
    fs_close_custom (file);
  }
#endif /* LWIP_HTTPD_CUSTOM_FILES */

#if LWIP_HTTPD_FILE_STATE
  fs_state_free (file, file->state);
#endif /* #if LWIP_HTTPD_FILE_STATE */
  fs_free(file);
}
コード例 #2
0
ファイル: ct.c プロジェクト: mkatkar/libct
static void local_ct_destroy(ct_handler_t h)
{
	struct container *ct = cth2ct(h);

	cgroups_free(ct);
	fs_free(ct);
	net_release(ct);
	xfree(ct->name);
	xfree(ct->hostname);
	xfree(ct->domainname);
	xfree(ct->cgroup_sub);
	local_ct_uid_gid_free(ct);
	xfree(ct);
}
コード例 #3
0
ファイル: fslist.c プロジェクト: mnv104/capfs
int fs_rem(fslist_p fsl_p, ino_t fs_ino)
{
	fsinfo_p fs_p;
	
	fslist_wrlock(fsl_p);
	fs_p = (fsinfo_p) llist_rem(fsl_p->list, (void *) (&fs_ino), fs_ino_cmp);
	if (fs_p) {
		fs_free(fs_p);
		fslist_unlock(fsl_p);
		return(0);
	}
	fslist_unlock(fsl_p);
	return(-1);
}
コード例 #4
0
ファイル: rb_define.c プロジェクト: Passerby/fsnet
void
wrap_Pack_free (struct fs_pack* ptr)
{
    if(ptr){
        // 这里的DATA是在RUBY堆里生成的. 所以不需要自己free
        if(ptr->input_stream){
            fs_stream_free_input(ptr->input_stream);
        }
        if(ptr->output_stream){
            fs_stream_free_output(ptr->output_stream);
        }
        
        fs_free(ptr);
    }
}
コード例 #5
0
ファイル: node.c プロジェクト: madhusirmv/C_monk
/**
 * @brief allocate a node to represent an identifier
 * @param text contains the name of the identifier
 * 		  length the length of the text (does not include terminating NULL)
 * @return pointer to the node structure defined in node.h
 *
 * Side-effects:
 *   Memory allocated on the heap by FLEXSTR.
 */
struct node *node_identifier(char *text, unsigned int len)
{
    struct node *node = node_create(NODE_IDENTIFIER);

    FLEXSTR str;
    fs_init(&str, 0);
    fs_addstr(&str, text);

    node->data.identifier.name = strdup(fs_getstr(&str));
    node->data.identifier.len = len;
    node->data.identifier.symbol = NULL;

    fs_free(&str);
    return node;
}
コード例 #6
0
static char *
fs_strdup_len (const char * s, size_t len)
{
  char * ret;
  if (s == NULL) return NULL;
  if (len == 0) return NULL;
  len = fs_comment_clamp(len);
  ret = fs_malloc (len + 1);
  if (ret == NULL) return NULL;
  if (strncpy (ret, s, len) == NULL) {
    fs_free (ret);
    return NULL;
  }

  ret[len] = '\0';
  return ret;
}
コード例 #7
0
ファイル: fs.c プロジェクト: MultiCalorNV/ChibiOS
/*-----------------------------------------------------------------------------------*/
struct fs_file *
fs_open(const char *name)
{
  struct fs_file *file;
  const struct fsdata_file *f;

  file = fs_malloc();
  if(file == NULL) {
    return NULL;
  }

#if LWIP_HTTPD_CUSTOM_FILES
  if(fs_open_custom(file, name)) {
    file->is_custom_file = 1;
    return file;
  }
  file->is_custom_file = 0;
#endif /* LWIP_HTTPD_CUSTOM_FILES */

  for(f = FS_ROOT; f != NULL; f = f->next) {
    if (!strcmp(name, (char *)f->name)) {
      file->data = (const char *)f->data;
      file->len = f->len;
      file->index = f->len;
      file->pextension = NULL;
      file->http_header_included = f->http_header_included;
#if HTTPD_PRECALCULATED_CHECKSUM
      file->chksum_count = f->chksum_count;
      file->chksum = f->chksum;
#endif /* HTTPD_PRECALCULATED_CHECKSUM */
#if LWIP_HTTPD_FILE_STATE
      file->state = fs_state_init(file, name);
#endif /* #if LWIP_HTTPD_FILE_STATE */
      return file;
    }
  }
  fs_free(file);
  return NULL;
}
コード例 #8
0
ファイル: test_spiffs.c プロジェクト: SkySparky/spiffs
void _teardown() {
  printf("  free blocks     : %i of %i\n", (FS)->free_blocks, (FS)->block_count);
  printf("  pages allocated : %i\n", (FS)->stats_p_allocated);
  printf("  pages deleted   : %i\n", (FS)->stats_p_deleted);
#if SPIFFS_GC_STATS
  printf("  gc runs         : %i\n", (FS)->stats_gc_runs);
#endif
#if SPIFFS_CACHE
#if SPIFFS_CACHE_STATS
  chits_tot += (FS)->cache_hits;
  cmiss_tot += (FS)->cache_misses;
  printf("  cache hits      : %i (sum %i)\n", (FS)->cache_hits, chits_tot);
  printf("  cache misses    : %i (sum %i)\n", (FS)->cache_misses, cmiss_tot);
  printf("  cache utiliz    : %f\n", ((float)chits_tot/(float)(chits_tot + cmiss_tot)));
  chits_tot = 0;
  cmiss_tot = 0;
#endif
#endif
  if (_area) {
    dump_flash_access_stats();
    clear_flash_ops_log();
#if SPIFFS_GC_STATS
    if ((FS)->stats_gc_runs > 0)
#endif
    dump_erase_counts(FS);
    printf("  fs consistency check output begin\n");
    SPIFFS_check(FS);
    printf("  fs consistency check output end\n");
  }
  clear_test_path();
  fs_free();
  printf("  locks : %i\n", _fs_locks);
  if (_fs_locks != 0) {
    printf("FATAL: lock asymmetry. Abort.\n");
    exit(-1);
  }
}
コード例 #9
0
ファイル: fs.c プロジェクト: liwei606/OS_proj
int main(int argc, char **argv) {
    FileSystem *fs;
    FILE* logfile;
    char str[4096];
    //char buffer[4096];
    
    int sd, client, diskserv;
    struct sockaddr_in server_addr, name;
    struct hostent *host;
    
    // connect to disk server
    if ((diskserv = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
		fprintf(stderr, "Socket error\n");
		exit(1);
	}
	
	printf("Trying to connect...\n");
	name.sin_family 	= AF_INET;
	host				= gethostbyname("localhost"); 
	name.sin_port		= htons(atoi(argv[1]));
	memcpy(&name.sin_addr.s_addr, host->h_addr, host->h_length);
	
	if (connect(diskserv, (struct sockaddr *)&name, sizeof(name)) == -1) {
		fprintf(stderr, "Connect error\n");
		exit(1);
	}	
	printf("Connection with the disk is established!\n");	

	// connect to client
    sd = socket(AF_INET, SOCK_STREAM, 0);
    server_addr.sin_family		 = AF_INET;
    server_addr.sin_addr.s_addr  = htonl(INADDR_ANY);
    server_addr.sin_port		 = htons(atoi(argv[2]));
    
    if (bind(sd, (struct sockaddr *) &server_addr, sizeof(server_addr)) == -1) {
    	fprintf(stderr, "Bind error\n");
    	exit(1);
    }
    if (listen(sd, 1) == -1) {
    	fprintf(stderr, "Listen error\n");
    	exit(1);
    }
    fs = fs_new();
    if ((client = accept(sd, 0, 0)) == -1) {
    	fprintf(stderr, "Accept error\n");
    	exit(1);
    }
    logfile = fdopen(client, "w+");
    printf("Connection with client is established!\n");
       
    
    while (1) {
        int result;
        
        recv(client, str, 4096, 0);
        while (isspace(str[strlen(str) - 1])) {
            str[strlen(str) - 1] = 0;
        }
        printf("receive successfully\n");
        result = process_request(str, logfile, fs);
        if (RESULT_EXIT == result) {
            fprintf(logfile, "Goodbye!\n");
            fflush(logfile);
            break;
        } else if (RESULT_DONE == result) {
            fprintf(logfile, "Done\n");
            fflush(logfile);
        } else if (RESULT_YES == result) {
            fprintf(logfile, "Yes\n");
            fflush(logfile);
        } else if (RESULT_NO == result) {
            fprintf(logfile, "No\n");
            fflush(logfile);
        }
        printf("send succussfully.\n");
    }
    close(client);
    close(diskserv);
    close(sd);
    printf("GoodBye!\n");
    fs_free(&fs);
    fclose(logfile);
    return 0;
}
コード例 #10
0
int
fish_sound_comments_decode (FishSound * fsound, unsigned char * comments,
			    long length)
{
   char *c= (char *)comments;
   int i, nb_fields, n;
   size_t len;
   char *end;
   char * name, * value, * nvalue = NULL;
   FishSoundComment * comment;
   
   if (length<8)
      return -1;

   end = c+length;
   len=readint(c, 0);

   c+=4;
   if (len > (unsigned long) length - 4) return -1;

   /* Vendor */
   if (len > 0) {
     if ((nvalue = fs_strdup_len (c, len)) == NULL)
       return FISH_SOUND_ERR_OUT_OF_MEMORY;
     if (fish_sound_comment_set_vendor (fsound, nvalue) == FISH_SOUND_ERR_OUT_OF_MEMORY) {
       fs_free (nvalue);
       return FISH_SOUND_ERR_OUT_OF_MEMORY;
     }

     fs_free (nvalue);
   }
#ifdef DEBUG
   fwrite(c, 1, len, stderr); fputc ('\n', stderr);
#endif
   c+=len;

   if (c+4>end) return -1;

   /* This value gets checked effectively by the 'for' condition
      and the checks within the loop for c running off the end.  */
   nb_fields=readint(c, 0);
   debug_printf (1, "%d comments", nb_fields);

   c+=4;
   for (i=0;i<nb_fields;i++)
   {
      if (c+4>end) return -1;

      len=readint(c, 0);
      debug_printf (1, "[%d] len %d\n", i, len);

      c+=4;
      if (len > (unsigned long) (end-c)) return -1;

      name = c;
      value = fs_index_len (c, '=', len);
      n = 0;
      if (value) {
	*value = '\0';
	value++;
	n = c+len - value;
	
      }
      if (n) {
	if ((nvalue = fs_strdup_len (value, n)) == NULL)
          return FISH_SOUND_ERR_OUT_OF_MEMORY;

	debug_printf (1, "%s -> %s (length %d)", name, nvalue, n);

	if ((comment = fs_comment_new (name, nvalue)) == NULL) {
	  fs_free (nvalue);
          return FISH_SOUND_ERR_OUT_OF_MEMORY;
	}

	if (_fs_comment_add (fsound, comment) == NULL) {
	  fs_free (nvalue);
          return FISH_SOUND_ERR_OUT_OF_MEMORY;
	}

	fs_free (nvalue);
      } else if (len > 0) {
        debug_printf (1, "[%d] %s (no value)", i, name, len);

	if ((nvalue = fs_strdup_len (name, len)) == NULL)
          return FISH_SOUND_ERR_OUT_OF_MEMORY;

	if ((comment = fs_comment_new (nvalue, "")) == NULL) {
	  fs_free (nvalue);
          return FISH_SOUND_ERR_OUT_OF_MEMORY;
	}

	if (_fs_comment_add (fsound, comment) == NULL) {
	  fs_free (nvalue);
          return FISH_SOUND_ERR_OUT_OF_MEMORY;
	}

	fs_free (nvalue);
      }

      c+=len;
   }

   debug_printf (1, "OUT");

   return FISH_SOUND_OK;
}
コード例 #11
0
ファイル: oc_bpt_test_fs.c プロジェクト: Acidburn0zzz/bt
void oc_bpt_test_fs_alt_free(void)
{
    fs_free(alt_p);
    alt_p = NULL;
}
コード例 #12
0
ファイル: runner.c プロジェクト: snake5/nailer
int main( int argc, char* argv[] )
{
	if( fs_init() )
		return 1;
	win_initialize( argc, argv );
	g_RS = rsl_create();
	g_RS.change_cb = runner_change_callback;
	g_winActCb = runner_action_callback;
	
	rsl_compile( &g_RS, g_scriptData, NULL );
	X_DBG( rsl_dump( &g_RS ) );
	
#if 0
	///////////////////////////////////////////////////
//	win_set_title( "Testā rešpekt" );
//	win_set_background_color( 120, 150, 180 );
//	win_set_background_image( 0 );
	
	win_ctl_resize( 2 );
	
	g_controls[0].type = WCTL_BUTTON;
	g_controls[0].x1 = 100;
	g_controls[0].y1 = 100;
	g_controls[0].x2 = 300;
	g_controls[0].y2 = 140;
	byte colors[ 24 ] =
	{
		50, 50, 50, 1,
		50, 50, 50, 1,
		50, 50, 50, 1,
		200, 200, 200, 1,
		220, 220, 220, 1,
		180, 180, 180, 1,
	};
	memcpy( g_controls[0].fgColorN, colors, 24 );
	strcpy( g_controls[0].text, "Spēlēt" );
	win_ctl_updated( 0, WCU_EVERYTHING );
	
	g_controls[1].type = WCTL_BUTTON;
	g_controls[1].x1 = 100;
	g_controls[1].y1 = 200;
	g_controls[1].x2 = 300;
	g_controls[1].y2 = 240;
	byte colors2[ 24 ] =
	{
		50, 30, 30, 1,
		60, 40, 40, 1,
		70, 50, 50, 1,
		190, 190, 210, 1,
		210, 210, 230, 1,
		170, 170, 190, 1,
	};
	memcpy( g_controls[1].fgColorN, colors2, 24 );
	strcpy( g_controls[1].text, "Instalēt" );
	win_ctl_updated( 1, WCU_EVERYTHING );
	///////////////////////////////////////////////////
#endif
	
	vl_set( &g_RS.varlist, strlitlen( "_action" ), strlitlen( "init" ) );
	rsl_run( &g_RS );
	vl_set( &g_RS.varlist, strlitlen( "_action" ), strlitlen( "" ) );
	runner_apply_changes();
	
	while( win_process( 0 ) );
	
	rsl_destroy( &g_RS );
	fs_free();
	win_destroy();
	return 0;
}
コード例 #13
0
ファイル: recv.c プロジェクト: gianninou/zmap
void handle_packet(uint32_t buflen, const u_char *bytes) {
	if ((sizeof(struct ip) + (zconf.send_ip_pkts ? 0 : sizeof(struct ether_header))) > buflen) {
		// buffer not large enough to contain ethernet
		// and ip headers. further action would overrun buf
		return;
	}
	struct ip *ip_hdr = (struct ip *) &bytes[(zconf.send_ip_pkts ? 0 : sizeof(struct ether_header))];

	uint32_t src_ip = ip_hdr->ip_src.s_addr;

	uint32_t validation[VALIDATE_BYTES/sizeof(uint8_t)];
	// TODO: for TTL exceeded messages, ip_hdr->saddr is going to be different
	// and we must calculate off potential payload message instead
	validate_gen(ip_hdr->ip_dst.s_addr, ip_hdr->ip_src.s_addr, (uint8_t *) validation);

	if (!zconf.probe_module->validate_packet(ip_hdr, buflen - (zconf.send_ip_pkts ? 0 : sizeof(struct ether_header)),
				&src_ip, validation)) {
		return;
	}

	int is_repeat = pbm_check(seen, ntohl(src_ip));

	//HACK vgiannin for multiple port
	is_repeat=0;

	fieldset_t *fs = fs_new_fieldset();

	//struct tcphdr *tcp = (struct tcphdr*)((char *) ip_hdr + 4*ip_hdr->ip_hl);
	//uint16_t sport = ntohs(tcp->th_sport);
	//printf("port : %d\n",sport);
	// char line[50];
	// struct in_addr t;
	// t.s_addr = ip_hdr->ip_src.s_addr;
	// const char *temp = inet_ntoa(t);
	// sprintf(line,"%s:%d",temp,sport);
	//printf("%s\n",line );


	fs_add_ip_fields(fs, ip_hdr);
	// HACK:
	// probe modules (for whatever reason) expect the full ethernet frame
	// in process_packet. For VPN, we only get back an IP frame.
	// Here, we fake an ethernet frame (which is initialized to
	// have ETH_P_IP proto and 00s for dest/src).
	if (zconf.send_ip_pkts) {
		if (buflen > sizeof(fake_eth_hdr)) {
			buflen = sizeof(fake_eth_hdr);
		}
		memcpy(&fake_eth_hdr[sizeof(struct ether_header)], bytes, buflen);
		bytes = fake_eth_hdr;
	}
	zconf.probe_module->process_packet(bytes, buflen, fs);
	fs_add_system_fields(fs, is_repeat, zsend.complete);
	int success_index = zconf.fsconf.success_index;
	assert(success_index < fs->len);
	int is_success = fs_get_uint64_by_index(fs, success_index);

	if (is_success) {
		zrecv.success_total++;
		if (!is_repeat) {
			zrecv.success_unique++;
			pbm_set(seen, ntohl(src_ip));
		}
		if (zsend.complete) {
			zrecv.cooldown_total++;
			if (!is_repeat) {
				zrecv.cooldown_unique++;
			}
		}
	} else {
		zrecv.failure_total++;
	}
	// probe module includes app_success field
	if (zconf.fsconf.app_success_index >= 0) {
		int is_app_success = fs_get_uint64_by_index(fs,
				zconf.fsconf.app_success_index);
		if (is_app_success) {
			zrecv.app_success_total++;
			if (!is_repeat) {
				zrecv.app_success_unique++;
			}
		}
	}

	fieldset_t *o = NULL;
	// we need to translate the data provided by the probe module
	// into a fieldset that can be used by the output module
	if (!is_success && zconf.filter_unsuccessful) {
		goto cleanup;
	}
	if (is_repeat && zconf.filter_duplicates) {
		goto cleanup;
	}
	if (!evaluate_expression(zconf.filter.expression, fs)) {
		goto cleanup;
	}
	o = translate_fieldset(fs, &zconf.fsconf.translation);
	if (zconf.output_module && zconf.output_module->process_ip) {
		zconf.output_module->process_ip(o);
	}
cleanup:
	fs_free(fs);
	free(o);
	if (zconf.output_module && zconf.output_module->update
			&& !(zrecv.success_unique % zconf.output_module->update_interval)) {
		zconf.output_module->update(&zconf, &zsend, &zrecv);
	}
}
コード例 #14
0
ファイル: tests2.c プロジェクト: scketches/funstrings
void fs_test(int tid)
{
  fun_string f[25];
  unsigned char d1[] = "kungfu\0kaleidescopes", d2[] = "funintheSun";
  size_t count;

  printf("[%d] START: FUN STRING test!\n", tid);

  assert(f[1] = fs_new(d1, 20, 0));
  assert(f[2] = fs_new(d1, 20, 0));
  assert(f[3] = fs_new(d2, 11, 0));

  assert(!fs_cmp(f[1], f[2]));
  assert(fs_cmp(f[1], f[3]));

  assert(f[4] = fs_resize(f[1], 10));
  assert(f[5] = fs_resize(f[2], 15));
  assert(f[6] = fs_resize(f[3], 10));
  
  assert(fs_cmp(f[4], f[5]));
  assert(!fs_ncmp(f[4], f[5], 10));
  assert(!fs_ncmp(f[3], f[6], 10));

  assert(f[7] = fs_access(f[1], 3, 10));
  assert(f[8] = fs_access(f[4], 3, 5));
  assert(f[9] = fs_access(f[5], 5, 10));

  assert(!fs_ncmp(f[7], f[8], 3));
  assert(fs_cmp(f[7], f[8]));
  assert(fs_ncmp(f[7], f[9], 5));

  assert(10 == fs_len(f[7]));
  assert(5 == fs_len(f[8]));
  assert(10 == fs_len(f[7]));
  assert(20 == fs_len(f[1]));
  assert(10 == fs_len(f[4]));
  assert(11 == fs_len(f[3]));

  assert(f[10] = fs_set(f[1], '9', 40));
  assert(f[11] = fs_set(f[1], '9', 50));
  assert(f[12] = fs_set(f[1], 'A', 40));

  assert(!fs_ncmp(f[10], f[11], 30));
  assert(fs_cmp(f[10], f[11]));
  assert(fs_cmp(f[10], f[12]));
  assert(fs_cmp(f[1], f[10]));

  assert(f[13] = fs_dup(f[1]));
  assert(f[14] = fs_dup(f[2]));
  assert(f[15] = fs_dup(f[4]));

  assert(!fs_cmp(f[13], f[14]));
  assert(!fs_ncmp(f[13], f[15], 5));
  assert(fs_cmp(f[13], f[6]));

  assert(f[16] = fs_chr(f[1], 'g'));
  assert(f[17] = fs_chr(f[4], 'g'));
  assert(f[18] = fs_rchr(f[1], 'g'));

  assert(!fs_ncmp(f[16], f[17], 3));
  assert(!fs_cmp(f[16], f[18]));
  assert(fs_cmp(f[16], f[7]));

  assert(f[19] = fs_cat(f[3], f[16]));
  assert(f[20] = fs_cat(f[3], f[18]));
  assert(f[21] = fs_ncat(f[3], f[17], 2));

  assert(!fs_cmp(f[19], f[20]));
  assert(fs_cmp(f[19], f[21]));
  assert(!fs_ncmp(f[19], f[21], 13));

  // To test
  // cat
  // ncat

  fs_free(&f[1]);
  fs_free(&f[2]);
  fs_free(&f[3]);
  fs_free(&f[4]);
  fs_free(&f[5]);
  fs_free(&f[6]);
  fs_free(&f[7]);
  fs_free(&f[8]);
  fs_free(&f[9]);
  fs_free(&f[10]);
  fs_free(&f[11]);
  fs_free(&f[12]);
  fs_free(&f[13]);
  fs_free(&f[14]);
  fs_free(&f[15]);
  fs_free(&f[16]);
  fs_free(&f[17]);
  fs_free(&f[18]);
  fs_free(&f[19]);
  fs_free(&f[20]);
  fs_free(&f[21]);

  printf("[%d] Strings destroyed!\n", tid);

  printf("[%d] END: FUN STRING Test!\n\n", tid);
  return;
}
コード例 #15
0
ファイル: rb_define.c プロジェクト: Passerby/fsnet
VALUE
rb_Node_initialize(int argc, VALUE* argv, VALUE self){
    
    // connect
    if(argc == 3){
        VALUE server_value = argv[0];
        Check_Type(argv[1], T_STRING);
        Check_Type(argv[2], T_FIXNUM);
        
        struct fs_server* server = NULL;
        Data_Get_Struct(server_value, struct fs_server, server);
        
        
        struct fs_node* node = fs_create_node(server);
        
        struct fs_node_addr addr;
        strcpy(addr.addr, StringValueCStr(argv[1]));
        addr.port = FIX2INT(argv[2]);
        
        
        if(fs_server_connect_node(server, node, &addr)){
            
            RDATA(self)->data = node;
            fs_node_set_script_id(node, self);
            rb_funcall(self, rb_intern("server="), 1, server_value);
            
        }else{
            fs_free(node);
            RDATA(node)->data = NULL;
            rb_raise(rb_eRuntimeError, "connect %s:%d fail", addr.addr, addr.port);
        }
        return Qnil;
    }
        
    // accept
    if(argc == 2){
        Check_Type(argv[0], T_DATA);
        Check_Type(argv[1], T_FIXNUM);
        
        VALUE v_server  = argv[0];
        fs_id node_id = FIX2INT(argv[1]);
        
        struct fs_server* server;
        Data_Get_Struct(v_server, struct fs_server, server);
        
        
        struct fs_node* node = fs_server_find_node_by_id(server, node_id);
        
        if(node){
            RDATA(self)->data = node;
            fs_node_set_script_id(node, self);
            rb_funcall(self, rb_intern("server="), 1, v_server);
        }else{
            
            rb_raise(rb_eRuntimeError, "bind node error");
        }
        return Qnil;
    }
    
    rb_raise(rb_eArgError, "#<ArgumentError: wrong number of arguments (%d for %d)>", argc, 3);
    
    return Qnil;
}
コード例 #16
0
ファイル: rb_define.c プロジェクト: Passerby/fsnet
void
wrap_Server_free (struct fs_server* server)
{
    fs_server_set_script_id(server, Qnil);
    fs_free(server);
}
コード例 #17
0
ファイル: FSParams.cpp プロジェクト: frodosens/fsnet
FSParamsString::~FSParamsString(){
    fs_free(m_data);
    this->val = NULL;
}
コード例 #18
0
ファイル: FSParams.cpp プロジェクト: frodosens/fsnet
void FSParams::init_from_stream(struct fs_input_stream* is, fs_bool check_head){
    
    fs_bool inval = true;
    if(check_head){
        params_type type = (params_type)fs_stream_read_byte(is);
        inval = (type == PARAMS_TYPE_DOUCMENT || type == PARAMS_TYPE_ARRAY);
    }
    if(inval){
        uint16_t size = fs_stream_read_uint16(is);
        
        for(int i = 0 ; i < size ; i++){
            char* key = NULL;
            
            if(type_hash){
                fs_stream_read_string(is, &key);
            }else{
                key = (char*)fs_malloc(12);
                sprintf(key, "%d", i);
            }
            
            params_type child_type = (params_type)fs_stream_read_byte(is);
            
            switch (child_type) {
                case PARAMS_TYPE_INT:
                    set(key, fs_stream_read_int32(is));
                    break;
                case PARAMS_TYPE_INT64:
                    set(key, fs_stream_read_int64(is));
                    break;
                case PARAMS_TYPE_BOOL:
                    set(key, fs_stream_read_byte(is) == 1);
                    break;
                case PARAMS_TYPE_DOUBLE:
                    set(key, fs_stream_read_double(is));
                    break;
                case PARAMS_TYPE_ARRAY:
                {
                    FSParamsArray* array = new FSParamsArray;
                    array->init_from_stream(is, false);
                    set(key, array, PARAMS_TYPE_ARRAY);
                    break;
                }
                case PARAMS_TYPE_DOUCMENT:{
                    FSParamsHash* hash = new FSParamsHash;
                    hash->init_from_stream(is, false);
                    set(key, hash, PARAMS_TYPE_DOUCMENT);
                    break;
                }
                case PARAMS_TYPE_UTF8:{
                    char* value;
                    size_t len = fs_stream_read_string(is, &value);
                    set(key, (void*)value, (uint32_t)len);
                    break;
                }
                case PARAMS_TYPE_NULL:
                    set(key, NULL, 0, PARAMS_TYPE_NULL);
                    break;
                default:
                    break;
            }
            if(key){
                fs_free(key);
            }
        }
    }
    
}