Esempio n. 1
0
void irep_pipet::receive(irept &sdu) const
{
#ifndef _WIN32
    assert(!read_closed);
    std::string data;
    char buffer[READ_BUFFER_SIZE];
    do
    {
        const ssize_t result=read(fd[0u], buffer, sizeof(buffer));
        if (result == -1)
        {
            perror(IREP_PIPE " read");
            throw std::runtime_error("Error reading pipe.");
        }
        if (result > 0) data.append(buffer, result);
        else break;
    } while (true);
    data.erase(data.end() - 1);
    std::istringstream is(data);
    xmlt xml;
    null_message_handlert msg;
    parse_xml(is, "", msg, xml);
    convert(xml, sdu);
#else
    assert(!"Pipes currently not supported on Windows.");
#endif
}
Esempio n. 2
0
static package
bf_parse_xml_tree(Var arglist, Byte next, void *vdata, Objid progr)
{
  package result = parse_xml(arglist.v.list[1].v.str, 0);
  free_var(arglist);
  return result;
}
Esempio n. 3
0
/*
 系统初始化和Initialize.xml更新时需要刷新注册,但Initialize.xml由push系统自己注册。
 regist_flag
 	0 means unregist
 	1 means resgist
*/
static int parse_progs()
{
	int ret = -1;
	int i = 0;
	PUSH_XML_FLAG_E push_flag = PUSH_XML_FLAG_UNDEFINED;
	RECEIVETYPE_E recv_type = -1;
	int product_id = -1;
	char sqlite_cmd[1024];
	int (*sqlite_callback)(char **, int, int, void *, unsigned int) = parse_progs_cb;
	int resgist_action = 0;
	
	s_mom_progs_p = (MOM_PROG_S *)malloc(sizeof(MOM_PROG_S) * MOM_PROG_NUM);
	if(NULL==s_mom_progs_p){
		DEBUG("can not malloc %d*%d memery to save mother progs\n", sizeof(MOM_PROG_S),MOM_PROG_NUM);
		ret = -1;
	}
	else{
		sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT ReceiveType,DescURI,productID FROM ProductDesc;");
		ret = sqlite_read(sqlite_cmd, (void *)(&resgist_action), sizeof(resgist_action), sqlite_callback);
		DEBUG("ret=%d\n", ret);
		
		for(i=0;i<MOM_PROG_NUM;i++)
		{
			if(strlen(s_mom_progs_p[i].DescURI)>0){
				s_receive_status = RECEIVESTATUS_FINISH;
				recv_type = atoi(s_mom_progs_p[i].ReceiveType);
				
				if(RECEIVETYPE_PUBLICATION==recv_type || RECEIVETYPE_PREVIEW==recv_type){
					push_flag = PUBLICATION_XML;
				}
				else if(RECEIVETYPE_COLUMN==recv_type){
					push_flag = COLUMN_XML;
				}
				else if(RECEIVETYPE_SPRODUCT==recv_type){
					push_flag = SPRODUCT_XML;
				}
				else{
					DEBUG("%d(%s) can not be distinguish\n", recv_type, s_mom_progs_p[i].DescURI);
					push_flag = PUSH_XML_FLAG_UNDEFINED;
				}
		
				if(PUSH_XML_FLAG_UNDEFINED!=push_flag){
					product_id = atoi(s_mom_progs_p[i].productID);
					s_receive_status = RECEIVESTATUS_FINISH;
		
					// 确保在解析Publications.xml之前,明确得到s_receive_status,因为在解析入库时需要判断
					if(0==parse_xml(s_mom_progs_p[i].DescURI, push_flag, NULL)){
						DEBUG("parse %s success\n", s_mom_progs_p[i].DescURI);
					}
					else{
						DEBUG("parse %s failed\n", s_mom_progs_p[i].DescURI);
					}
				}
			}
		}
	
	}
	
	return ret;
}
Esempio n. 4
0
/// Make a PUT to the server and store off the XML response. Caller is
/// responsible for deleting the filled-in "root" pointer.
HTTPCode HSSConnection::put_for_xml_object(const std::string& path,
                                           std::string body,
                                           bool cache_allowed,
                                           rapidxml::xml_document<>*& root,
                                           SAS::TrailId trail)
{
  std::string raw_data;
  std::map<std::string, std::string> rsp_headers;
  std::vector<std::string> req_headers;

  if (!cache_allowed)
  {
    req_headers.push_back("Cache-control: no-cache");
  }

  HTTPCode http_code = _http->send_put(path,
                                       rsp_headers,
                                       raw_data,
                                       body,
                                       req_headers,
                                       trail);

  if (http_code == HTTP_OK)
  {
    root = parse_xml(raw_data, path);
  }

  return http_code;
}
Esempio n. 5
0
int tinyroute_main(struct audio_tool_config *config, int argc, char **argv)
{

		// 0. check for filename on cmd line rather than default
		if (argc > 1) {
			printf("Opening Mixer Paths XML %s\n", argv[1]);
			mixer_paths_xml = argv[1];
		} else {
			printf("Opening default file %s\n", MIXER_XML_PATH);
		}

    // 1. allocate audio_route and setup state
    struct audio_route *ar = setup_audio_route(config);
    struct config_parse_state state;
    memset(&state, 0, sizeof(state));
    state.ar = ar;
		// setup top level initial settings path
		state.path = path_create(ar, TOP_LEVEL_XML_SETTINGS);

    // 2. parse XML
    parse_xml(&state);

    // 3. print results
    print_routes(&state);

    return 0;

    // TODO: FREE RESOURCES
}
Esempio n. 6
0
void datat::read(const std::string &file)
{
  xmlt xml;

  console_message_handlert message_handler;
  parse_xml(file, message_handler, xml);

  read(xml);
}
Esempio n. 7
0
File: tmx.c Progetto: jabelardo/tmx
tmx_map* tmx_load(const char *path) {
	tmx_map *map = NULL;

	if (!tmx_alloc_func) tmx_alloc_func = realloc;
	if (!tmx_free_func) tmx_free_func = free;

	map = parse_xml(path);

	return map;
}
Esempio n. 8
0
static HRESULT WINAPI xmldoc_IPersistStreamInit_Load(
    IPersistStreamInit *iface, LPSTREAM pStm)
{
    xmldoc *This = impl_from_IPersistStreamInit(iface);
    HRESULT hr;
    HGLOBAL hglobal;
    DWORD read, written, len;
    BYTE buf[4096];
    char *ptr;

    TRACE("(%p, %p)\n", iface, pStm);

    if (!pStm)
        return E_INVALIDARG;

    /* release previously allocated stream */
    if (This->stream) IStream_Release(This->stream);
    hr = CreateStreamOnHGlobal(NULL, TRUE, &This->stream);
    if (FAILED(hr))
        return hr;

    do
    {
        IStream_Read(pStm, buf, sizeof(buf), &read);
        hr = IStream_Write(This->stream, buf, read, &written);
    } while(SUCCEEDED(hr) && written != 0 && read != 0);

    if (FAILED(hr))
    {
        ERR("Failed to copy stream\n");
        return hr;
    }

    hr = GetHGlobalFromStream(This->stream, &hglobal);
    if (FAILED(hr))
        return hr;

    len = GlobalSize(hglobal);
    ptr = GlobalLock(hglobal);
    if (len != 0)
    {
        xmlFreeDoc(This->xmldoc);
        This->xmldoc = parse_xml(ptr, len);
    }
    GlobalUnlock(hglobal);

    if (!This->xmldoc)
    {
        ERR("Failed to parse xml\n");
        return E_FAIL;
    }

    return S_OK;
}
Esempio n. 9
0
// 'do it all' function
bool parse_xml(
  const std::string &filename,
  message_handlert &message_handler,
  xmlt &dest)
{
  std::ifstream in(filename.c_str());
  
  if(!in) return true;
 
  return parse_xml(in, filename, message_handler, dest);
}
Esempio n. 10
0
File: tmx.c Progetto: emanuele-f/tmx
tmx_map* tmx_load(const char *path) {
	tmx_map *map = NULL;
	const char *extension;
	FILE *file;
	int fchar;

	if (!tmx_alloc_func) tmx_alloc_func = realloc;
	if (!tmx_free_func) tmx_free_func = free;

	/* is 'path' a JSON or a XML file ? */
	extension = strrchr(path, '.'); /* First using the file extension */
	if (extension && (!strcmp(extension, ".tmx") || !strcmp(extension, ".xml"))) {
		map = parse_xml(path);
	} else if (extension && !strcmp(extension, ".json")) {
		map = parse_json(path);
	} else {
		/* open the file and check with the first character */
		if ((file = fopen(path, "r"))) {
			fchar = fgetc(file);
			fclose(file);
			if (fchar == '<') {
				map = parse_xml(path);
			} else if (fchar == '{') {
				map = parse_json(path);
			} else {
				tmx_errno = E_FORMAT;
			}
		} else {
			if (errno == EACCES) {
				tmx_errno = E_ACCESS;
			} else if (errno == ENOENT) {
				tmx_errno = E_NOENT;
			} else {
				tmx_err(E_UNKN, "%s", strerror(errno));
			}
		}
	}

	return map;
}
Esempio n. 11
0
int checkNewEvents(char *xml_file){
	xmlChar *db_creation;
	db_creation = getCreation(db_uri, (const xmlChar *)"remendo_db");
	parse_xml(xml_file, "event", db_creation);

	if(pending_events != 0){
		//show interface
		pending_events = 0;
		return 1;
	}else{
		printf("No new events to handle.\n");
		return 0;
	}
}
Esempio n. 12
0
/// Retrieve an XML object from a path on the server. Caller is responsible for deleting.
HTTPCode HSSConnection::get_xml_object(const std::string& path,
                                       rapidxml::xml_document<>*& root,
                                       SAS::TrailId trail)
{
  std::string raw_data;

  HTTPCode http_code = _http->send_get(path, raw_data, "", trail);

  if (http_code == HTTP_OK)
  {
    root = parse_xml(raw_data, path);
  }

  return http_code;
}
Esempio n. 13
0
int
main(int argc, char **argv)
{
    // int             result;
    // char            buffer[BUFFER_SIZE];
    // char* buffer = malloc(BUFFER_SIZE);

    // if (buffer == NULL) {
    //     printf("malloc e arg\n");
    // }

    parse_xml(argv[1]);
    printf("Result is %i\n", max_dep);
    return 0;
}
Esempio n. 14
0
void* bacnet_parser(void* adapterv)
{
    adapter_t *adapter = (adapter_t*) adapterv;
    char* config_dir = adapter -> config_dir;
    bacnet_context_t* context;
    parser_context = new_bacnet_context();

    char bacnet_file[512];
    char device_file[512];

    DIR *d;
    d = opendir(config_dir);
    
    if (d != NULL)
    {
        sprintf(device_file,"%s/device.xml",(char*)config_dir);
        parse_xml(device_file, device_start,device_end);

        sprintf(bacnet_file,"%s/bacnet.xml",(char*)config_dir);
        parse_xml(bacnet_file, bacnet_start, bacnet_end);

        mio_lock = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
        pthread_mutex_init(mio_lock,NULL);

        context = parser_context;
        parser_context = NULL;
    } else
    {
        context = parse_bacnet_context_node(adapter);
    }

    address_init();
    Init_Service_Handlers();
    dlenv_init();
    return (void*) context;
}
Esempio n. 15
0
int ploop_read_dd(struct ploop_disk_images_data *di)
{
	int ret;
	char basedir[PATH_MAX];
	const char *fname;
	struct stat st;
	xmlDoc *doc = NULL;
	xmlNode *root_element = NULL;

	LIBXML_TEST_VERSION

	if (!di || !di->runtime || !di->runtime->xml_fname) {
		ploop_err(0, "DiskDescriptor.xml is not opened");
		return -1;
	}
	ploop_clear_dd(di);

	fname = di->runtime->xml_fname;
	if (stat(fname, &st)) {
		ploop_err(errno, "Can't stat %s", fname);
		return -1;
	}

	/* workaround libxml2 SIGSEGV on empty document */
	if (st.st_size == 0) {
		ploop_err(0, "Can't parse %s", fname);
		return -1;
	}

	doc = xmlReadFile(fname, NULL, 0);
	if (doc == NULL) {
		ploop_err(0, "Can't parse %s", fname);
		return -1;
	}
	root_element = xmlDocGetRootElement(doc);

	get_basedir(fname, basedir, sizeof(basedir));
	ret = parse_xml(basedir, root_element, di);
	if (ret == 0)
		ret = validate_disk_descriptor(di);

	xmlFreeDoc(doc);

	return ret;
}
Esempio n. 16
0
void
LastFmParser::request_done (int id, bool err)
{
	if (err) {
		m_cache.remove (m_cache_map[id]);
		m_cache_map.remove (id);
		emit gotError (m_cache_map[id]);
		return;
	}
	QBuffer *b = m_requests.take (id);

	if (!b) {
		return;
	}
	
	parse_xml (b->buffer (), id);
	delete b;
}
Esempio n. 17
0
int main(int argc, char** argv){
    int i;
    char *filename, *query_string, *node;

    if(argc == 2){
        filename = "-";
    }
    else if(argc != 3){
        printf("usage: %s \"query\" \"xml_file\"\n", argv[0]);
        return 0;
    }
    else{
        filename = argv[2];
    }

    query_string = argv[1];

    doc* document = parse_xml(filename);
    if(document == NULL) exit(1);

    register_extended_operators();
    list* result = query(query_string, document->root);

    if(result == NULL) exit(1);

    for(i=0; i < result->count; i++){
        dom_node* t = (dom_node*)get_element_at(result, i);
        node = node_to_string(t, XML);
        printf("%s", node);
        free(node);
    }

    if(result)
    destroy_generic_list(result);

    if(document != NULL)
    destroy_dom_tree(document);

    destroy_dictionary();
    destroy_custom_filters();
    destroy_custom_operators();
    return 0;
}
Esempio n. 18
0
header_buffer_type read_xml(const char* test_id) {
    std::string input = read_file(test_id);
    return parse_xml(input);
}
Esempio n. 19
0
void Cartridge::load(Mode cartridge_mode, const lstring &xml_list) {
  mode = cartridge_mode;
  region = Region::NTSC;
  ram_size = 0;
  spc7110_data_rom_offset = 0x100000;
  st_A_ram_size = 0;
  st_B_ram_size = 0;
  supergameboy_version = SuperGameBoyVersion::Version1;
  supergameboy_ram_size = 0;
  supergameboy_rtc_size = 0;

  has_bsx_slot   = false;
  has_superfx    = false;
  has_sa1        = false;
  has_necdsp     = false;
  has_srtc       = false;
  has_sdd1       = false;
  has_spc7110    = false;
  has_spc7110rtc = false;
  has_cx4        = false;
  has_obc1       = false;
  has_st0018     = false;
  has_msu1       = false;
  has_serial     = false;

  parse_xml(xml_list);
//print(xml_list[0], "\n\n");

  if(ram_size > 0) {
    memory::cartram.map(allocate<uint8_t>(ram_size, 0xff), ram_size);
  }

  if(has_srtc || has_spc7110rtc) {
    memory::cartrtc.map(allocate<uint8_t>(20, 0xff), 20);
  }

  if(mode == Mode::Bsx) {
    memory::bsxram.map (allocate<uint8_t>( 32 * 1024, 0xff),  32 * 1024);
    memory::bsxpram.map(allocate<uint8_t>(512 * 1024, 0xff), 512 * 1024);
  }

  if(mode == Mode::SufamiTurbo) {
    if(st_A_ram_size) memory::stAram.map(allocate<uint8_t>(st_A_ram_size, 0xff), st_A_ram_size);
    if(st_B_ram_size) memory::stBram.map(allocate<uint8_t>(st_B_ram_size, 0xff), st_B_ram_size);
  }

  if(mode == Mode::SuperGameBoy) {
    if(memory::gbrom.data()) {
      if(supergameboy_ram_size) memory::gbram.map(allocate<uint8_t>(supergameboy_ram_size, 0xff), supergameboy_ram_size);
      if(supergameboy_rtc_size) memory::gbrtc.map(allocate<uint8_t>(supergameboy_rtc_size, 0x00), supergameboy_rtc_size);
    }
  }

  memory::cartrom.write_protect(true);
  memory::cartram.write_protect(false);
  memory::cartrtc.write_protect(false);
  memory::bsxflash.write_protect(true);
  memory::bsxram.write_protect(false);
  memory::bsxpram.write_protect(false);
  memory::stArom.write_protect(true);
  memory::stAram.write_protect(false);
  memory::stBrom.write_protect(true);
  memory::stBram.write_protect(false);
  memory::gbrom.write_protect(true);
  memory::gbram.write_protect(false);
  memory::gbrtc.write_protect(false);

  unsigned checksum = ~0;                                           foreach(n, memory::cartrom ) checksum = crc32_adjust(checksum, n);
  if(memory::bsxflash.size() != 0 && memory::bsxflash.size() != ~0) foreach(n, memory::bsxflash) checksum = crc32_adjust(checksum, n);
  if(memory::stArom.size()   != 0 && memory::stArom.size()   != ~0) foreach(n, memory::stArom  ) checksum = crc32_adjust(checksum, n);
  if(memory::stBrom.size()   != 0 && memory::stBrom.size()   != ~0) foreach(n, memory::stBrom  ) checksum = crc32_adjust(checksum, n);
  if(memory::gbrom.size()    != 0 && memory::gbrom.size()    != ~0) foreach(n, memory::gbrom   ) checksum = crc32_adjust(checksum, n);
  crc32 = ~checksum;

  sha256_ctx sha;
  uint8_t shahash[32];
  sha256_init(&sha);
  sha256_chunk(&sha, memory::cartrom.data(), memory::cartrom.size());
  sha256_final(&sha);
  sha256_hash(&sha, shahash);

  string hash;
  foreach(n, shahash) hash << hex<2>(n);
  sha256 = hash;

  bus.load_cart();
  system.serialize_init();
  loaded = true;
}
Esempio n. 20
0
/**
 * Parses the byte stream according to the given document type
 * and creates a document model from it.
 *
 * @param p0 the destination (Hand over as reference!)
 * @param p1 the destination count
 * @param p2 the destination size
 * @param p3 the source
 * @param p4 the source count
 * @param p5 the type
 * @param p6 the type count
 */
void parse(void* p0, void* p1, void* p2, const void* p3, const void* p4,
           const void* p5, const void* p6) {

    // The comparison result.
    int r = 0;

    if (r != 1) {

        compare_arrays(p5, p6, (void*) CYBOL_ABSTRACTION, (void*) CYBOL_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_xml(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) OPERATION_ABSTRACTION, (void*) OPERATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) STRING_ABSTRACTION, (void*) STRING_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_string(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) BOOLEAN_ABSTRACTION, (void*) BOOLEAN_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_boolean(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) INTEGER_ABSTRACTION, (void*) INTEGER_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_integer(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) VECTOR_ABSTRACTION, (void*) VECTOR_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_vector(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) DOUBLE_ABSTRACTION, (void*) DOUBLE_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_double(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) FRACTION_ABSTRACTION, (void*) FRACTION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_fraction(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) COMPLEX_ABSTRACTION, (void*) COMPLEX_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_complex(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) TIME_ABSTRACTION, (void*) TIME_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_time(p0, p1, p2, p3, p4);
        }
    }

    if (r != 1) {

        compare_arrays(p5, p6, (void*) CONFIGURATION_ABSTRACTION, (void*) CONFIGURATION_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

        if (r == 1) {

            parse_xml(p0, p1, p2, p3, p4);
        }
    }

    /*??
        //?? Later, distinguish file types according to abstraction,
        //?? for example xml, html, sxi, txt, rtf,
        //?? adl (from OpenEHR), KIF, ODL etc.!
        //?? For now, only the cybol file format is considered.

        if (r != 1) {

            compare_arrays(p5, p6, (void*) SXW_ABSTRACTION, (void*) SXW_ABSTRACTION_COUNT, (void*) &r, (void*) CHARACTER_ARRAY);

            if (r == 1) {

                //?? For other kinds of file (stream) formats,
                //?? for example from special applications like Open Office,
                //?? use a similar handling like for compound above!

                //?? Images possibly also have to be handled that way.
                //?? At first, the single image parameters have to be parsed
                //?? and written into a special parameter model in memory;
                //?? then that model has to be decoded into a knowledge model!
                //?? May be this idea is rubbish and will not work!
                //?? For the beginning, better handle images as primitve types.
            }
        }
    */
}
Esempio n. 21
0
/**
    \fn get_doc
**/
inline xdp_t  get_doc(void){
    char * ixmlstr = (char *)read_alloc_cmd(1);
    xdp_t doc = parse_xml(ixmlstr);
    return doc;
}
Esempio n. 22
0
//get the xml object from the daemon, parse the information 
int getRecordEngine( string &input, connInfo &connectionInfo, string *output )
{
	hlr_log ("getRecord Engine: Entering.", &logStream,4);
	hlrError e;
	bool success = true;
	int code = 0;
	if ( !authorize(connectionInfo.contactString) )
	{
		success = false;
		code = atoi(ATM_E_AUTH);
	}
	//Get info concerning the job from the incoming request originating 
	//from the sensor
	baseRecord usage_info;
	map<string,string> fieldsValues;
	if ( success )
	{
		if ( parse_xml(input, &usage_info, fieldsValues) != 0 )
		{
			//something went wrong parsing the input DGASML
			 hlr_log ("getRecord Engine: Error parsing the XML, reporting error.", &logStream,1);
			 code = atoi(E_PARSE_ERROR);
			 success = false;
		} 
		else
		{
			if ( (usage_info.tableName).find("sysDef") != string::npos )
			{
				//sysDef table
				hlr_log ("getRecord Engine: Processing sysDef record", &logStream,6);
				db hlrDb ( hlr_sql_server,
					hlr_sql_user,
					hlr_sql_password,
					hlr_sql_dbname);
				if ( hlrDb.errNo != 0 )
				{
					code = atoi(E_NO_DB);
					success = false;
				}
				else
				{
					//getTable Definition.
					string queryStr = "DESCRIBE " + usage_info.tableName;
					dbResult result = hlrDb.query(queryStr);
					if ( hlrDb.errNo != 0 )
					{
						success = false;
						hlr_log("Warning: the requested table does not exists. Create it first!", &logStream, 3);
						code = atoi(ATM_E_TRANS);
					}
					else
					{
						//check that table size is
						//equal to number of fields
						//specified by teh client. 
						//throw an erro if not
						if ( result.numRows() != fieldsValues.size() )
						{
							//there is a mismatch
							success = false;
							code = atoi(E_NO_ATTRIBUTES);
							hlr_log("Wrong number of attributes from the client", &logStream, 3);
						}
						else
						{
							//create a map containing field names and corresponding types
							//as defined in the database.
							map<string,string> tableDef;
							for ( unsigned int i = 0; i< result.numRows(); i++ )
							{
								string field =result.getItem(i,0);
								string type =result.getItem(i,1);
								tableDef.insert(pair<string,string>(field,type));
							}
							//compose INSERT query managing field types.
							string queryStr = "INSERT INTO " + usage_info.tableName + " SET ";
							map<string,string>::iterator it = fieldsValues.begin();
							bool alreadyStarted = false;
							while ( it != fieldsValues.end() )
							{
								if ( (*it).second != "" )
								{ 
									if ( (it != fieldsValues.begin()) && alreadyStarted )
									{
										queryStr += ",";
									}
									queryStr += (*it).first+"=";
									string typeBuff = tableDef[(*it).first];
									if ( typeBuff.find("int") != string::npos )
									{
										queryStr += (*it).second; 
									} 
									if ( typeBuff.find("date") != string::npos )
									{
										//integer type
										queryStr += (*it).second; 
									} 
									if ( typeBuff.find("char") != string::npos )
									{
										//string type
										queryStr += "\"" + (*it).second + "\""; 
									}
									alreadyStarted=true;
								}
								it++;
							}	
							hlr_log ( queryStr,&logStream,8);
							//perform query
							dbResult insert = hlrDb.query(queryStr);
							if ( hlrDb.errNo != 0 )
							{
								success = false;
								code = atoi(ATM_E_TRANS);
							}
						}
					}
				}
			}
			else
			{
				//voStorageRecords table
				hlr_log ("getRecord Engine: Processing record", &logStream,6);
				time_t currTime;
				time (&currTime);
				if ( usage_info.timestamp == "" )
				{
					//if time is not available use current time!
					usage_info.timestamp = int2string(currTime);
				}
				string buff = usage_info.timestamp + usage_info.vo + usage_info.voDefSubClass + usage_info.storage + usage_info.storageDefSubClass + usage_info.usedBytes + usage_info.freeBytes;
				usage_info.uniqueChecksum = md5sum(buff);
				string logBuff ="Inserting into " + usage_info.tableName + ":"; 
				usage_info.uniqueChecksum + "," + 
				usage_info.timestamp + "," + 
				usage_info.vo + "," +
				usage_info.voDefSubClass + "," +
				usage_info.storage+","+
				usage_info.usedBytes+","+
				usage_info.freeBytes;
				hlr_log (logBuff, &logStream,6);
				string queryStr = "INSERT INTO " + usage_info.tableName;
				queryStr += " VALUES (0,'";
				queryStr += usage_info.uniqueChecksum + "',";
				queryStr += usage_info.timestamp + ",'";
				queryStr += usage_info.siteName + "','";
				queryStr += usage_info.vo + "','";
				queryStr += usage_info.voDefSubClass + "','";
				queryStr += usage_info.storage + "','";
				queryStr += usage_info.storageDefSubClass + "','";
				queryStr += connectionInfo.hostName + "',";
				queryStr += usage_info.usedBytes + ",";
				queryStr += usage_info.freeBytes + ")";
				hlr_log(queryStr, &logStream, 8);
				db hlrDb ( hlr_sql_server,
					hlr_sql_user,
					hlr_sql_password,
					hlr_sql_dbname);
				if ( hlrDb.errNo == 0 )
				{
					hlrDb.query(queryStr);
					if ( hlrDb.errNo != 0 )
					{
						success = false;
						code = atoi(ATM_E_TRANS);
					}
				}
				else
				{
					code = atoi(E_NO_DB);
					success = false;
				} 
			}
		}
	}//ifsuccess
	string message;
        if (success)
        {
		message += "<dgas:info status=\"ok\"\\>\n";
        }
	else
	{
		message += "<dgas:info status=\"failed\"\\>\n";
		message += "<errMsg>";
        	message += e.error[int2string(code)];
        	message += "</errMsg>";
	}
	message += "<CODE>\n";
	message += int2string(code);
	message += "\n</CODE>\n";
        if ( compose_xml(usage_info, message, output) != 0 )
        {
	         hlr_log ( "getRecord engine: Error composing the XML answer!",&logStream,3);
        }
	hlr_log ("getRecord Engine: Exiting.", &logStream,4);	
	return code;
} //Engine( string doc, connInfo &connectionInfo, string *output )
Esempio n. 23
0
static int motherdisc_parse()
{
	char xml_uri[512];
	char sqlite_cmd[1024];
	char error_num[32];
	int ret = 0;

	DEBUG("%s, process motherdisc...\n", MOTHERDISC_XML_URI);
	
	sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"DELETE FROM Initialize;");
	sqlite_execute(sqlite_cmd);
	
	// parse Initialize.xml
	if(0==parse_xml(initialize_uri_get(), INITIALIZE_XML, NULL)){
		// parse Service.xml
		sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT URI FROM Initialize WHERE PushFlag='%d';", SERVICE_XML);
		memset(xml_uri,0,sizeof(xml_uri));
		if(0==str_sqlite_read(xml_uri,sizeof(xml_uri),sqlite_cmd) && 0==parse_xml(xml_uri, SERVICE_XML, NULL)){
			
		}
		else{
			DEBUG("read URI or parse for %d failed\n",SERVICE_XML);
			// Service.xml是无关紧要的文件,即便失败也继续。
			//msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, NULL, 0);
			
			//ret = -1;
		}
		
#if 0
		// parse GuideList.xml	
		sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT URI FROM Initialize WHERE PushFlag='%d';", GUIDELIST_XML);
		memset(xml_uri,0,sizeof(xml_uri));
		if(0==str_sqlite_read(xml_uri,sizeof(xml_uri),sqlite_cmd) && 0==parse_xml(xml_uri, GUIDELIST_XML, NULL)){
			
		}
		else{
			DEBUG("read URI or parse for %d failed\n",GUIDELIST_XML);
			snprintf(error_num,sizeof(error_num),"%d",GUIDELIST_XML);
			msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, error_num, strlen(error_num));
			
			ret = -1;
		}
#endif
		
		// parse ProductDesc.xml
		// 解析ProductDesc.xml时判断拒绝的节目也入库
		
		sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"DELETE FROM ProductDesc;");
		sqlite_execute(sqlite_cmd);
		
		sqlite3_snprintf(sizeof(sqlite_cmd),sqlite_cmd,"SELECT URI FROM Initialize WHERE PushFlag='%d';", PRODUCTDESC_XML);
		memset(xml_uri,0,sizeof(xml_uri));
		if(0==str_sqlite_read(xml_uri,sizeof(xml_uri),sqlite_cmd) && 0==parse_xml(xml_uri, PRODUCTDESC_XML, NULL)){
			DEBUG("parse xmls for mother disc initialize finish, waiting for programs parsing...\n");
			
			parse_progs();
			msg_send2_UI(MOTHER_DISC_INITIALIZE_SUCCESS, NULL, 0);
			DEBUG("parse publications for mother disc initialize finished\n");
			
			ret = 0;
		}
		else{
			DEBUG("read URI or parse for %d failed\n",PRODUCTDESC_XML);
			snprintf(error_num,sizeof(error_num),"%d",PRODUCTDESC_XML);
			msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, error_num, strlen(error_num));
			
			ret = -1;
		}
		
		// 只要ProductDesc.xml解析过,无论成功与否,都直接返回0。即使在失败情况下,也无需再次尝试,没有意义。
		ret = 0;
	}
	else{
		DEBUG("parse %d for motherdisc init failed\n", INITIALIZE_XML);
		snprintf(error_num,sizeof(error_num),"%d",INITIALIZE_XML);
		msg_send2_UI(MOTHER_DISC_INITIALIZE_FAILED, error_num, strlen(error_num));
		
		ret = -1;
	}
	
	return ret;
}