⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 urlbox.c

📁 一个内存数据库的源代码这是服务器端还有客户端
💻 C
📖 第 1 页 / 共 2 页
字号:
#line 139 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"#include "mal_config.h"#include "urlbox.h"#include "mal_linker.h"#include "mal_authorize.h"#define MAXURLDEPTH 50static int urlDepth = 0;static BAT *urlBAT[MAXURLDEPTH];strURLBOXprelude(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	Box box;	int depth;	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;		rethrow("urlBox.prelude", tmp, AUTHrequireAdmin());	}#line 157 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	box = openBox("urlbox");	if (box == 0)		throw(MAL, "urlbox.prelude", "failed to open box");	/* if the box was already filled we can skip initialization */	for(depth=0; depth<MAXURLDEPTH; depth++) {		urlBAT[depth]=0;	}	urlDepth= 0;	return MAL_SUCCEED;}#line 171 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"strURLBOXopen(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;		rethrow("urlBox.open", tmp, AUTHrequireAdmin());	}#line 177 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	if (openBox("urlbox") != 0)		return MAL_SUCCEED;	throw(MAL, "urlbox.open", "failed to open box");}strURLBOXclose(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;		rethrow("urlBox.close", tmp, AUTHrequireAdmin());	}#line 189 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	if (closeBox("urlbox", TRUE) == 0)		return MAL_SUCCEED;	throw(MAL, "urlbox.close", "failed to close box");}strURLBOXdestroy(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	Box box;	(void) mb;	(void) stk;	(void) pci;		/* fool compiler */	#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;		rethrow("urlBox.destroy", tmp, AUTHrequireAdmin());	}#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	box= findBox("urlbox");	if( box ==0) 	throw(MAL, "urlbox.destroy","box is not open");#line 203 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	destroyBox("urlbox");	return MAL_SUCCEED;}#line 219 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"intURLBOXchop(str url, str *parts){	char *s, *t;	int depth=0;	s= url;	while( *s && *s != '\n'){		t= s+1;		while(*t && *t !='\n' && *t!= '/') t++;		if( *t ){			*t= 0;		} else break;		parts[depth++]= s;		for( t++; *t && (*t == '\n' || *t== '/'); t++) ;		s= t;	}	return depth;}strURLBOXinsert(char *tuple){	str parts[MAXURLDEPTH];	int i=0,depth;	BAT *b;	ptr p;	int idx= 0,prv=0;	char buf[128];	depth= URLBOXchop(tuple, parts);	if( depth == 0) return MAL_SUCCEED;	if( depth > urlDepth || urlBAT[0]== NULL){		for(i=0; i<=depth; i++){			/* make new bat */			snprintf(buf, 128, "urlbox_%d", i);			b = BATdescriptor(BBPindex(buf));			if (b){				urlBAT[i] = b;				continue;			}			b = BATnew(TYPE_int, TYPE_str, 1024);			if (b == NULL)				GDKfatal("urlbox.create: could not allocate.");			BATkey(b,TRUE);			BBPrename(b->batCacheid, buf);			BATmode(b, PERSISTENT);			BATcommit(b);			urlBAT[i] = b;		}		urlDepth= depth;	}#line 273 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	p= BUNfnd(BATmirror(urlBAT[0]),parts[0]);	if( p ) 		for( i=1; i<depth; i++){			/* printf("search [%d]:%s\n",i,parts[i]);*/			p= BUNfnd(BATmirror(urlBAT[i]),parts[i]);			if( p == 0) break;			prv= *(int*) p;		}	else i = 0;#line 285 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	for( ; i<depth; i++){		/* printf("update [%d]:%s\n",i,parts[i]);*/		idx= (int) BATcount(urlBAT[i]);		BUNins(urlBAT[i], (ptr) &prv, parts[i], FALSE);		prv=idx;	}	return MAL_SUCCEED;}#define SIZE 1*1024*1024strURLBOXdepositFile(int *r, str *fnme){	stream *fs;	bstream *bs;	char *s,*t;	int len=0;	char buf[PATHLENGTH];	Client c= MCgetClient();	(void) r; 	if( **fnme == '/')		snprintf(buf,PATHLENGTH,"%s",*fnme);	else snprintf(buf,PATHLENGTH,"%s/%s",c->cwd,*fnme);	/* later, handle directory separator */	fs= open_rastream(buf);	if( fs == NULL || stream_errnr(fs) ) 		throw(MAL, "urlbox.deposit","File not accessible");	bs= bstream_create(fs,SIZE);	if( bs == NULL) 		throw(MAL, "urlbox.deposit","Buffered file not available");	while( bstream_read(bs,bs->size-(bs->len-bs->pos)) != 0 &&		!stream_errnr(bs->s) ){		s= bs->buf;		for( t=s; *t ; ){			while(t < bs->buf+bs->len && *t && *t != '\n') t++;			if(t== bs->buf+bs->len || *t != '\n'){				/* read next block if possible after shift  */				len = t-s;				memcpy(bs->buf, s, len);				bs->len = len;				bs->pos = 0;				break;			}			/* found a string to be processed */			*t = 0;			URLBOXinsert(s);			*t= '\n';			s= t+1;			t= s;		}	}	bstream_destroy(bs);	stream_close(fs);	stream_destroy(fs);	return MAL_SUCCEED;}strURLBOXdeposit(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str url;	Box box;	char tuple[2048];	(void) mb;	#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;		rethrow("urlBox.deposit", tmp, AUTHrequireAdmin());	}#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	box= findBox("urlbox");	if( box ==0) 	throw(MAL, "urlbox.deposit","box is not open");#line 351 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	url = (str) getArgValue(stk, pci, 1);	if( strlen(url) <2048)		strcpy(tuple,url);	else throw(MAL, "urlbox.deposit","url too long");	return URLBOXinsert(url);}strURLBOXtake(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str url, parts[MAXURLDEPTH];	Box box;	#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;		rethrow("urlBox.take", tmp, AUTHrequireAdmin());	}#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	box= findBox("urlbox");	if( box ==0) 	throw(MAL, "urlbox.take","box is not open");#line 365 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	url = (str) getArgValue(stk, pci, 1);	url = GDKstrdup(url);	URLBOXchop(url, parts);	GDKfree(url);	(void) mb;	return MAL_SUCCEED;}strURLBOXrelease(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str name;	Box box;	(void) mb;		/* fool compiler */	#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;		rethrow("urlBox.release", tmp, AUTHrequireAdmin());	}#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	box= findBox("urlbox");	if( box ==0) 	throw(MAL, "urlbox.release","box is not open");#line 382 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	name = (str) getArgValue(stk, pci, 1);	if (releaseBox(box, name))		throw(MAL, "urlbox.release", "failed to release object from box");	return MAL_SUCCEED;}strURLBOXreleaseOid(MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){	str name;	Box box;	(void) mb;		/* fool compiler */	#line 212 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	#line 134 "/export/scratch0/monet/monet.GNU.64.64.d.14791/MonetDB5/src/modules/mal/urlbox.mx"	{		str tmp = NULL;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -