/*	-------------------------------------------	*/
private	int	create_provider(struct occi_category * optr, void * vptr)
{
	struct	occi_kind_node * nptr;
	struct	cords_provider * pptr;
	char	buffer[256];
	if (!( nptr = vptr ))
		return(0);
	else if (!( pptr = nptr->contents ))
		return(0);
	
	if (!( rest_valid_string( pptr->opinion )))
	{

		sprintf(buffer,"%u",(time((long *)0) % 10)+1);
		pptr->opinion = allocate_string( buffer );
	}

	if (!( rest_valid_string( pptr->zone ) ))
		pptr->zone = allocate_string("europe");

	if (!( rest_valid_string( pptr->security ) ))
		pptr->security = allocate_string("public");

	if (!( rest_valid_string( pptr->operator ) ))
		pptr->operator = allocate_string("any");

	return(0);
	
}
   Document::Document( const char* NamespaceString, const char* prefix, const char* type, const char* Declaration )
      : Declaration( Declaration )
      , prefix( prefix )
      , root( 0 )
   {
      // xml declaration. TODO: use parameter
      ::rapidxml::xml_node<>* decl = allocate_node( ::rapidxml::node_declaration );
      decl->append_attribute( allocate_attribute( "version", "1.0" ) );
      decl->append_attribute( allocate_attribute( "encoding", "utf-8" ) );
      append_node( decl );

      if ( type )
      {
         // root node
         root = allocate_node( ::rapidxml::node_element, PrefixType( type ) );

         ::std::string temp( "xmlns" );
         if ( ::strlen( prefix ) != 0 )
         {
            temp.append( ":" );
            temp.append( prefix );
         }
         root->append_attribute( allocate_attribute( allocate_string( temp.c_str(), temp.size()+1 ), NamespaceString ) );
         append_node( root );
      }
   }
char *rson_serialize_list(rson_list *list) {
	int i;
	size_t serial_list_len, serial_part_len;
	char *serial_list, *serial_part, *list_size;

	list_size = int_to_string(list->size);

	// rson list begins with: "L<number of list items>:"
	serial_list = allocate_string(strlen(list_size) + 2);
	sprintf(serial_list, "L%s:", list_size);

	for (i = 0; i < list->size; i++) {
		serial_part = rson_serialize_type(list->objects[i]);

		serial_part_len = strlen(serial_part);
		serial_list_len = strlen(serial_list);
		if (serial_part_len >= SIZE_MAX - serial_list_len) {
			print_error("Unsigned integer overflow");
		}
		serial_list = append_to_string(serial_list, serial_part);	
	}

	free(list_size);
	return serial_list;
}
/*	-----------------------------------------------------------------	*/
char * get_ec2_flavor(int memory, int cores, int speed, int storage, char * architecture)
{
	char srcdir[1024];
	PyObject    *pName=NULL, *pModule=NULL, *pDict=NULL, *pFunc=NULL,*result=NULL;
	PyThreadState* pythr=NULL;
	char * response;

	//python interface	
        sprintf(srcdir,"%s/pyaccords/pysrc",PYPATH);
	pythr = Py_NewInterpreter();
	python_path(srcdir);
	pName = PyString_FromString("ec2client");
	if(pName == NULL) printf("erro: in ec2client.py no such file name\n");
	else pModule = PyImport_Import(pName);
	if(pModule == NULL) printf("error: failed to load ec2client module\n");
	else pDict = PyModule_GetDict(pModule);
	if(pDict == NULL) printf("error: failed to load dict name in ec2client module\n");
	else pFunc = PyDict_GetItemString(pDict,"ec2_get_flavor");
	if(pFunc == NULL) printf("error: failed to load ec2_get_flavor function in ec2client module\n");
	else result=PyObject_CallFunction(pFunc,"iiiis",memory,cores,speed,storage,architecture);
	if (!result || PyErr_Occurred())
        {
       		PyErr_Print();
       		return (0);
       	}

	response=allocate_string(PyString_AsString( result ));
	Py_DECREF(pModule);
	Py_DECREF(pName);
	Py_EndInterpreter(pythr);
	return response;
}
/* ---------------------------------------------------------------------------*/
char * get_ec2_imgname(struct ec2_subscription* subptr, char *imgname,char * zone)
{
	char srcdir[1024];
  	PyObject    *pName=NULL, *pModule=NULL, *pDict=NULL, *pFunc=NULL,*result=NULL;
	PyThreadState* pythr=NULL;
	char * response;
	//python interface	
        sprintf(srcdir,"%s/pyaccords/pysrc",PYPATH);
	pythr = Py_NewInterpreter();
	python_path(srcdir);
	pName = PyString_FromString("ec2client");
	if(pName == NULL) printf("erro: in ec2client.py no such file name\n");
	else pModule = PyImport_Import(pName);
	if(pModule == NULL) printf("error: failed to load ec2client module\n");
	else pDict = PyModule_GetDict(pModule);
	if(pDict == NULL) printf("error: failed to load dict name in ec2client module\n");
	else pFunc = PyDict_GetItemString(pDict,"ec2_get_image");
	if(pFunc == NULL) printf("error: failed to load ec2_get_image function in ec2client module\n");
	else result=PyObject_CallFunction(pFunc,"ssss",subptr->accesskey,subptr->secretkey,imgname,zone);
	if (!result || PyErr_Occurred())
        {
       		PyErr_Print();
       		return (0);
       	}

	response=allocate_string(PyString_AsString( result ));
	Py_DECREF(pModule);
	Py_DECREF(pName);
	Py_EndInterpreter(pythr);
	return response;


}
Exemple #6
0
static mlval to_string(mlval arg)
{
  char buffer[40];
  size_t length;
  mlval string;

  double x = GETREAL (FIELD (arg,0));
  int prec = CINT (FIELD (arg,1));

  if (isnan(x))
    strcpy (buffer,"nan");
  else 
    if (is_infinity (x))
      if (x > 0.0) 
	strcpy (buffer,"inf");
      else strcpy (buffer,"~inf");
    else
      {
	size_t i, plus = 0;
	int point = 0;
	    
	sprintf(buffer, "%.*G", prec, x);

	length = strlen(buffer);

	for(i=0; i<length; ++i)
	  {
	    char c = buffer[i];

	    if(c == '-')
	      buffer[i] = '~';
	    else if(c == '.' || c == 'E')
	      point = 1;
	    else if(c == '+')
	      plus = i;
	  }
  
	if(plus)
	  {
	    for(i=plus; i<length; ++i)
	      buffer[i] = buffer[i+1];
	    length--;
	    
	  }
	
	if(!point)
	  {
	    buffer[length++] = '.';
	    buffer[length++] = '0';
	    buffer[length] = '\0';
	  }
      }

  length = strlen (buffer);
  string = allocate_string(length+1);
  strcpy(CSTRING(string), buffer);

 return(string);
}
int	add_member()
{
	struct	item * iptr;
	if (!( iptr = allocate_item()))
		return( failure( 27,"allocation","item") );
	else if (!( iptr->name = allocate_string( C.member )))
		return( failure( 27,"allocation","item->name") );
	else if (!( iptr->basic = allocate_string( C.basic )))
		return( failure( 27,"allocation","item->basic") );
	else 	
	{
		if (!( strcmp( C.basic, "struct" ) ))
			if (!( iptr->type = allocate_string( C.special )))
				return( failure( 27,"allocation","item->type") );
		iptr->dimension = C.dimension;
		iptr->indirection = C.isptr;
		C.isptr = 0;
		C.dimension=0;
		if (!( iptr->previous = C.last ))
			C.first = iptr;
		else	iptr->previous->next = iptr;
		C.last = iptr;
		if (!( strcmp( C.basic, "struct" ) )) 
		{
			if (!( strcmp(C.member, "first" ) ))
			{
				C.hasfirst=1;
				strcpy( C.premier, C.special );
			}
			else if (!( strcmp(C.member, "parent" ) ))
			{
				C.hasparent=1;
				strcpy( C.parent, C.special );
			}
			else if (!( strcmp(C.member, "previous" ) ))
			{
				C.hasprevious=1;
			}
			else if (!( strcmp(C.member, "next" ) ))
			{
				C.hasnext=1;
			}
		}
		return( 0 );
	}
}
 const char* Document::PrefixType( const char* type )
 {
    ::std::string temp( prefix );
    if ( !temp.empty() )
       temp.append( ":" );
    temp.append( type );
    return allocate_string( temp.c_str(), temp.size()+1 );
 }
Exemple #9
0
struct string *alloc_string_n(uvalue n)
{
  struct string *newp;

  newp = (struct string *)allocate_string(type_string, n + 1);
  newp->str[n] = '\0';

  return newp;
}
Exemple #10
0
void	xml_get_text(struct xml_application * xptr, char ** rptr )
{
	char *	cptr;
	if (( cptr = allocate_string( xptr->buffer )) != (char *) 0) {
		use_xml_macros();
		convert_html_accents( &cptr, 1 );
		use_html_macros();
		}
	*rptr = cptr;
}
Exemple #11
0
struct string *alloc_string(const char *s)
{
  struct string *newp;

  newp = (struct string *)allocate_string(type_string, strlen(s) + 1);

  strcpy(newp->str, s);

  return newp;
}
/* get a substring. */
static char *substring(char *begin, int len)
{
	char *new_string;

	new_string = allocate_string(len);
	memcpy(new_string, begin, len);
	new_string[len] = 0;

	return new_string;
}
Exemple #13
0
struct mudlle_float *alloc_mudlle_float(float d)
{
  struct mudlle_float *newp;

  newp = (struct mudlle_float *)allocate_string(type_float, sizeof newp->d);
  newp->d = d;
  SETFLAGS(newp,  OBJ_READONLY | OBJ_IMMUTABLE);

  return newp;
}
/*	--------------------------------------------------------	*/
int	reset_ec2_server( struct amazonEc2 * pptr )
{
	if ( pptr )
	{
		if ( pptr->number ) pptr->number = liberate( pptr->number );
		if ( pptr->hostname ) pptr->hostname = liberate( pptr->hostname );
		if ( pptr->reference ) pptr->reference = liberate( pptr->reference );
		if ( pptr->rootpass ) pptr->rootpass = liberate( pptr->rootpass );
		if ( pptr->publicaddr ) pptr->publicaddr = liberate( pptr->publicaddr );
		if ( pptr->privateaddr ) pptr->privateaddr = liberate( pptr->privateaddr );
		pptr->number = allocate_string("");
		pptr->hostname = allocate_string("");
		pptr->rootpass  = allocate_string("");
		pptr->publicaddr = allocate_string("");
		pptr->privateaddr = allocate_string("");
		pptr->state = _OCCI_IDLE;
	}
	return(0);
}
   ::rapidxml::xml_node<>* Document::AppendChildNode( ::rapidxml::xml_node<>* Parent, const char* type, const ::std::string& text )
   {
      ::rapidxml::xml_node<>* ChildElement = AppendChildNode( Parent, type );

      // encoding is done in the rapidxml::print() method
      //::std::string temp = encode( text );
      ChildElement->value( allocate_string( text.c_str(), text.size() ), text.size() );
      
      return ChildElement;
   }
Exemple #16
0
void prf(char *format, ...)
{
    string b = allocate_string(prf_heap);
    va_list ap;
    string f = alloca_string(format);
    va_start(ap, format);
    vbprintf(b, f, ap);
    va_end(ap);
    write(1, bref(b, 0), buffer_length(b));
    //    deallocate_buffer(b);
}
char *rson_serialize_integer(int integer) {
	char *int_string, *serial_int;

	int_string = int_to_string(integer);
	serial_int = allocate_string(strlen(int_string) + 2);

	sprintf(serial_int, "I%s:", int_string);

	free(int_string);
	return serial_int;
}
/* create a new stringbuffer */
stringbuffer_t *stringbuffer_create(void)
{
	stringbuffer_t *sb;

	sb = malloc(sizeof(stringbuffer_t));
	sb->len = 0;
	sb->capacity = 0;
	sb->buf = allocate_string(0);

	return sb;
}
/*	---------------------------------------------------	*/
public	char *	occi_xml_capacity( struct occi_category * optr )
{
	char	buffer[8192];
	char  *	term;
	struct	occi_attribute * mptr;
	struct	occi_action    * fptr;
	sprintf(buffer,"%s;\r\n scheme=\"%s\";\r\n class=%s;\r\n rel=\"%s\";\r\n",
		optr->id,optr->scheme,optr->class,optr->rel );

	if ( optr->first )
	{
		strcat( buffer, " attributes");
		term = "=";
		for (	mptr = optr->first;
			mptr != (struct occi_attribute *) 0;
			mptr = mptr->next )
		{
			strcat( buffer, term );
			strcat( buffer, optr->domain );
			strcat( buffer, "." );
			strcat( buffer, optr->id   );
			strcat( buffer, "." );
			strcat( buffer, mptr->name );
			if ( mptr->mandatory )
				strcat( buffer,"{required}" );
			if ( mptr->immutable )
				strcat( buffer,"{immutable}" );
			term=",";
		}
		strcat( buffer, ";\r\n" );

	}
	if ( optr->firstact )
	{
		strcat( buffer, " actions");
		term = "=";
		for (	fptr = optr->firstact;
			fptr != (struct occi_action *) 0;
			fptr = fptr->next )
		{
			strcat( buffer, term );
			strcat( buffer, fptr->name );
			term=",";
		}
		strcat( buffer, ";\r\n" );
	}

	strcat( buffer, " location=\"" );
	strcat( buffer, optr->location );
	strcat( buffer, "\";" );

	return( allocate_string( buffer ) );

}
/*	-----------------------------------		*/
private	char * resolve_json_atb( struct os_response * zptr, char * nptr )
{
	char * result=(char *) 0;
	if (!( zptr ))
		return( (char *) 0 );
	else if (!( zptr->jsonroot ))
		return( (char *) 0 );
	else if (!( result = json_atribut( zptr->jsonroot, nptr ) ))
		return( (char *) 0 );
	else	return( allocate_string( result ) );
}
Exemple #21
0
void add_stringn(mpop_string *str, const void *p, int n)
{
  char *np;
  
  assert( p && str );

  allocate_string(str, str->size + n + 1);
  np = str->string + str->size;
  memcpy(np, p, n);
  np[n] = 0;
  str->size += n;
}
char *rson_serialize_string(char *string) {
	size_t allocate_size;
	char *string_length, *serial_string;

	string_length = int_to_string(strlen(string));
	allocate_size = strlen(string_length) + strlen(string) + 2;
	serial_string = allocate_string(allocate_size);

	sprintf(serial_string, "S%s:%s", string_length, string);

	free(string_length);
	return serial_string;
}
void strings_resource_storage::init_page_texts()
{
    page_texts.clear();

    QString queryStr = "SELECT entry,text FROM page_text;";
    QSqlQuery res = m_db->exec(queryStr);
    while(res.next())
    {
        int a;
        int index = allocate_string(res.record().value(1).toByteArray().data(),a);
        item_template_names.insert({res.value(0).toInt(),index});
    }
}
void	generate_occi_sql_on_create( FILE * h, char * nptr, char * fullname )
{
	char	buffer[1024];
	char *	xptr=(char *) 0;
	char *	wptr;
	struct	item * iptr;
	int	items=0;
	fprintf(h,"\nprivate int %s_sql_on_create()\n{\n",fullname);
	fprintf(h,"\tstruct occi_expression expression={(char *) 0, (void *) 0};\n");
	for ( 	iptr= C.first;
		iptr != (struct item *) 0;
		iptr = iptr->next )
	{
		if (!( strcmp( iptr->name, "previous" ) ))
			continue;
		else if (!( strcmp( iptr->name, "next" ) ))
			continue;
		else if (!( strcmp( iptr->name, "parent" ) ))
			continue;
		else if (!( strncmp( iptr->name, "first", strlen("first") ) ))
			continue;
		else if (!( strncmp( iptr->name, "last", strlen("last") ) ))
			continue;
		else
		{
			if (!( strcmp( iptr->basic, "int" ) ))
				sprintf(buffer, "%s %s INTEGER",(xptr ? "," : " ("),iptr->name);
			else 	sprintf(buffer, "%s %s CHAR(128)",(xptr ? "," : " ("),iptr->name);
			if ( xptr )
			{
				if (!( wptr = allocate( strlen( xptr ) + strlen( buffer ) + 3 ) ))
					break;
				else	sprintf(wptr,"%s%s",xptr,buffer);
				liberate( xptr );
				xptr = wptr;
			}
			else	xptr = allocate_string( buffer );
			if (!( strcmp( iptr->name, "id" ) ))
				xptr = join_string( xptr, " PRIMARY KEY");							
		}
	}
	if ( xptr )
	{
		xptr = join_string( xptr, " ) ");
		fprintf(h,"\tif (!( expression.value = allocate_string(%c%s%c) ))\n",0x0022,xptr,0x0022);
		fprintf(h,"\t\treturn( 27 );\n");
	}
	fprintf(h,"\treturn(0);\n");
	fprintf(h,"}\n");
	return;
}
char * create_onapp_authentication(char * user, char * password)
{
	static size_t const buffersize = 1024;
	char buffer[buffersize];
	char encoded[buffersize];
	char * rstrip;
	int nchars;
	char * authentication = 0;

	if ( user == NULL )
		return authentication;
	if ( password == NULL )
		return authentication;

	nchars = snprintf(buffer,buffersize, "%s:%s", user, password);

#ifdef BASE64_ENCODE_ONAPP_AUTHORIZATION
	// No check for memory overrun in encoded...
	if (!( EncodeBase64(encoded, buffer, strlen( buffer )) ))
		return( authentication );

	int const lenEncoded = strlen(encoded);

	/*  POST on OnApp has been seen to fail with excessive newlines in authentication header. */
	rstrip = encoded + lenEncoded - 1;
	while (*rstrip == '\n') {
		*rstrip = '\0';
		--rstrip;
	}

	/* Need to be in format "Basic <64bit encoded auth token>" for ControlPanel 3. */
	snprintf(buffer, buffersize, "Basic %s", encoded);
	authentication = allocate_string(buffer);
#else // !BASE64_ENCODE_ONAPP_AUTHORIZATION
	authentication = allocate_string(buffer);
#endif // BASE64_ENCODE_ONAPP_AUTHORIZATION
	return authentication;
}
char *rson_serialize_dict(rson_dict *dict) {
	size_t i, serial_dict_len, serial_part_len, serial_key_len,
	       serial_value_len;
	char *serial_dict, *serial_value, *serial_key, *serial_dict_tmp;

	serial_dict = allocate_string(1);
	serial_dict[0] = '\0';

	for (i = 0; i < dict->size; i++) {
		serial_key = rson_serialize_type(dict->entries[i]->key);
		serial_value = rson_serialize_type(dict->entries[i]->value);

		serial_key_len = strlen(serial_key);
		serial_value_len = strlen(serial_value);
		serial_dict_len = strlen(serial_dict);
		if (serial_key_len >= SIZE_MAX - serial_value_len) {
			print_error("Unsigned integer overflow");
		}

		serial_part_len = serial_key_len + serial_value_len;
		if (serial_part_len >= SIZE_MAX - serial_dict_len) {
			print_error("Unsigned integer overflow");
		}
		// Each rson dictionary entry is formatted as: "N<key>:<value>"
		serial_part_len += serial_dict_len + 2;
		serial_dict_tmp = allocate_string(serial_part_len);

		if (serial_dict != NULL) {
			sprintf(serial_dict_tmp, "%sN%s%s", serial_dict, serial_key, serial_value);
			free(serial_dict);
		} else {
			sprintf(serial_dict_tmp, "N%s%s", serial_key, serial_value);
		}
		serial_dict = serial_dict_tmp;
	}

	return serial_dict;
}
/* 	--------------------------------------		*/
private	int	build_transaction( struct cords_transaction * pptr, struct orga_transaction * tptr )
{
	struct	occi_response * zptr;
	struct	occi_element * eptr;

	if (!( tptr->operator = resolve_provider_account()))
		return(0);
	else if (!( rest_valid_string( pptr->account ) ))
		return(0);
	else
	{

		if ((zptr = occi_simple_get( pptr->account, get_default_agent(), default_tls() )) != (struct occi_response *) 0)
		{
			if ((eptr = occi_locate_element( zptr->first, "occi.core.id" )) != (struct occi_element *) 0)
				tptr->account = allocate_string( eptr->value );
			zptr = occi_remove_response( zptr );
		}
	}

	if ( rest_valid_string( pptr->price ) )
	{
		if ((zptr = occi_simple_get( pptr->price, get_default_agent(), default_tls() )) != (struct occi_response *) 0)
		{
			if ((eptr = occi_locate_element( zptr->first, "occi.price.currency" )) != (struct occi_element *) 0)
				tptr->currency = allocate_string( eptr->value );
			if ((eptr = occi_locate_element( zptr->first, "occi.price.rate" )) != (struct occi_element *) 0)
				tptr->value = allocate_string( eptr->value );
			if ((eptr = occi_locate_element( zptr->first, "occi.price.description" )) != (struct occi_element *) 0)
				tptr->label = allocate_string( eptr->value );
			zptr = occi_remove_response( zptr );
		}
	}
	if (!( tptr->measures = allocate_string("") ))
		return( 0 );
	else	return( 1 );
}
/* remove whitespace (including tabs) */
stringbuffer_t *stringbuffer_trim_whitespace(stringbuffer_t *sb)
{
	char *newbuf;
	int new_len;
	int i, j;

	if (sb->len == 0) /* empty string. */
		return sb;

	/* find beginning of string after tabs and whitespaces. */
	for (i = 0; i < sb->len && (sb->buf[i] == ' ' || sb->buf[i] == '\t'); i++);

	if (sb->buf[i] != '\0')
	{

		/* we do have whitespace in the beginning so find the end. */
		for (j = (sb->len -1); (sb->buf[j] == ' ' || sb->buf[j] == '\t'); j--);

		/* increment j since it's on the non whitespace character. */
		j++;

		/* create a new string. */
		new_len = j - i;
		newbuf = allocate_string(new_len);

		/* copy in. */
		memcpy(newbuf, &sb->buf[i], (j - i) * sizeof(char));
		newbuf[new_len] = 0;

		/* free up old. */
		free(sb->buf);

		/* set new. */
		sb->buf = newbuf;
		sb->len = new_len;
		sb->capacity = new_len;


	}
	else
	{

		/* zap beginning of string. since its all whitespace. */
		sb->buf[0] = 0;
		sb->len = 0;
	}

	return sb;
}
void rson_serialize_test() {
	rson_object *object;
	char *string;
	int integer;
	rson_list *list;
	rson_dict *dict;

	object = (rson_object *) malloc(sizeof(rson_object));

	// String
	string = allocate_string(strlen("asdf"));
	sprintf(string, "asdf");

	object->type = RSON_STR;
	object->value = string;

	printf("[*] Testing strings: %s\n", rson_serialize(object));

	// Integer
	integer = 42;
	object->type = RSON_INT;
	object->value = &integer;

	printf("[*] Testing integers: %s\n", rson_serialize(object));

	// List
	list = rson_create_list(4);
	list->objects[0] = rson_create_integer(15);
	list->objects[1] = rson_create_string(string);
	list->objects[2] = rson_create_integer(42);
	list->objects[3] = rson_create_string(string);
	object->type = RSON_LIST;
	object->value = list;

	printf("[*] Testing lists: %s\n", rson_serialize(object));

	// Dictionary
	dict = rson_create_dict(4);
	dict->entries[0] = rson_create_dict_entry(rson_create_string(string), rson_create_integer(15));
	dict->entries[1] = rson_create_dict_entry(rson_create_string(string), rson_create_integer(15));
	dict->entries[2] = rson_create_dict_entry(rson_create_string(string), rson_create_integer(15));
	dict->entries[3] = rson_create_dict_entry(rson_create_string(string), rson_create_integer(15));
	object->type = RSON_DICT;
	object->value = dict;

	printf("[*] Testing dictionaries: %s\n", rson_serialize(object));

	rson_free_object(object);
}
Exemple #30
0
void	xml_put_cdata(FILE * h, char * sptr )
{
	char *	cptr;
	if (!( sptr ))
		return;
	else if (!( cptr = allocate_string( sptr ) ))
		return;
	else	{
		use_xml_macros();
		convert_html_accents( &cptr, 2 );
		use_html_macros();
		fprintf(h,"%s",cptr);
		liberate( cptr );
		return;
		}
}