Exemplo n.º 1
0
int preprocessAndRun(struct collectionFormat *collection, struct cargsF *cargs, char execute[], char *error, int errorlength) {

	//antar at rutiner som ikke returnerer noe mislykkes. Dette kan for eks skje hvis vi kaller die, eller ikke trenger retur koden

	char perlfile[PATH_MAX];

	snprintf(perlfile,sizeof(perlfile),"%s/main.pm",collection->crawlLibInfo->resourcepath);

	bblog(DEBUGINFO, "cargs %p\n",cargs);


	#ifdef DEBUG
		//printer ut pekere til colection info, og alle rutinene
		bblog(DEBUGINFO, "collection %p, documentExist %p, documentAdd %p, documentError %p, documentContinue %p",cargs->collection,cargs->documentExist,cargs->documentAdd,cargs->documentError,cargs->documentContinue);
	#endif

	HV *obj_attr = newHV();
	hv_store(obj_attr, "ptr", strlen("ptr"), sv_2mortal(newSViv(PTR2IV(cargs))), 0);


	HV *hv = newHV();

	//sendes altid med
	hv_store(hv, "last_crawl", strlen("last_crawl"), sv_2mortal(newSVuv(collection->lastCrawl)), 0);

	//sendes bare med hvis vi har verdi
	if (collection->resource != NULL)
		hv_store(hv, "resource", strlen("resource"), sv_2mortal(newSVpv(collection->resource, 0)), 0);
	if (collection->connector != NULL)
		hv_store(hv, "connector", strlen("connector"), sv_2mortal(newSVpv(collection->connector, 0)), 0);
	if (collection->password != NULL)
		hv_store(hv, "password", strlen("password"), sv_2mortal(newSVpv(collection->password, 0)), 0);
	if (collection->query1 != NULL)
		hv_store(hv, "query1", strlen("query1"), sv_2mortal(newSVpv(collection->query1, 0)), 0);
	if (collection->query2 != NULL)
		hv_store(hv, "query2", strlen("query2"), sv_2mortal(newSVpv(collection->query2, 0)), 0);
	if (collection->collection_name != NULL)
		hv_store(hv, "collection_name", strlen("collection_name"), sv_2mortal(newSVpv(collection->collection_name, 0)), 0);
	if (collection->user != NULL)
		hv_store(hv, "user", strlen("user"), sv_2mortal(newSVpv(collection->user, 0)), 0);
	if (collection->userprefix != NULL)
		hv_store(hv, "userprefix", strlen("userprefix"), sv_2mortal(newSVpv(collection->userprefix, 0)), 0);
	if (collection->extra != NULL)
		hv_store(hv, "extra", strlen("extra"), sv_2mortal(newSVpv(collection->extra, 0)), 0);
	if (collection->test_file_prefix != NULL)
		hv_store(hv, "test_file_prefix", strlen("test_file_prefix"), sv_2mortal(newSVpv(collection->test_file_prefix, 0)), 0);


        // Add custom params to hash.
	ht_to_perl_ht(hv, collection->params);

	return perl_embed_run(perlfile, execute, hv, "Perlcrawl", obj_attr, error, errorlength);

}
Exemplo n.º 2
0
void run_filter_perlplugin(char *dst, size_t dst_size, struct fileFilterFormat *filter, struct hashtable **metahash) {
	char perlpath[PATH_MAX];	
	snprintf(perlpath, sizeof perlpath, "%smain.pm", filter->path);

	HV *perl_metahash = newHV();
	SV *perl_dst = newSVpv("", strlen(""));
	//AV *perl_extracted_files = newAV();
	HV *params = newHV();

	hv_store(params, "file", strlen("file"), sv_2mortal(newSVpv(filter->command, 0)), 0);
	hv_store(params, "metadata", strlen("metadata"), sv_2mortal(newRV((SV *) perl_metahash)), 0);
	hv_store(params, "data", strlen("data"),  sv_2mortal(newRV((SV *) perl_dst)), 0);
	//hv_store(params, "extracted_files", strlen("extracted_files"),  sv_2mortal(newRV((SV *) perl_extracted_files)), 0);

	#ifdef DEBUG
		printf("perl run: %s:dump(file=%s, metadata=%p)\n",perlpath,filter->command,perl_metahash);
	#endif

	if(!perl_embed_run(perlpath, "dump", params, NULL, NULL, NULL, 0))
		errx(1, "Perlplugin error on '%s'", filter->command);

	STRLEN data_size;
	char *data = SvPV(perl_dst, data_size);


	// asuming data is a '\0'-terminated string
	strlcpy(dst, data, dst_size);

	if (metahash) {
		*metahash = create_hashtable(3, ht_stringhash, ht_stringcmp);
		perl_ht_to_ht(perl_metahash, *metahash);
	}

	// clean up
	hv_undef(perl_metahash);
	hv_undef(params);
	free(data); 

}