Beispiel #1
0
void wpacket_destroy(wpacket_t *w)
{
	buffer_release(&(*w)->buf);
	buffer_release(&(*w)->writebuf);
	FREE((*w)->allocator,*w);
	*w = NULL;
}
Beispiel #2
0
void      rpacket_destroy(rpacket_t *r) {
    //释放所有对buffer_t的引用
    buffer_release(&(*r)->buf);
    buffer_release(&(*r)->readbuf);
    buffer_release(&(*r)->binbuf);
    FREE((*r)->allocator,*r);
    *r = 0;
}
Beispiel #3
0
void wpacket_destroy(wpacket_t *w)
{
	buffer_release(&(*w)->buf);
	buffer_release(&(*w)->writebuf);
	LIST_PUSH_BACK(g_wpacket_pool,*w);
	//free(*w);
	*w = 0;
}
Beispiel #4
0
void rpk_destroy(rpacket_t *r)
{
	//释放所有对buffer_t的引用
    buffer_release(&PACKET_BUF(*r));//(*r)->base.buf);
	buffer_release(&(*r)->readbuf);
	buffer_release(&(*r)->binbuf);
    FREE(rpacket_allocator,*r);
	*r = 0;
}
Beispiel #5
0
void connection_destroy(void *arg)
{
	struct connection *c = (struct connection*)arg;
	unregister_timer(con2wheelitem(c));
    wpacket_t w;
    while((w = LLIST_POP(wpacket_t,&c->send_list))!=NULL)
        wpk_destroy(&w);
    buffer_release(&c->unpack_buf);
    buffer_release(&c->next_recv_buf);
    free(c);
    //printf("connection_destroy\n");
}
Beispiel #6
0
static char *parse_delimited_text(const char **s) {
	Buffer buf;
	bool escaped = false;
	char delim = **s;

	if (!delim)
		return NULL;
	buffer_init(&buf);

	for ((*s)++; **s && (**s != delim || escaped); (*s)++) {
		if (!escaped && **s == '\\') {
			escaped = true;
			continue;
		}

		char c = **s;

		if (escaped) {
			escaped = false;
			switch (**s) {
			case '\n':
				continue;
			case 'n':
				c = '\n';
				break;
			case 't':
				c = '\t';
				break;
			default:
				if (**s != '\\' && **s != delim)
					buffer_append(&buf, "\\", 1);
				break;
			}
		}

		if (!buffer_append(&buf, &c, 1)) {
			buffer_release(&buf);
			return NULL;
		}
	}

	if (**s == delim)
		(*s)++;

	if (!buffer_append(&buf, "\0", 1)) {
		buffer_release(&buf);
		return NULL;
	}

	return buf.data;
}
Beispiel #7
0
void vis_free(Vis *vis) {
	if (!vis)
		return;
	if (vis->event && vis->event->vis_quit)
		vis->event->vis_quit(vis);
	vis->event = NULL;
	while (vis->windows)
		vis_window_close(vis->windows);
	file_free(vis, vis->command_file);
	file_free(vis, vis->search_file);
	file_free(vis, vis->error_file);
	for (int i = 0; i < LENGTH(vis->registers); i++)
		register_release(&vis->registers[i]);
	vis->ui->free(vis->ui);
	map_free(vis->cmds);
	map_free_full(vis->usercmds);
	map_free(vis->options);
	map_free(vis->actions);
	map_free(vis->keymap);
	buffer_release(&vis->input_queue);
	for (int i = 0; i < VIS_MODE_INVALID; i++)
		map_free(vis_modes[i].bindings);
	array_release_full(&vis->motions);
	array_release_full(&vis->textobjects);
	free(vis);
}
Beispiel #8
0
int connection_destroy(struct connection** c)
{
	if(!(*c)->recv_overlap.isUsed && !(*c)->send_overlap.isUsed)
	{ 
		wpacket_t w;
		while(w = LINK_LIST_POP(wpacket_t,(*c)->send_list))
			wpacket_destroy(&w);
		LINK_LIST_DESTROY(&(*c)->send_list);
		buffer_release(&(*c)->unpack_buf);
		buffer_release(&(*c)->next_recv_buf);
		free(*c);
		*c = 0;
		return 0;
	}
	return -1;
}
Beispiel #9
0
static char* load_query( const char* filename ) {
	FILE* fp;

	// Sanity check
	if( ! filename || ! *filename ) {
		fprintf( stderr, "Name of query file is empty or missing\n" );
		return NULL;
	}

	// Open query file, or use standard input
	if( ! strcmp( filename, "-" ) )
		fp = stdin;
	else {
		fp = fopen( filename, "r" );
		if( !fp ) {
			fprintf( stderr, "Unable to open query file \"%s\"\n", filename );
			return NULL;
		}
	}

	// Load file into a growing_buffer
	size_t num_read;
	char buf[ BUFSIZ + 1 ];
	growing_buffer* gb = buffer_init( sizeof( buf ) );

	while( ( num_read = fread( buf, 1, sizeof( buf ) - 1, fp ) ) ) {
		buf[ num_read ] = '\0';
		buffer_add( gb, buf );
	}

	if( fp != stdin )
		fclose( fp );

	return buffer_release( gb );
}
Beispiel #10
0
void uv_udp_handle_t::write(request_udp_write_t& request)
{
	int32_t err = UV_UNKNOWN;
	if (request.m_shared_write) {
		uv_udp_handle_t* handle = (uv_udp_handle_t*)singleton_ref(network_t).get_shared_write_socket(request.m_socket_fd);
		if (handle != NULL) {
			uint32_t length = request.m_length > 0 ? request.m_length : (uint32_t)buffer_data_length(request.m_buffer);
			if (uv_is_closing((uv_handle_t*)handle)) {
				err = NL_EUDPSCLOSED;
			} else {
				err = handle->write_handle(request);
			}
		} else {
			err = NL_EUDPNOWSHARED;
		}
	} else {
		err = request.m_socket_handle->write_handle(request);
	}
	if (err != UV_OK) { /* write error had been occurred */
		if (request.m_length > 0) {
			nl_free((void*)request.m_string);
		} else {
			buffer_release(request.m_buffer);
		}
		if (request.m_session != LUA_REFNIL) {
			singleton_ref(node_lua_t).context_send(request.m_source, 0, request.m_session, RESPONSE_UDP_WRITE, (nl_err_code)err);
		}
	}
}
Beispiel #11
0
struct gwseriport *gwseriport_create(const char *ttypath,int uart_speed)
{
        struct gwseriport *s = malloc(sizeof(*s));
        if(s == NULL)
                return NULL;
        memset(s,0,sizeof(*s));

        int fd = open_seriport(ttypath,uart_speed);
        if(fd < 0){
                free(s);
                return NULL;
        }

        s->recvbuf = buffer_create(1024);
        s->fd = fd;
        s->ttypath = strdup(ttypath);

        if(aeCreateFileEvent(server.el,fd,AE_READABLE,seriportHandler,s) == AE_ERR){
                close(fd);
                buffer_release(s->recvbuf);
                free(s);
                return NULL;
        }

        listAddNodeTail(server.seriports,s);
        
        return s;
}
/* ser_phy API function */
void ser_phy_close(void)
{
    m_spi_master_state = SER_PHY_STATE_DISABLED;

    m_callback_events_handler = NULL;

    buffer_release(&mp_tx_buffer, &m_tx_buf_len);
    buffer_release(&mp_rx_buffer, &m_rx_buf_len);
    m_tx_packet_length             = 0;
    m_accumulated_tx_packet_length = 0;
    m_current_tx_packet_length     = 0;
    m_rx_packet_length             = 0;
    m_accumulated_rx_packet_length = 0;
    m_current_rx_packet_length     = 0;
    ser_phy_deinit_gpiote();
    spi_master_close(SER_PHY_SPI_MASTER);
}
Beispiel #13
0
static void buffer_destroy(void *b)
{
	buffer_t _b = (buffer_t)b;
	if(_b->next)
		buffer_release(&(_b)->next);
    FREE(buffer_allocator,_b);
	b = 0;
}
Beispiel #14
0
static inline void buffer_destroy(void *b)
{
	buffer_t _b = (buffer_t)b;
	if(_b->next)
		buffer_release(&(_b)->next);
	FREE(NULL,_b);
	b = 0;
}
Beispiel #15
0
static void content(void)
{
    char current;

    /*
     * We should get one character at a time.
     */
    assert(strlen(yytext) == 1);

    current = yytext[0];
    if (current == EOF)
	return;
    
    if (is_newline(current)) {
	 newline();
	 return;
    }
    buffer_push_char(current_buf, current);

    /*
     * Forcing newline changes 'text' so lets do it after we've pushed
     * it to the buffer.
     */
    if (wrap_long_lines && need_wrap(current_buf)) {
	struct buffer tmp;
	buffer_init(&tmp, buffer_size(current_buf));
	/*
	 * Find last character that was not whitespace
	 */
	for (;;) {
	    int c;
	    if (buffer_size(current_buf) == 0)
		break;

	    c = buffer_pop_char(current_buf);
	    if (is_whitespace(c)) {
		/*
		 * Do not push whitespace because it would appear
		 * after the newline.
		 */
		break;
	    }
	    /*
	     * Characters are put in tmp buffer in reverse order.
	     */
	    buffer_push_char(&tmp, c);
	}
	force_newline_for_wrap(current_buf);
	/*
	 * Restore non-wrapped text into buffer.
	 */
	while (buffer_size(&tmp) > 0) {
	    buffer_push_char(current_buf, buffer_pop_char(&tmp));
	}
	buffer_release(&tmp);
    }
}
Beispiel #16
0
void cleanup(cog *c){
  switch(c->type){
    case COG_CONCAT:
      cleanup(c->data.concat.lhs);
      cleanup(c->data.concat.rhs);
      break;
    case COG_BTREE:
      cleanup(c->data.btree.lhs);
      cleanup(c->data.btree.rhs);
      break;
    case COG_ARRAY:
      buffer_release(c->data.array.records);
      break;
    case COG_SORTEDARRAY:
      buffer_release(c->data.sortedarray.records);
      break;
  }
  free_cog(c);
}
Beispiel #17
0
int connection_destroy(struct connection** c)
{
	if(!(*c)->recv_overlap.isUsed && !(*c)->send_overlap.isUsed)
	{ 
		wpacket_t w;
		while((w = LINK_LIST_POP(wpacket_t,(*c)->send_list))!=NULL)
			wpacket_destroy(&w);
		LINK_LIST_DESTROY(&(*c)->send_list);
		buffer_release(&(*c)->unpack_buf);
		buffer_release(&(*c)->next_recv_buf);
		if((*c)->wheelitem)
			DestroyWheelItem(&((*c)->wheelitem));
		free(*c);
		*c = NULL;
		printf("connection_destroy\n");
		return 0;
	}
	return -1;
}
Beispiel #18
0
int vsprintf(char *string, const char *fmt, va_list ap)
{
  struct buffer b;
  buffer_init(&b);
  vbprintf(&b, fmt, ap);
  memcpy(string, b.buffer, b.position);
  string[b.position]= '\0';
  buffer_release(&b);
  return b.position;
}
Beispiel #19
0
buffer_t buffer_acquire(buffer_t b1,buffer_t b2)
{
	if(b1 == b2)
		return b1;	
	if(b2)
		ref_increase(&b2->_refbase);
	if(b1)
		buffer_release(&b1);

	return b2;
}
Beispiel #20
0
char* jsonObjectToXML(const jsonObject* obj) {

	if (!obj)
		return strdup("<null/>");
	
	growing_buffer * res_xml = buffer_init(1024);

	_recurse_jsonObjectToXML( obj, res_xml );
	return buffer_release(res_xml);

}
Beispiel #21
0
int main(void) {
	buffer_t buf;

	buffer_create(&buf, LIBNET_BM_MEMORY);
	buffer_write_formatted(&buf, "Hallo Welt\r\nEinfach\tmal\tden\tBuffer\ttesten.\n");
	buffer_set_mode(&buf, LIBNET_BM_FILE);
	buffer_release(&buf);

	printf("\r\n\r\nLast Error: %s (%d)\n", libnet_str_error(libnet_error_get()), libnet_error_get());

	return 0;
}
Beispiel #22
0
int fat32_init( t_16 dev )
{
	FAT32_BOOTSEC* boot;
	void* buf;
	fat32 = &fatdev;
	root = &rootfile;
	memset( fat32, 0, sizeof(FAT32DEV) );

	buf = buffer_read( dev, 0 );	//读取第一块 1KB
	boot = (FAT32_BOOTSEC*)buf;
	if( boot->EBR != 0x28 && boot->EBR !=0x29 )
	{
		//printf("Not fat32 system\n");
		buffer_release( buf );
		return -1;
	}
	printf("fat32 System OEM: %s\n", boot-> OEM );
	fat32->fats = boot->Fats;//
	fat32->secPerClu = boot->SecPerClu;//
	fat32->secPerFat = boot->SecPerFat;	//每fat扇区数
	fat32->bytPerSec = boot->BytPerSec;	//每扇区字节数 512
	fat32->secReserved = boot->SecReserved;	//保留扇区数
	fat32->rootClu = boot->RootCluster;	//根目录簇号
	
	buffer_release( buf );
	//caculate some information
	fat32->fatAddr = fat32->bytPerSec * fat32->secReserved;	//fat基址
	//printf("fat addr: 0x%X\n", fat32->FatAddr);
	fat32->dataAddr = fat32->fatAddr + fat32->fats * fat32->secPerFat *fat32->bytPerSec;	//数据区基址
	fat32->bytPerClu = fat32->bytPerSec * fat32->secPerClu;
	printf("fat32 RootClu: 0x%X  data_addr: 0x%X  bytPerClu:%x  fatAddr:%x\n",
        fat32->rootClu, fat32->dataAddr, fat32->bytPerClu, fat32->fatAddr );
	//设置根目录
	memset( root, 0, sizeof(FILE_DESC) );
	root->dev = dev;
	root->data = fat32->rootClu;	//根目录的簇
	root->attribute = FILE_ATTR_ISDIR;
	root->dev_info = fat32;
	return 0;
}
Beispiel #23
0
void indent(FILE * input, FILE * output, struct indent_options * opts)
{
    set_options(opts);

    buffer_init(&primary_buf,   BUFFER_INITIAL_CAPACITY);
    buffer_init(&secondary_buf, BUFFER_INITIAL_CAPACITY);
    buffer_init(&tag_buf,       BUFFER_INITIAL_CAPACITY);

    current_buf   = &primary_buf;
    yyin          = input;
    indent_output = output;
    yylex();

    /*
     * There might not have been a newline before EOF.
     */
    buffer_flush(current_buf, indent_output);

    buffer_release(&primary_buf);
    buffer_release(&secondary_buf);
    buffer_release(&tag_buf);
}
Beispiel #24
0
void gwseriport_release(struct gwseriport *s)
{
        aeDeleteFileEvent(server.el,s->fd,AE_READABLE);
        aeDeleteFileEvent(server.el,s->fd,AE_WRITABLE);
        close(s->fd);
        buffer_release(s->recvbuf);

        listNode *ln = listSearchKey(server.seriports,s);
        assert(ln != NULL);
        listDelNode(server.seriports,ln);

        free(s);
}
Beispiel #25
0
static int oilsAuthLoginVerifyPassword(const osrfMethodContext* ctx, 
    int user_id, const char* username, const char* password) {

    // build the cache key
    growing_buffer* gb = buffer_init(64); // free me
    buffer_add(gb, OILS_AUTH_CACHE_PRFX);
    buffer_add(gb, username);
    buffer_add(gb, OILS_AUTH_COUNT_SFFX);
    char* countkey = buffer_release(gb); // free me

    jsonObject* countobject = osrfCacheGetObject(countkey); // free me

    long failcount = 0;
    if (countobject) {
        failcount = (long) jsonObjectGetNumber(countobject);

        if (failcount >= _oilsAuthBlockCount) {
            // User is blocked.  Don't waste any more CPU cycles on them.

            osrfLogInfo(OSRF_LOG_MARK, 
                "oilsAuth found too many recent failures for '%s' : %i, "
                "forcing failure state.", username, failcount);

            jsonObjectFree(countobject);
            free(countkey);   
            return 0;
        }
    }

    int verified = oilsAuthLoginCheckPassword(user_id, password);

    if (!verified) { // login failed.  increment failure counter.
        failcount++;

        if (countobject) {
            // append to existing counter
            jsonObjectSetNumber(countobject, failcount);

        } else { 
            // first failure, create a new counter
            countobject = jsonNewNumberObject((double) failcount);
        }

        osrfCachePutObject(countkey, countobject, _oilsAuthBlockTimeout);
    }

    jsonObjectFree(countobject); // NULL OK
    free(countkey);

    return verified;
}
Beispiel #26
0
void uv_udp_handle_t::on_write(uv_udp_send_t* req, int status)
{
	write_uv_request_t *uv_request = (write_uv_request_t*)req->data;
	uv_udp_handle_t *socket_handle = (uv_udp_handle_t*)(req->handle->data);
	if (uv_request->m_length > 0) {
		nl_free((void*)uv_request->m_string);
	} else {
		buffer_release(uv_request->m_buffer);
	}
	if (uv_request->m_session != LUA_REFNIL) {
		singleton_ref(node_lua_t).context_send(uv_request->m_source, 0, uv_request->m_session, RESPONSE_UDP_WRITE, status == 0 ? UV_OK : singleton_ref(network_t).last_error());
	}
	socket_handle->put_write_cached_request(uv_request);
}
Beispiel #27
0
static char* _escape_xml (const char* text) {
	growing_buffer* b = buffer_init(256);
	int len = strlen(text);
	int i;
	for (i = 0; i < len; i++) {
		if (text[i] == '&')
			buffer_add(b,"&amp;");
		else if (text[i] == '<')
			buffer_add(b,"&lt;");
		else if (text[i] == '>')
			buffer_add(b,"&gt;");
		else
			buffer_add_char(b,text[i]);
	}
	return buffer_release(b);
}
Beispiel #28
0
/**
 * Returns true if the provided password is correct.
 * Turn the password into the nested md5 hash required of migrated
 * passwords, then check the password in the DB.
 */
static int oilsAuthLoginCheckPassword(int user_id, const char* password) {

    growing_buffer* gb = buffer_init(33); // free me 1
    char* salt = oilsAuthGetSalt(user_id); // free me 2
    char* passhash = md5sum(password); // free me 3

    buffer_add(gb, salt); // gb strdup's internally
    buffer_add(gb, passhash);

    free(salt); // free 2
    free(passhash); // free 3

    // salt + md5(password)
    passhash = buffer_release(gb); // free 1 ; free me 4
    char* finalpass = md5sum(passhash); // free me 5

    free(passhash); // free 4

    jsonObject *arr = jsonNewObjectType(JSON_ARRAY);
    jsonObjectPush(arr, jsonNewObject("actor.verify_passwd"));
    jsonObjectPush(arr, jsonNewNumberObject((long) user_id));
    jsonObjectPush(arr, jsonNewObject("main"));
    jsonObjectPush(arr, jsonNewObject(finalpass));
    jsonObject *params = jsonNewObjectType(JSON_HASH); // free me 6
    jsonObjectSetKey(params, "from", arr);

    free(finalpass); // free 5

    jsonObject* verify_obj = // free 
        oilsUtilsCStoreReq("open-ils.cstore.json_query", params);

    jsonObjectFree(params); // free 6

    if (!verify_obj) return 0; // error

    int verified = oilsUtilsIsDBTrue(
        jsonObjectGetString(
            jsonObjectGetKeyConst(verify_obj, "actor.verify_passwd")
        )
    );

    jsonObjectFree(verify_obj);

    return verified;
}
Beispiel #29
0
void editor_free(Editor *ed) {
	if (!ed)
		return;
	while (ed->windows)
		editor_window_close(ed->windows);
	file_free(ed, ed->prompt->file);
	window_free(ed->prompt);
	text_regex_free(ed->search_pattern);
	for (int i = 0; i < REG_LAST; i++)
		register_release(&ed->registers[i]);
	for (int i = 0; i < MACRO_LAST; i++)
		macro_release(&ed->macros[i]);
	editor_syntax_unload(ed);
	ed->ui->free(ed->ui);
	map_free(ed->cmds);
	map_free(ed->options);
	buffer_release(&ed->buffer_repeat);
	free(ed);
}
Beispiel #30
0
static char *parse_text(const char **s) {
	skip_spaces(s);
	if (**s != '\n')
		return parse_delimited_text(s);

	Buffer buf;
	buffer_init(&buf);
	const char *start = *s + 1;
	bool dot = false;

	for ((*s)++; **s && (!dot || **s != '\n'); (*s)++)
		dot = (**s == '.');

	if (!dot || !buffer_put(&buf, start, *s - start - 1) ||
	    !buffer_append(&buf, "\0", 1)) {
		buffer_release(&buf);
		return NULL;
	}

	return buf.data;
}