Example #1
0
/* cm.ret is also set to an error <0 or the read length */
void *ReadHandler(struct handlerdata *hd, struct client_msg *cm, struct one_wire_query *owq)
{
	BYTE * retbuffer = NULL ;
	SIZE_OR_ERROR read_or_error;

	LEVEL_DEBUG("ReadHandler start");
	if (hd == NULL || owq == NULL || cm == NULL) {
		LEVEL_DEBUG("ReadHandler: illegal null inputs hd==%p owq==%p cm==%p", hd, owq, cm);
		return NULL;			// only sane response for bad inputs
	}

	LEVEL_DEBUG("ReadHandler: From Client sm->payload=%d sm->size=%d sm->offset=%d", hd->sm.payload, hd->sm.size, hd->sm.offset);

	if (hd->sm.payload >= PATH_MAX) {
		cm->ret = -EMSGSIZE;
	} else if ((hd->sm.size <= 0) || (hd->sm.size > MAX_OWSERVER_PROTOCOL_PAYLOAD_SIZE)) {
		cm->ret = -EMSGSIZE;
		LEVEL_DEBUG("ReadHandler: error hd->sm.size == %d", hd->sm.size);
	} else if ( BAD( OWQ_allocate_read_buffer(owq)) ) {	// allocate read buffer
		LEVEL_DEBUG("ReadHandler: can't allocate memory");
		cm->ret = -ENOBUFS;
	} else {
		struct parsedname *pn = PN(owq);

		if ( OWQ_size(owq) > (size_t) hd->sm.size ) {
			OWQ_size(owq) = hd->sm.size ;
		}
		OWQ_offset(owq) = hd->sm.offset ;

		LEVEL_DEBUG("ReadHandler: call FS_read_postparse on %s", pn->path);
		read_or_error = FS_read_postparse(owq);
		LEVEL_DEBUG("ReadHandler: FS_read_postparse read on %s return = %d", pn->path, read_or_error);

		Debug_OWQ(owq);

		if (read_or_error <= 0) {
			LEVEL_DEBUG("ReadHandler: FS_read_postparse error %d", read_or_error);
			cm->ret = read_or_error;
		} else {
			LEVEL_DEBUG("ReadHandler: FS_read_postparse ok size=%d", read_or_error);
			// make return size smaller (just large enough)
			cm->payload = read_or_error;
			cm->offset = hd->sm.offset;
			cm->size = read_or_error;
			cm->ret = read_or_error;
			/* Move this pointer, and let owfree remove it instead of OWQ_destroy() */
			retbuffer = (BYTE *)OWQ_buffer(owq);
			OWQ_buffer(owq) = NULL;
		}
	}
	LEVEL_DEBUG("ReadHandler: To Client cm->payload=%d cm->size=%d cm->offset=%d", cm->payload, cm->size, cm->offset);
	if ((cm->size > 0)) {
		Debug_Bytes("Data returned to client",(BYTE *) OWQ_buffer(owq),cm->size) ;
	}
	return retbuffer;
}
Example #2
0
// Handles .n
static ZERO_OR_ERROR FS_read_a_part( struct one_wire_query *owq_part )
{
	struct parsedname *pn = PN(owq_part);
	size_t extension = pn->extension;
	struct filetype * ft = pn->selected_filetype ;
	struct one_wire_query * owq_all ;
	
	// bitfield
	if ( ft->format == ft_bitfield ) {
		return FS_read_a_bit( owq_part ) ;
	}

	// non-bitfield 
	owq_all = OWQ_create_aggregate( owq_part ) ;
	if ( owq_all == NO_ONE_WIRE_QUERY ) {
		return -ENOENT ;
	}
	
	// First fill the whole array with current values
	if ( FS_read_owq( owq_all ) < 0 ) {
		OWQ_destroy( owq_all ) ;
		return -EINVAL ;
	}

	// Copy ascii/binary field
	switch (ft->format) {
	case ft_binary:
	case ft_ascii:
	case ft_vascii:
	case ft_alias:
		{
			size_t extension_index;
			char *buffer_pointer = OWQ_buffer(owq_all);

			// All prior elements
			for (extension_index = 0; extension_index < extension; ++extension_index) {
				// move past their buffer position
				buffer_pointer += OWQ_array_length(owq_all, extension_index);
			}

			// now move current element's buffer to location
			OWQ_length(owq_part) = OWQ_array_length(owq_all, extension) ;
			memmove( OWQ_buffer(owq_part), buffer_pointer, OWQ_length(owq_part));
			break;
		}
	default:
		// Copy value field
		memcpy( &OWQ_val(owq_part), &OWQ_array(owq_all)[pn->extension], sizeof(union value_object) );
		break;
	}

	OWQ_destroy(owq_all);
	return 0 ;
}
Example #3
0
static ZERO_OR_ERROR FS_w_screenX(struct one_wire_query *owq)
{
	struct one_wire_query * owq_line ;
	int extension;

	struct parsedname *pn = PN(owq);

	int width = pn->selected_filetype->data.i;
	int rows = (width == 40) ? 2 : 4;	/* max number of rows */
	char *start_of_remaining_text = OWQ_buffer(owq);
	char *pointer_after_all_text = OWQ_buffer(owq) + OWQ_size(owq);

	if (OWQ_offset(owq)) {
		return -ERANGE;
	}

	if (BAD( OW_clear(pn) ) ) {
		return -EFAULT;
	}

	owq_line = OWQ_create_separate( 0, owq ) ;
	if ( owq_line == NO_ONE_WIRE_QUERY ) {
		return -ENOMEM ;
	}

	for (extension = 0; extension < rows; ++extension) {
		char *newline_location = memchr(start_of_remaining_text, '\n',
										pointer_after_all_text - start_of_remaining_text);
		OWQ_pn(owq_line).extension = extension;
		OWQ_buffer(owq_line) = start_of_remaining_text;
		if ((newline_location != NULL)
			&& (newline_location < start_of_remaining_text + width)) {
			OWQ_size(owq_line) = newline_location - start_of_remaining_text;
			start_of_remaining_text = newline_location + 1;	/* skip over newline */
		} else {
			char *lineend_location = start_of_remaining_text + width;
			if (lineend_location > pointer_after_all_text) {
				lineend_location = pointer_after_all_text;
			}
			OWQ_size(owq_line) = lineend_location - start_of_remaining_text;
			start_of_remaining_text = lineend_location;
		}
		if (FS_w_lineX(owq_line)) {
			OWQ_destroy( owq_line ) ;
			return -EINVAL;
		}
		if (start_of_remaining_text >= pointer_after_all_text)
			break;
	}
	OWQ_destroy( owq_line ) ;
	return 0;
}
Example #4
0
void _print_owq(struct one_wire_query *owq)
{
	char c[32];
	fprintf(stderr,"OWQ OneWireQuery structure of %s\n", PN(owq)->path);
	fprintf(stderr,"    OneWireQuery size=%lu offset=%lu, extension=%d\n",
		   (unsigned long) OWQ_size(owq), (unsigned long) OWQ_offset(owq), (int) OWQ_pn(owq).extension);
	if ( OWQ_buffer(owq) != NULL ) {
		Debug_Bytes("OneWireQuery buffer", (BYTE *) OWQ_buffer(owq), OWQ_size(owq));
	}
	fprintf(stderr,"    Cleanup = %.4X",OWQ_cleanup(owq));
	fprintf(stderr,"    OneWireQuery I=%d U=%u F=%G Y=%d D=%s\n", OWQ_I(owq), OWQ_U(owq), OWQ_F(owq), OWQ_Y(owq), SAFESTRING(ctime_r(&OWQ_D(owq), c)));
	fprintf(stderr,"--- OneWireQuery done\n");
}
Example #5
0
void OWQ_assign_write_buffer(const char *buffer, size_t size, off_t offset, struct one_wire_query *owq)
{
	// OWQ_buffer used for both read (non-const) and write (const)
#if ( __GNUC__ > 4 ) || (__GNUC__ == 4 && __GNUC_MINOR__ > 4 )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcast-qual"
	OWQ_buffer(owq) = (char *) buffer;
#pragma GCC diagnostic pop
#else
	OWQ_buffer(owq) = (char *) buffer;
#endif
	OWQ_size(owq) = size;
	OWQ_offset(owq) = offset;
}
static ZERO_OR_ERROR OW_script_read( FILE * script_f, struct one_wire_query * owq )
{
	size_t fr_return ;

	memset( OWQ_buffer(owq), 0, OWQ_size(owq) ) ;
	fr_return = fread( OWQ_buffer(owq), OWQ_size(owq), 1, script_f ) ;
	
	if ( fr_return == 0 && ferror(script_f) != 0 ) {
		LEVEL_DEBUG( "Could not read script data back for %s",PN(owq)->path ) ;
		return -EIO ;
	}
	
	return OWQ_parse_input( owq ) ;
}
Example #7
0
static ZERO_OR_ERROR FS_redefchar_hex(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	BYTE data[LCD_REDEFCHAR_LENGTH] ;
	
	if ( OWQ_size(owq) != LCD_REDEFCHAR_LENGTH * 2 ) {
		return -ERANGE ;
	}
	if ( OWQ_offset(owq) != 0 ) {
		return -ERANGE ;
	}
	string2bytes( OWQ_buffer(owq), data, LCD_REDEFCHAR_LENGTH ) ;
		
	return GB_to_Z_OR_E( OW_redefchar( OWQ_buffer(owq), pn ) ) ;
}
Example #8
0
static ZERO_OR_ERROR FS_Mscreen(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	size_t size = OWQ_size(owq);
	BYTE data[size];
	size_t i;
	for (i = 0; i < size; ++i) {
		// no upper ascii chars
		if (OWQ_buffer(owq)[i] & 0x80) {
			return -EINVAL;
		}
		data[i] = OWQ_buffer(owq)[i] | 0x80;
	}
	return GB_to_Z_OR_E( OW_w_pios(data, size, pn) ) ;
}
Example #9
0
// Handles: ALL
static ZERO_OR_ERROR FS_write_in_parts( struct one_wire_query *owq_all )
{
	struct one_wire_query * owq_part = OWQ_create_separate( 0, owq_all ) ;
	struct parsedname *pn = PN(owq_all);
	size_t elements = pn->selected_filetype->ag->elements;
	size_t extension ;
	char *buffer_pointer;
	ZERO_OR_ERROR z_or_e = 0 ;
	
	// Create a "single" OWQ copy to iterate with
	if ( owq_part == NO_ONE_WIRE_QUERY ) {
		return -ENOENT ;
	}

	// create a buffer for certain types
	// point to 0th element's buffer first
	buffer_pointer = OWQ_buffer(owq_all);
	OWQ_size(owq_part) = FileLength(PN(owq_part));
	OWQ_offset(owq_part) = 0;

	// loop through all eloements
	for (extension = 0; extension < elements; ++extension) {
		ZERO_OR_ERROR single_write;

		switch (pn->selected_filetype->format) {
		case ft_ascii:
		case ft_vascii:
		case ft_alias:
		case ft_binary:
			OWQ_length(owq_part) = OWQ_array_length(owq_all,extension) ;
			OWQ_buffer(owq_part) = buffer_pointer;
			buffer_pointer += OWQ_length(owq_part);
			break;
		default:
			memcpy(&OWQ_val(owq_part), &OWQ_array(owq_all)[extension], sizeof(union value_object));
			break;
		}

		OWQ_pn(owq_part).extension = extension;
		single_write = FS_write_owq(owq_part);

		if (single_write != 0) {
			z_or_e = single_write ;
		}
	}

	return z_or_e;
}
Example #10
0
static ZERO_OR_ERROR FS_w_TS(struct one_wire_query *owq)
{
	ZERO_OR_ERROR ret = 0;
	if (OWQ_size(owq) == 0 || OWQ_offset(owq) > 0) {
		return 0;				/* do nothing */
	}

	switch (OWQ_buffer(owq)[0]) {
	case 'C':
	case 'c':
		Globals.temp_scale = temp_celsius ;
		break;
	case 'F':
	case 'f':
		Globals.temp_scale = temp_fahrenheit ;
		break;
	case 'R':
	case 'r':
		Globals.temp_scale = temp_rankine ;
		break;
	case 'K':
	case 'k':
		Globals.temp_scale = temp_kelvin ;
		break;
	default:
		ret = -EINVAL;
	}
	SetLocalControlFlags() ;
	return ret;
}
Example #11
0
/* Use an single OWQ as a template for the aggregate one */
struct one_wire_query * OWQ_create_aggregate( struct one_wire_query * owq_single )
{
    int sz = sizeof( struct one_wire_query ) + OWQ_DEFAULT_READ_BUFFER_SIZE;
	struct one_wire_query * owq_all = owmalloc( sz );
	
	LEVEL_DEBUG("%s with extension ALL", PN(owq_single)->path);

	if ( owq_all == NO_ONE_WIRE_QUERY) {
		LEVEL_DEBUG("No memory to create object for extension ALL") ;
		return NO_ONE_WIRE_QUERY ;
	}
	
	memset(owq_all, 0, sz);
	OWQ_cleanup(owq_all) = owq_cleanup_owq ;
	
	memcpy( PN(owq_all), PN(owq_single), sizeof(struct parsedname) ) ;
	PN(owq_all)->extension = EXTENSION_ALL ;
	OWQ_buffer(owq_all) = (char *) (& owq_all[1]) ; // point just beyond the one_wire_query struct
	OWQ_size(owq_all) = OWQ_DEFAULT_READ_BUFFER_SIZE ;
	OWQ_offset(owq_all) = 0 ;
	if ( BAD( OWQ_allocate_array(owq_all)) ) {
		OWQ_destroy(owq_all);
		return NO_ONE_WIRE_QUERY ;
	}
	return owq_all ;
}
Example #12
0
void OWQ_create_temporary(struct one_wire_query *owq_temporary, char *buffer, size_t size, off_t offset, struct parsedname *pn)
{
	OWQ_buffer(owq_temporary) = buffer;
	OWQ_size(owq_temporary) = size;
	OWQ_offset(owq_temporary) = offset;
	memcpy(PN(owq_temporary), pn, sizeof(struct parsedname));
}
Example #13
0
/* Put a string ionto the OWQ structure and return the length
   check lengths and offsets as part of the process */
static SIZE_OR_ERROR OWQ_parse_output_offset_and_size(const char *string, size_t length, struct one_wire_query *owq)
{
	size_t copy_length = length;
	off_t offset = OWQ_offset(owq);
	Debug_Bytes("OWQ_parse_output_offset_and_size", (const BYTE *) string, length);

	/* offset is after the length of the string -- return 0 since
	   some conditions a read after the end is done automatically */
	if (offset > (off_t) length) {
		return 0;
	}

	/* correct length for offset (cannot be negative because of previous check) */
	copy_length -= offset;

	/* correct length for buffer space */
	if (copy_length > OWQ_size(owq)) {
		copy_length = OWQ_size(owq);
	}

	/* and copy */
	memcpy(OWQ_buffer(owq), &string[offset], copy_length);
	
	// Warning, this will overwrite the I U or DATA value, 
	// but that shouldn't matter since it's only called on ascii values
	// and all structure values
	OWQ_length(owq) = copy_length;

	return copy_length;
}
Example #14
0
GOOD_OR_BAD OWQ_allocate_write_buffer( const char * write_buffer, size_t buffer_length, off_t offset, struct one_wire_query * owq )
{
	char * buffer_copy ;
	
	if ( buffer_length == 0 ) {
		// Buffer size is zero. Allowed, but make it NULL and no cleanup needed.
		OWQ_size(owq) = 0 ;
		OWQ_offset(owq) = 0 ;
		return gbGOOD ;
	}
	
	buffer_copy = owmalloc( buffer_length+1) ;
	if ( buffer_copy == NULL) {
		// cannot allocate space for buffer
		LEVEL_DEBUG("Cannot allocate %ld bytes for buffer", buffer_length) ;
		OWQ_size(owq) = 0 ;
		OWQ_offset(owq) = 0 ;
		return gbBAD ;
	}
	
	memcpy( buffer_copy, write_buffer, buffer_length) ;
	buffer_copy[buffer_length] = '\0' ; // make sure it's zero-ended
	OWQ_buffer(owq) = buffer_copy ;
	OWQ_size(owq)   = buffer_length ;
	OWQ_length(owq) = buffer_length ;
	OWQ_offset(owq) = offset ;
	OWQ_cleanup(owq) |= owq_cleanup_buffer ; // buffer needs cleanup
	return gbGOOD ;
}
Example #15
0
void OWQ_destroy(struct one_wire_query *owq)
{
	if ( owq == NO_ONE_WIRE_QUERY) {
		return ;
	}
	
	if ( OWQ_cleanup(owq) & owq_cleanup_buffer ) {
		owfree(OWQ_buffer(owq)) ;
	}
	
	if ( OWQ_cleanup(owq) & owq_cleanup_rbuffer ) {
		//owfree(OWQ_read_buffer(owq)) ;
	}
	
	if ( OWQ_cleanup(owq) & owq_cleanup_array ) {
		owfree(OWQ_array(owq)) ;
	}
	
	if ( OWQ_cleanup(owq) & owq_cleanup_pn ) {
		FS_ParsedName_destroy(PN(owq)) ;
	}

	if ( OWQ_cleanup(owq) & owq_cleanup_owq ) {
		owfree(owq) ;
	} else {
		OWQ_cleanup(owq) = owq_cleanup_none ;
	}
}
Example #16
0
/* Create the Parsename structure and create the buffer */
struct one_wire_query * OWQ_create_from_path(const char *path)
{
	int sz = sizeof( struct one_wire_query ) + OWQ_DEFAULT_READ_BUFFER_SIZE;
	struct one_wire_query * owq = owmalloc( sz );
	
	LEVEL_DEBUG("%s", path);

	if ( owq== NO_ONE_WIRE_QUERY) {
		LEVEL_DEBUG("No memory to create object for path %s",path) ;
		return NO_ONE_WIRE_QUERY ;
	}
	
	memset(owq, 0, sz);
	OWQ_cleanup(owq) = owq_cleanup_owq ;
	
	if ( GOOD( OWQ_parsename(path,owq) ) ) {
		if ( GOOD( OWQ_allocate_array(owq)) ) {
			/*   Add a 1 byte buffer by default. This distinguishes from filesystem calls at end of buffer */
			/*   Read bufer is provided by OWQ_assign_read_buffer or OWQ_allocate_read_buffer */
			OWQ_buffer(owq) = (char *) (& owq[1]) ; // point just beyond the one_wire_query struct
			OWQ_size(owq) = OWQ_DEFAULT_READ_BUFFER_SIZE ;
			return owq ;
		}
		OWQ_destroy(owq);
	}
	return NO_ONE_WIRE_QUERY ;
}
Example #17
0
static SIZE_OR_ERROR OWQ_parse_output_yesno(struct one_wire_query *owq)
{
	if (OWQ_size(owq) < PROPERTY_LENGTH_YESNO) {
		return -EMSGSIZE;
	}
	OWQ_buffer(owq)[0] = ((OWQ_Y(owq) & 0x1) == 0) ? '0' : '1';
	return ShouldTrim(PN(owq))? 1 : PROPERTY_LENGTH_YESNO;
}
Example #18
0
// print from current position
static ZERO_OR_ERROR FS_Hscreen(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	// y=0 is flag to do no position setting
	struct yx YX = { LCD_SAME_LOCATION_VALUE, LCD_SAME_LOCATION_VALUE, OWQ_buffer(owq), OWQ_size(owq), 0 } ;
	RETURN_ERROR_IF_BAD( OW_Hinit(pn) ) ;
	return GB_to_Z_OR_E( OW_Hprintyx(&YX, pn) );
}
Example #19
0
// print from specified positionh --
// either in ascii format "y.x:text" or "x:text"
// or binary (first 2 bytes are y and x)
static ZERO_OR_ERROR FS_Hscreenyx(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	struct yx YX = { 0, 0, OWQ_buffer(owq), OWQ_size(owq), 0 } ;

	RETURN_ERROR_IF_BAD( Parseyx( &YX )  ) ;
	RETURN_ERROR_IF_BAD( OW_Hinit(pn) ) ;
	return GB_to_Z_OR_E( OW_Hprintyx(&YX, pn) );
}
Example #20
0
// Print from home position
static ZERO_OR_ERROR FS_Hmessage(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	struct yx YX = { 1, 1, OWQ_buffer(owq), OWQ_size(owq), 0 } ;
	RETURN_ERROR_IF_BAD( OW_Hinit(pn) ) ;
	if (FS_Hclear(owq) != 0) {
		return -EINVAL;
	}
	return GB_to_Z_OR_E( OW_Hprintyx(&YX, pn) );
}
Example #21
0
static SIZE_OR_ERROR OWQ_parse_output_ascii_array(struct one_wire_query *owq)
{
	size_t extension;
	size_t elements = OWQ_pn(owq).selected_filetype->ag->elements;
	size_t total_length = 0;
	size_t current_offset = OWQ_array_length(owq, 0);

	for (extension = 0; extension < elements; ++extension) {
		total_length += OWQ_array_length(owq, extension);
	}

	for (extension = 1; extension < elements; ++extension) {
		memmove(&OWQ_buffer(owq)[current_offset + 1], &OWQ_buffer(owq)[current_offset], total_length - current_offset);
		OWQ_buffer(owq)[current_offset] = ',';
		++total_length;
		current_offset += 1 + OWQ_array_length(owq, extension);
	}

	return total_length;
}
Example #22
0
static ZERO_OR_ERROR FS_redefchar(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	
	if ( OWQ_size(owq) != LCD_REDEFCHAR_LENGTH ) {
		return -ERANGE ;
	}
	if ( OWQ_offset(owq) != 0 ) {
		return -ERANGE ;
	}
		
	return GB_to_Z_OR_E( OW_redefchar( OWQ_buffer(owq), pn ) ) ;
}
Example #23
0
static SIZE_OR_ERROR OWQ_parse_output_array_with_commas(struct one_wire_query *owq)
{
	struct one_wire_query owq_single;
	size_t extension;
	int len;
	size_t used_size = 0;
	size_t remaining_size = OWQ_size(owq);
	size_t elements = OWQ_pn(owq).selected_filetype->ag->elements;

	// loop though all array elements
	for (extension = 0; extension < elements; ++extension) {
		//printf("OWQ_parse_output_array_with_commas element=%d, size_used=%d, remaining=%d\n",(int)extension,(int)used_size,(int)remaining_size) ;
		// Prepare a copy of owq that only points to a single element
		memcpy(&owq_single, owq, sizeof(owq_single));
		OWQ_pn(&owq_single).extension = extension;
		memcpy(&OWQ_val(&owq_single), &OWQ_array(owq)[extension], sizeof(union value_object));
		// add the comma first (if not the first element and enough room)
		if (used_size > 0) {
			if (remaining_size == 0) {
				return -EFAULT;
			}
			OWQ_buffer(owq)[used_size] = ',';
			++used_size;
			--remaining_size;
		}
		// Now process the single element
		OWQ_buffer(&owq_single) = &OWQ_buffer(owq)[used_size];
		OWQ_size(&owq_single) = remaining_size;
		len = OWQ_parse_output(&owq_single);
		// any error aborts
		if (len < 0) {
			return len;
		}
		remaining_size -= len;
		used_size += len;
	}
	return used_size;
}
Example #24
0
/* No CRC -- 0xF0 code */
GOOD_OR_BAD COMMON_read_memory_F0(struct one_wire_query *owq, size_t page, size_t pagesize)
{
	off_t offset = OWQ_offset(owq) + page * pagesize;
	BYTE p[3] = { _1W_READ_F0, LOW_HIGH_ADDRESS(offset), };
	struct transaction_log t[] = {
		TRXN_START,
		TRXN_WRITE3(p),
		TRXN_READ((BYTE *) OWQ_buffer(owq), OWQ_size(owq)),
		TRXN_END,
	};

	Set_OWQ_length(owq);
	return BUS_transaction(t, PN(owq));
}
Example #25
0
static ZERO_OR_ERROR FS_w_port_raw(struct one_wire_query *owq)
{
	BYTE *buf = (BYTE *) OWQ_buffer(owq);
    size_t len = OWQ_size(owq);
	if (OWQ_offset(owq) != 0)
		return -EINVAL; /* ignore? */

	// Hack for testing, otherwise we'll not be able to clear a port using owwrite.
	if(len == 1 && (*buf == '0' || *buf == '1')) {
		*buf -= '0';
	}

	return GB_to_Z_OR_E( OW_w_std( buf,len, M_PORT,OWQ_pn(owq).extension, PN(owq)) ) ;
}
Example #26
0
/* Higher level add of a one-wire-query object */
GOOD_OR_BAD OWQ_Cache_Add(const struct one_wire_query *owq)
{
	const struct parsedname *pn = PN(owq);
	if (pn->extension == EXTENSION_ALL) {
		switch (pn->selected_filetype->format) {
		case ft_ascii:
		case ft_vascii:
		case ft_alias:
		case ft_binary:
			return gbBAD;			// cache of string arrays not supported
		case ft_integer:
		case ft_unsigned:
		case ft_yesno:
		case ft_date:
		case ft_float:
		case ft_pressure:
		case ft_temperature:
		case ft_tempgap:
			LEVEL_DEBUG("Adding data for %s", SAFESTRING(pn->path) );
			return Cache_Add(OWQ_array(owq), (pn->selected_filetype->ag->elements) * sizeof(union value_object), pn);
		default:
			return gbBAD;
		}
	} else {
		switch (pn->selected_filetype->format) {
		case ft_ascii:
		case ft_vascii:
		case ft_alias:
		case ft_binary:
			if (OWQ_offset(owq) > 0) {
				return gbBAD;
			}
			LEVEL_DEBUG("Adding data for %s", SAFESTRING(pn->path) );
			return Cache_Add(OWQ_buffer(owq), OWQ_length(owq), pn);
		case ft_integer:
		case ft_unsigned:
		case ft_yesno:
		case ft_date:
		case ft_float:
		case ft_pressure:
		case ft_temperature:
		case ft_tempgap:
			LEVEL_DEBUG("Adding data for %s", SAFESTRING(pn->path) );
			return Cache_Add(&OWQ_val(owq), sizeof(union value_object), pn);
		default:
			return gbBAD;
		}
	}
}
Example #27
0
SIZE_OR_ERROR FS_get(const char *path, char **return_buffer, size_t * buffer_length)
{
	SIZE_OR_ERROR size = 0 ;		/* current buffer string length */
	OWQ_allocate_struct_and_pointer( owq ) ;

	/* Check the parameters */
	if (return_buffer == NULL) {
		//  No buffer for read result.
		return -EINVAL;
	}

	if (path == NULL) {
		path = "/";
	}

	*return_buffer = NULL;				// default return string on error

	if ( BAD( OWQ_create(path, owq) ) ) {	/* Can we parse the input string */
		return -ENOENT;
	}

	if ( IsDir( PN(owq) ) ) { /* A directory of some kind */
		struct charblob cb ;
		CharblobInit(&cb) ;
		getdir( &cb, owq ) ;
		size = CharblobLength(&cb) ;
		*return_buffer = copy_buffer( CharblobData(&cb), size ) ;
		CharblobClear( &cb ) ;
	} else { /* A regular file  -- so read */
		if ( GOOD(OWQ_allocate_read_buffer(owq)) ) { // make the space in the buffer
			size = FS_read_postparse(owq) ;
			*return_buffer = copy_buffer( OWQ_buffer(owq), size ) ;
		}
	}
	// the buffer is allocated by getdir or getval
	OWQ_destroy(owq);

	/* Check the parameters */
	if (*return_buffer == NULL) {
		//  no data.
		return -EINVAL;
	}

	if ( buffer_length != NULL ) {
		*buffer_length = size ;
	}
	return size ;
}
Example #28
0
static ZERO_OR_ERROR FS_w_PS(struct one_wire_query *owq)
{
	int ret = -EINVAL ;
	enum pressure_type pindex ;
	if (OWQ_size(owq) < 2 || OWQ_offset(owq) > 0) {
		return -EINVAL ;				/* do nothing */
	}

	for ( pindex = 0 ; pindex < pressure_end_mark ; ++pindex ) {
		if ( strncasecmp(  OWQ_buffer(owq), PressureScaleName(pindex), 2 ) == 0 ) {
			Globals.pressure_scale = pindex ;
			SetLocalControlFlags() ;
			ret = 0 ;
			break;
		}
	}
	return ret;
}
Example #29
0
// Standard Data via GET
void ChangeData(struct one_wire_query *owq)
{
	struct parsedname *pn = PN(owq);
	ASCII *value_string = OWQ_buffer(owq);
	
	/* Do command processing and make changes to 1-wire devices */
	LEVEL_DETAIL("New data path=%s value=%s", pn->path, value_string);
	switch (pn->selected_filetype->format) {
		case ft_binary:
			hex_only(value_string);
			OWQ_size(owq) = hex_convert(value_string);
			break;
		default:
			OWQ_size(owq) = strlen(value_string);
			break;
	}
	FS_write_postparse(owq);
}
Example #30
0
// create the buffer of size filesize
GOOD_OR_BAD OWQ_allocate_read_buffer(struct one_wire_query * owq )
{
	struct parsedname * pn = PN(owq) ;
	size_t size = FullFileLength(pn);

	if ( size > 0 ) {
		char * buffer = owmalloc(size+1) ;
		if ( buffer == NULL ) {
			return gbBAD ;
		}
		memset(buffer,0,size+1) ;
		OWQ_buffer(owq) = buffer ;
		OWQ_size(owq) = size ;
		OWQ_offset(owq) = 0 ;
		OWQ_cleanup(owq) |= owq_cleanup_buffer ;
	}
	return gbGOOD;
}