Пример #1
0
int movie_load(char *filename)
{
	memfile_t *file;
	u32 size;
	u8 flags;
	int devid[3];
	char ident[5];

	movie_unload();
	if((file = memfile_open(filename,"rb")) == 0) {
		log_printf("movie_load:  error opening movie '%s'\n",filename);
		return(1);
	}
	//need header and stuff here
	memfile_read(ident,1,4,file);
	if(memcmp(ident,movie_ident,4) != 0) {
		log_printf("movie_load:  bad movie ident\n");
		memfile_close(file);
		return(2);
	}

	//read movie flags
	memfile_read(&flags,1,sizeof(u8),file);
	if(flags & 1)
		nes->movie.mode |= MOVIE_TEST;

	//set required input devices
	memfile_read(&devid[0],1,sizeof(int),file);
	memfile_read(&devid[1],1,sizeof(int),file);
	memfile_read(&devid[2],1,sizeof(int),file);
	nes_set_inputdev(0,devid[0]);
	nes_set_inputdev(1,devid[1]);
	nes_set_inputdev(2,devid[2]);

	//read movie data
	memfile_read(&nes->movie.startframe,1,sizeof(u32),file);
	memfile_read(&nes->movie.endframe,1,sizeof(u32),file);
	memfile_read(&nes->movie.crc32,1,sizeof(u32),file);
	memfile_read(&nes->movie.len,1,sizeof(u32),file);
	log_printf("movie_load:  start, end = %d, %d :: len = %d bytes\n",nes->movie.startframe,nes->movie.endframe,nes->movie.len);
	nes->movie.data = (u8*)mem_alloc(nes->movie.len);
	memfile_read(nes->movie.data,1,nes->movie.len,file);
	size = memfile_size(file) - memfile_tell(file);
	nes->movie.state = memfile_create();
	memfile_copy(nes->movie.state,file,size);
	memfile_close(file);
	return(0);
}
Пример #2
0
static int loadbios(cart_t *ret,char *filename)
{
	memfile_t *file;
	int n = 0;

	//open bios file
	if((file = memfile_open(filename,"rb")) == 0) {
		log_printf("loadbios:  error opening fds bios '%s'\n",filename);
		return(1);
	}

	//setup prg for bios
	ret->prg.size = 0x2000;
	ret->prg.mask = 0x1FFF;
	ret->prg.data = (u8*)mem_alloc(0x2000);

	//read bios
	if(memfile_read(ret->prg.data,1,0x2000,file) != 0x2000) {
		log_printf("loadbios:  error reading bios file '%s'\n",filename);
		n = 1;
	}
	else
		log_printf("loadbios:  loaded bios file '%s'\n",filename);

	//close bios file handle
	memfile_close(file);

	//return
	return(n);
}
Пример #3
0
static int abstract_search_handler(request_rec *r, softbot_handler_rec *s)
{
    int rv = 0;
    int i = 0;
	int recv_pos = 0;
    memfile *buf = NULL;
	virtual_document_t* vd = NULL;
    int max_doc_hits_size = 0;

    sb_run_qp_get_max_doc_hits_size( &max_doc_hits_size );

    init_server(r, s);

	set_con_config(r->server);
	msg_record_init(&s->msg);

	rv = sb_run_qp_init();
    if(rv != SUCCESS && rv != DECLINE) {
	    MSG_RECORD(&s->msg, error, "qp init failed");
        return FAIL;
    }

	if(apr_table_get(s->parameters_in, "q") == NULL ||
			strlen(apr_table_get(s->parameters_in, "q")) == 0) {
	    MSG_RECORD(&s->msg, error, "query is null, must use http get method");
        return FAIL;
	}

	ap_unescape_url((char *)apr_table_get(s->parameters_in, "q"));

    rv = sb_run_qp_init_request(&qp_request, 
                                (char *)apr_table_get(s->parameters_in, "q"));
    if(rv != SUCCESS) {
	    s->msg = qp_request.msg;
        error("can not init request");
        return FAIL;
    }

    rv = sb_run_qp_init_response(&qp_response);
    if(rv != SUCCESS) {
	    s->msg = qp_request.msg;
        error("can not init request");
        return FAIL;
    }

	/* 수신할 doc_hit 를 assign */
	qp_response.vdl->cnt = 1;
	vd = &(qp_response.vdl->data[0]);

	if(g_dochits_buffer == NULL) {
		g_dochits_buffer = (doc_hit_t*)sb_calloc(max_doc_hits_size, sizeof(doc_hit_t));
	}

    vd->dochits = g_dochits_buffer; 

	/* comment를 추출할 virtual document 정보 받기 */
	CHECK_REQUEST_CONTENT_TYPE(r, "x-softbotd/binary");

	if (sb_run_sbhandler_make_memfile(r, &buf) != SUCCESS) {
	    MSG_RECORD(&s->msg, error, "make_memfile_from_postdata failed");
        if(buf != NULL) memfile_free(buf);
		return FAIL;
	}

    vd->dochit_cnt = memfile_getSize(buf) / (sizeof(doc_hit_t) + sizeof(uint32_t));
    for (i = 0; i < vd->dochit_cnt; i++) {
		uint32_t node_id = 0;
		uint32_t recv_data_size = 0;

        recv_data_size = sizeof(doc_hit_t);
        if ( memfile_read(buf, (char*)&(vd->dochits[recv_pos]), recv_data_size)
                != recv_data_size ) {
			MSG_RECORD(&s->msg, error, "incomplete result at [%d]th node: doc_hits ", i);
            if(buf != NULL) memfile_free(buf);
            return FAIL;
        }

		// 2. node_id 수신
		recv_data_size = sizeof(uint32_t);
		if ( memfile_read(buf, (char*)&node_id, recv_data_size)
				!= recv_data_size ) {
			MSG_RECORD(&s->msg, error, "incomplete result at [%d]th node: node_id ", i);
            if(buf != NULL) memfile_free(buf);
			return FAIL;
		}

		// 자신의 node_id가 아니면 error
		if(get_node_id(node_id) != this_node_id) {
			MSG_RECORD(&s->msg, 
			              error, "node_id[%u] not equals this_node_id[%0X]",
						  get_node_id(node_id),
						  this_node_id);
            if(buf != NULL) memfile_free(buf);
			return FAIL;
		}

		debug("did[%u], node_id[%0X]", vd->dochits[recv_pos].id, node_id);

        // 자신의 node_id pop
        node_id = pop_node_id(node_id);
		recv_pos++;
    }
	vd->dochit_cnt = recv_pos;


	/* comment 추출 */
	timelog("sb_run_qp_abstract_search start");
	rv = sb_run_qp_abstract_search(&qp_request, &qp_response);
	timelog("sb_run_qp_abstract_search finish");
	if (rv != SUCCESS) {
	    s->msg = qp_request.msg;
		error("sb_run_qp_abstract_search failed: query[%s]", qp_request.query);
        if(buf != NULL) memfile_free(buf);
		return FAIL;
	}

    /////////// abstarct search 결과 전송 ////////////////////////////////////////
    ap_set_content_type(r, "x-softbotd/binary");

    // 1. 전송건수.
    ap_rwrite(&vd->comment_cnt, sizeof(uint32_t), r);
	
	// 2. doc_hits 전송.
    for (i = 0; i < vd->comment_cnt; i++ ) {
        // 2.1 doc_id 전송.
        ap_rwrite(&vd->dochits[i].id, sizeof(uint32_t), r);
        // 2.2 node_id 전송.
        ap_rwrite(&this_node_id, sizeof(uint32_t), r);
        // 2.3. comment
        ap_rwrite(qp_response.comments[i].s, LONG_LONG_STRING_SIZE, r);
		debug("comments[%s]", qp_response.comments[i].s);
    }

    // log를 위하여 setting 해준다.
    qp_response.search_result = vd->comment_cnt;

	s->msg = qp_request.msg;

    if(buf != NULL) memfile_free(buf);
	return SUCCESS;
}
Пример #4
0
int cart_load_nsf(cart_t *ret,memfile_t *file)
{
	int n = 0;
	char biosfile[1024];
	u32 size;
	u32 loadaddr;
	u8 nobankswitch[8 + 8] = {0,0,0,0,0,0,0,0,  0,1,2,3,4,5,6,7};

	//clear the string
	memset(biosfile,0,1024);

	//parse the bios path
	config_get_eval_string(biosfile,"path.bios");

	//append the path seperator
	str_appendchar(biosfile,PATH_SEPERATOR);

	//append the bios filename
	strcat(biosfile,"nsfbios.bin");

	//try to load bios from the bios directory
	if(loadbios(ret,biosfile) != 0) {

		//see if bios is in the current directory
		if(loadbios(ret,"nsfbios.bin") != 0) {
			return(1);
		}
	}

	//get length of file
	size = memfile_size(file);

	//discount for the header
	size -= 0x80;

	if(memfile_read(ret->data,1,0x80,file) != 0x80) {
		log_printf("cart_load_nsf:  error reading header from '%s'\n",file->filename);
		n = 1;
	}
	else {
		loadaddr = ret->data[8] | (ret->data[9] << 8);

		//if the nsf doesnt use bankswitching
		if(memcmp((u8*)ret->data + 0x70,(u8*)nobankswitch,8) == 0) {
			memcpy((u8*)ret->data + 0x70,(u8*)nobankswitch + 8,8);
			ret->prg.size = (u32)size + (loadaddr & 0x7FFF);
			ret->prg.data = (u8*)mem_alloc(ret->prg.size);
			memset(ret->prg.data,0,ret->prg.size);
			memfile_read(ret->prg.data + (loadaddr & 0x7FFF),1,size,file);
		}

		//else the nsf is bankswitched
		else {
			ret->prg.size = (u32)size + (loadaddr & 0xFFF);
			ret->prg.data = (u8*)mem_alloc(ret->prg.size);
			memset(ret->prg.data,0,ret->prg.size);
			memfile_read(ret->prg.data + (loadaddr & 0xFFF),1,size,file);
		}

		//setup mapper
		ret->mapperid = B_NSF;
		log_printf("cart_load_nsf:  nsf v%d loaded, %d bytes (padded to %d), %d songs.\n",ret->data[5],size,ret->prg.size,ret->data[6]);
		log_printf("init $%04X, play $%04X\n",ret->data[0xA] | (ret->data[0xB] << 8),ret->data[0xC] | (ret->data[0xD] << 8));
	}

	return(n);
}
Пример #5
0
/////////////////////////////////////////////////////////////////////////
// 문서 등록/수정 
static int document_insert(request_rec *r, softbot_handler_rec *s)
{
    int rv = 0;
    uint32_t docid = 0;
    uint32_t olddocid = 0;
    char* OID = 0;
    char* document = NULL;
    memfile* request_body = NULL;

    OID = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "OID"));

    if(OID == NULL || strlen(OID) == 0) {
        MSG_RECORD(&s->msg, error, "oid is null, get parameter exist with oid.");
        return FAIL;
    }
    
    // 이미 존재하는 문서는 삭제.
	rv = sb_run_get_docid(did_db, OID, &docid);
	if ( rv == SUCCESS ) document_delete(r, s);

    decodencpy(OID, OID, strlen(OID));

    rv = sb_run_sbhandler_make_memfile(r, &request_body);
    if(rv != SUCCESS) {
        MSG_RECORD(&s->msg, error, "cannot get POST data");
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }

    if (canned_doc == NULL) {
        canned_doc = (char *)sb_malloc(DOCUMENT_SIZE);
        if (canned_doc == NULL) {
            MSG_RECORD(&s->msg, crit, "out of memory: %s", strerror(errno));
		    if(request_body != NULL) memfile_free(request_body);
            return FAIL;
        }
    }

    if(memfile_getSize(request_body) >= DOCUMENT_SIZE) {
        MSG_RECORD(&s->msg, error, "cannot insert document, max size[%d], current size[%ld]",
                                  DOCUMENT_SIZE, memfile_getSize(request_body));
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }

    rv = memfile_read(request_body, canned_doc, memfile_getSize(request_body));
    if(rv != memfile_getSize(request_body)) {
        MSG_RECORD(&s->msg, error, "cannot read memfile");
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }
    canned_doc[memfile_getSize(request_body)] = '\0';
	debug("memfile_getSize(request_body) = [%ld]", memfile_getSize(request_body));

    decodencpy(canned_doc, canned_doc, strlen(canned_doc));

    document = strchr(canned_doc, '=');
    if(document == NULL || document - canned_doc > 20) {
        MSG_RECORD(&s->msg, error, "cannot find body");
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }

    document++;

	rv = sb_run_cdm_put_xmldoc(cdm_db, did_db, OID,
			document, strlen(document), &docid, &olddocid);
	switch ( rv ) {
		case CDM2_PUT_NOT_WELL_FORMED_DOC:
			//RGLOG_ERROR("cannot register canned document[%s]. not well formed document", OID);
			break;
		case CDM2_PUT_OID_DUPLICATED:
			//RGLOG_INFO("doc[%u] is deleted. OID[%s] is registered by docid[%u]", olddocid, OID, docid);
			break;
		case SUCCESS:
			//RGLOG_INFO("OID[%s] is registered by docid[%u]", OID, docid);
			break;
		default:
			//RGLOG_ERROR("cannot register canned document[%s] because of error(%d)", OID, n);
			break;
	}

	if(request_body != NULL) memfile_free(request_body);
    return SUCCESS;
}
Пример #6
0
static int document_ma(request_rec *r, softbot_handler_rec *s)
{
    int rv = 0;
    char* metadata = NULL;
    char* document = NULL;
    char* p = NULL;
    void *parser = NULL;
	char* field_value; int field_length;
    sb4_merge_buffer_t merge_buffer;
    memfile* request_body = NULL;
	char field_name[MAX_FIELD_NAME_LEN];
	int ma_id = 0;
    int field_id = 0;
	int data_size =0;
	uint32_t buffer_size=0;
	char *buffer = NULL;
    int is_binary = 0;
	int is_plantext = 0;
	int is_raw_koma_text = 0;
    char* contenttype = NULL;
    char* rawkomatext = NULL;
	char content_type[SHORT_STRING_SIZE+1];

    is_binary = equals_content_type(r, "x-softbotd/binary");

    contenttype = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "contenttype"));
	if(contenttype == NULL) {
        is_plantext = 0; // xml
	} else if(strncasecmp("xml", contenttype, 3) == 0) {
        is_plantext = 0; // xml
	} else if(strncasecmp("text", contenttype, 4) == 0) {
        is_plantext = 1; // text
	}

    rawkomatext = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "rawkomatext"));
	if(rawkomatext == NULL) {
        is_raw_koma_text = 0;
	} else {
        is_raw_koma_text = 1;
	}

    metadata = apr_pstrdup(r->pool, apr_table_get(s->parameters_in, "metadata"));

    if( metadata == NULL || strlen(metadata) == 0 ) {
        MSG_RECORD(&s->msg, error, "metadata is null, get parameter exist with metadata.");
        return FAIL;
    }

    if (canned_doc == NULL) {
        canned_doc = (char *)sb_malloc(DOCUMENT_SIZE);
        if (canned_doc == NULL) {
            MSG_RECORD(&s->msg, crit, "out of memory: %s", strerror(errno));
            return FAIL;
        }
    }
    
    if(metadata != NULL) decodencpy(metadata, metadata, strlen(metadata));

    rv = sb_run_sbhandler_make_memfile(r, &request_body);
    if(rv != SUCCESS) {
        MSG_RECORD(&s->msg, error, "can not post data");
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }

    if(memfile_getSize(request_body) >= DOCUMENT_SIZE) {
        MSG_RECORD(&s->msg, error, "can not insert document, max size[%d], current size[%ld]",
                                  DOCUMENT_SIZE, memfile_getSize(request_body));
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }

    rv = memfile_read(request_body, canned_doc, memfile_getSize(request_body));
    if(rv != memfile_getSize(request_body)) {
        MSG_RECORD(&s->msg, error, "can not read memfile");
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }
    canned_doc[memfile_getSize(request_body)] = '\0';

    decodencpy(canned_doc, canned_doc, strlen(canned_doc));

    document = strchr(canned_doc, '=');
    if(document == NULL || document - canned_doc > 20) {
        MSG_RECORD(&s->msg, error, "can not find body");
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }

    document++;

    parser = sb_run_xmlparser_parselen("CP949" , (char *)document, strlen(document));
    if (parser == NULL) { 
        MSG_RECORD(&s->msg, error, "cannot parse document");
		if(request_body != NULL) memfile_free(request_body);
        return FAIL;
    }

    p = metadata;
    merge_buffer.data = NULL;
    merge_buffer.data_size = 0;
    merge_buffer.allocated_size = 0;

    do {
        char path[STRING_SIZE];
        char *field_id_ptr=0x00;
        char fid[3];
        int  field_id_is_given = 0;
        void* tmp_data = NULL;

        p = get_field_and_ma_id_from_meta_data(p , field_name,  &ma_id);

        field_id_ptr = strchr(field_name, '#');

        if (field_id_ptr != NULL) 
            field_id_is_given = 1;

        if (field_id_is_given == 1) {
            strcpy(fid, field_id_ptr+1);
            *field_id_ptr = '\0';
            field_id = atol(fid);
        }
        info("fieldname[%s] id[%d]", field_name, field_id);

        sprintf(path, "/Document/%s", field_name);
        path[STRING_SIZE-1] = '\0';
        rv = sb_run_xmlparser_retrieve_field(parser, path, &field_value, &field_length);

        if (field_id_is_given) {
            if (rv != SUCCESS) {
                warn("cannot retrieve field[%s]", path);
                continue;
            }

            if (field_length == 0) {
                continue;
            }
        } else {
            if (rv != SUCCESS) {
                warn("cannot retrieve field[%s]", path);
                field_id++;
                continue;
            }

            if (field_length == 0) {
                field_id++;
                continue;
            }
        }

        if ( field_length+1 > buffer_size ) {
            buffer = apr_palloc(r->pool, sizeof(char) * (field_length+1));
            buffer_size = field_length + 1;
        }

        memcpy(buffer, field_value, field_length);
        buffer[field_length] = '\0';

        tmp_data = NULL;

		if(is_raw_koma_text) ma_id = 100;
        rv = sb_run_rmas_morphological_analyzer(field_id, buffer, &tmp_data,
                &data_size, ma_id);
        if (rv == FAIL || rv == DECLINE) {
            MSG_RECORD(&s->msg, warn, "failed to do morphological analysis - rmas_morphological_analyzer()");
            sb_run_xmlparser_free_parser(parser);
            return FAIL;
        }
        info("finished ma: data_size: %d", data_size);

        rv = sb_run_rmas_merge_index_word_array( &merge_buffer , tmp_data , data_size);
        if (rv == FAIL) {
            MSG_RECORD(&s->msg, warn, "failed to do morphological analysis - rmas_merge_index_word_array()");
            sb_free(tmp_data);
            sb_run_xmlparser_free_parser(parser);
            return FAIL;
        }
        sb_free(tmp_data);

        field_id++;
    } while (*p);

    sb_run_xmlparser_free_parser(parser);

    if(is_binary == SUCCESS) {
        ap_rwrite(merge_buffer.data, merge_buffer.data_size, r);
    } else {
        int i;
        index_word_t *idx = NULL;
        int cnt = merge_buffer.data_size / sizeof(index_word_t);
	    char tag[5];

        if(is_plantext) {
				ap_rprintf(r, "%d\n", cnt);
				for(i = 0; i < cnt; i++) {
					idx = (index_word_t*)merge_buffer.data + i;

					memcpy(tag, &idx->attribute, 4);
					tag[4] = '\0';

					ap_rprintf(r, "%s %d %s\n", idx->word, idx->pos, tag);
				}
		} else {
		        snprintf( content_type, SHORT_STRING_SIZE, "text/xml; charset=%s", default_charset);
			    ap_set_content_type(r, content_type);
			    ap_rprintf(r, "<?xml version=\"1.0\" encoding=\"%s\"?>\n", default_charset);

				ap_rprintf(r, "<items count=\"%d\">", cnt);
				for(i = 0; i < cnt; i++) {
					idx = (index_word_t*)merge_buffer.data + i;

					memcpy(tag, &idx->attribute, 4);
					tag[4] = '\0';

					ap_rprintf(r, "<word pos = \"%d\"  field=\"%d\" tag=\"%s\"><![CDATA[%s]]></word>\n", idx->pos, idx->field, tag, idx->word);
				}
				ap_rprintf(r, "</items>");
	    }
    }

    return SUCCESS;
}
Пример #7
0
unsigned int mfread(MEMFILE *mf,unsigned char *buffer,unsigned int size)
{
  return memfile_read(mf, buffer, size);
}
Пример #8
0
SC_FUNC size_t mfread(memfile_t *mf,unsigned char *buffer,size_t size)
{
    return memfile_read(mf, buffer, size);
}
Пример #9
0
int ByteArrayInputStream::s_read(void* vp,char* buf,int off,int sz)
{
	if(vp==NULL)return -1;
	return memfile_read((MEMFILE*)vp,(void*)(buf+off),sz);
}
Пример #10
0
int cart_load_fds(cart_t *ret,memfile_t *file)
{
	u8 header[16];
	u32 size;
	char biosfile[1024];

	//clear the string
	memset(biosfile,0,1024);

	//parse the bios path
	config_get_eval_string(biosfile,"path.bios");

	//append the path seperator
	str_appendchar(biosfile,PATH_SEPERATOR);

	//append the bios filename
	strcat(biosfile,config_get_string("nes.fds.bios"));

	//try to load bios from the bios directory
	if(loadbios(ret,biosfile) != 0) {

		//see if bios is in the current directory
		if(loadbios(ret,config_get_string("nes.fds.bios")) != 0) {
			return(1);
		}
	}

	//get length of file
	size = memfile_size(file);

	//read the header
	memfile_read(header,1,16,file);

	//check if this is raw fds disk
	if(memcmp(header,fdsident2,15) == 0) {

		//check if the file is a valid size
		if((size % 65500) != 0) {
			log_printf("cart_load_fds:  fds disk image size not multiple of 65500, aborting\n");
			return(1);
		}

		//set number of disk sides
//		ret->disksides = size / 65500;

		//skip back to the beginning
		memfile_rewind(file);
	}

	//check if this is 16-byte header fds disk
	else if(memcmp(header,fdsident,4) == 0) {

		//set number of disk sides
//		ret->disksides = header[4];
		size -= 16;

	}

	//set mapper id to fds mapper
	ret->mapperid = B_FDS;

	//setup the disk data pointers
	ret->disk.size = size;
	ret->disk.data = (u8*)mem_alloc(size);
	ret->diskoriginal.size = size;
	ret->diskoriginal.data = (u8*)mem_alloc(size);

	//read disk data into pointer
	memfile_read(ret->disk.data,1,size,file);

	//copy to original disk data pointer
	memcpy(ret->diskoriginal.data,ret->disk.data,size);

	log_printf("cart_load_fds:  loaded disk, %d sides (%d bytes)\n",ret->disk.size / 65500,size);
	return(0);
}
Пример #11
0
size_t mf_read(void *buf, size_t size, size_t count, void *handle)
{
	return memfile_read((memfile_t *)handle, buf, size*count) / count;
}