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

📄 zserver.c

📁 harvest是一个下载html网页得机器人
💻 C
📖 第 1 页 / 共 2 页
字号:
					      rr->num_setnames, rr->setnames,					      rr->statuses);    return 0;}static int es_admin_request (ZebraHandle zh, Z_AdminEsRequest *r){    switch (r->toKeep->which)    {    case Z_ESAdminOriginPartToKeep_reIndex:	yaz_log(LOG_LOG, "adm-reindex");	break;    case Z_ESAdminOriginPartToKeep_truncate:	yaz_log(LOG_LOG, "adm-truncate");	break;    case Z_ESAdminOriginPartToKeep_drop:	yaz_log(LOG_LOG, "adm-drop");	zebra_drop_database (zh, r->toKeep->databaseName);	break;    case Z_ESAdminOriginPartToKeep_create:	yaz_log(LOG_LOG, "adm-create %s", r->toKeep->databaseName);	zebra_create_database (zh, r->toKeep->databaseName);	break;    case Z_ESAdminOriginPartToKeep_import:	yaz_log(LOG_LOG, "adm-import");	zebra_admin_import_begin (zh, r->toKeep->databaseName,			r->toKeep->u.import->recordType);	break;    case Z_ESAdminOriginPartToKeep_refresh:	yaz_log(LOG_LOG, "adm-refresh");	break;    case Z_ESAdminOriginPartToKeep_commit:	yaz_log(LOG_LOG, "adm-commit");	break;    case Z_ESAdminOriginPartToKeep_shutdown:	yaz_log(LOG_LOG, "shutdown");	zebra_admin_shutdown(zh);	break;    case Z_ESAdminOriginPartToKeep_start:	yaz_log(LOG_LOG, "start");	zebra_admin_start(zh);	break;    default:	yaz_log(LOG_LOG, "unknown admin");    }    if (r->toKeep->databaseName)    {	yaz_log(LOG_LOG, "database %s", r->toKeep->databaseName);    }    return 0;}static int es_admin (ZebraHandle zh, Z_Admin *r){    switch (r->which)    {    case Z_Admin_esRequest:	es_admin_request (zh, r->u.esRequest);	break;    case Z_Admin_taskPackage:	yaz_log (LOG_LOG, "adm taskpackage (unhandled)");	break;    default:	break;    }    return 0;}int bend_segment (void *handle, bend_segment_rr *rr){    ZebraHandle zh = (ZebraHandle) handle;    Z_Segment *segment = rr->segment;    if (segment->num_segmentRecords)	zebra_admin_import_segment (zh, rr->segment);    else	zebra_admin_import_end (zh);    return 0;}int bend_esrequest (void *handle, bend_esrequest_rr *rr){    ZebraHandle zh = (ZebraHandle) handle;        yaz_log(LOG_LOG, "function: %d", *rr->esr->function);    if (rr->esr->packageName)    	yaz_log(LOG_LOG, "packagename: %s", rr->esr->packageName);    yaz_log(LOG_LOG, "Waitaction: %d", *rr->esr->waitAction);    if (!rr->esr->taskSpecificParameters)    {        yaz_log (LOG_WARN, "No task specific parameters");    }    else if (rr->esr->taskSpecificParameters->which == Z_External_ESAdmin)    {	es_admin (zh, rr->esr->taskSpecificParameters->u.adminService);        zebra_result (zh, &rr->errcode, &rr->errstring);    }    else if (rr->esr->taskSpecificParameters->which == Z_External_update)    {    	Z_IUUpdate *up = rr->esr->taskSpecificParameters->u.update;	yaz_log (LOG_LOG, "Received DB Update");	if (up->which == Z_IUUpdate_esRequest)	{	    Z_IUUpdateEsRequest *esRequest = up->u.esRequest;	    Z_IUOriginPartToKeep *toKeep = esRequest->toKeep;	    Z_IUSuppliedRecords *notToKeep = esRequest->notToKeep;	    	    yaz_log (LOG_LOG, "action");	    if (toKeep->action)	    {		switch (*toKeep->action)		{		case Z_IUOriginPartToKeep_recordInsert:		    yaz_log (LOG_LOG, "recordInsert");		    break;		case Z_IUOriginPartToKeep_recordReplace:		    yaz_log (LOG_LOG, "recordUpdate");		    break;		case Z_IUOriginPartToKeep_recordDelete:		    yaz_log (LOG_LOG, "recordDelete");		    break;		case Z_IUOriginPartToKeep_elementUpdate:		    yaz_log (LOG_LOG, "elementUpdate");		    break;		case Z_IUOriginPartToKeep_specialUpdate:		    yaz_log (LOG_LOG, "specialUpdate");		    break;                case Z_ESAdminOriginPartToKeep_shutdown:		    yaz_log (LOG_LOG, "shutDown");		    break;		case Z_ESAdminOriginPartToKeep_start:		    yaz_log (LOG_LOG, "start");		    break;		default:		    yaz_log (LOG_LOG, " unknown (%d)", *toKeep->action);		}	    }	    if (toKeep->databaseName)	    {		yaz_log (LOG_LOG, "database: %s", toKeep->databaseName);                if (zebra_select_database(zh, toKeep->databaseName))                    return 0;	    }            else            {                yaz_log (LOG_WARN, "no database supplied for ES Update");                rr->errcode = 1008;                rr->errstring = "database";                return 0;            }	    if (notToKeep)	    {		int i;                zebra_begin_trans (zh, 1);		for (i = 0; i < notToKeep->num; i++)		{		    Z_External *rec = notToKeep->elements[i]->record;                    struct oident *oident = 0;                    Odr_oct *recid = notToKeep->elements[i]->u.opaque;                    if (!recid)                    {                        rr->errcode = 224;                        rr->errstring = "record Id not supplied";                        break;                    }                    if (notToKeep->elements[i]->which !=                        Z_IUSuppliedRecords_elem_opaque)                    {                        rr->errcode = 224;                        rr->errstring = "only opaque record ID supported";                        break;                    }                        		    if (rec->direct_reference)		    {			oident = oid_getentbyoid(rec->direct_reference);			if (oident)			    yaz_log (LOG_LOG, "record %d type %s", i,				     oident->desc);		    }		    switch (rec->which)		    {		    case Z_External_sutrs:			if (rec->u.octet_aligned->len > 170)			    yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",				     rec->u.sutrs->len,				     rec->u.sutrs->buf);			else			    yaz_log (LOG_LOG, "%d bytes:\n%s",				     rec->u.sutrs->len,				     rec->u.sutrs->buf);                        break;		    case Z_External_octet:			if (rec->u.octet_aligned->len > 170)			    yaz_log (LOG_LOG, "%d bytes:\n%.168s ...",				     rec->u.octet_aligned->len,				     rec->u.octet_aligned->buf);			else			    yaz_log (LOG_LOG, "%d bytes\n%s",				     rec->u.octet_aligned->len,				     rec->u.octet_aligned->buf);		    }                    if (oident && oident->value != VAL_TEXT_XML)                    {                        rr->errcode = 224;                        rr->errstring = "only XML update supported";                        break;                    }                    if (rec->which == Z_External_octet)                    {                        int action = 0;                        if (*toKeep->action ==                            Z_IUOriginPartToKeep_recordInsert)                            action = 1;                        if (*toKeep->action ==                            Z_IUOriginPartToKeep_recordReplace)                            action = 2;                        if (*toKeep->action ==                            Z_IUOriginPartToKeep_recordDelete)                            action = 3;                        if (*toKeep->action ==                            Z_IUOriginPartToKeep_specialUpdate)                            action = 1;                        if (!action)                        {                            rr->errcode = 224;                            rr->errstring = "unsupported ES Update action";                            break;                        }                        else                        {                            int r = zebra_admin_exchange_record (                                zh, toKeep->databaseName,                                rec->u.octet_aligned->buf,                                rec->u.octet_aligned->len,                                recid->buf, recid->len,                                action);                            if (r && *toKeep->action ==                                Z_IUOriginPartToKeep_specialUpdate)                            {                                r = zebra_admin_exchange_record (                                    zh, toKeep->databaseName,                                    rec->u.octet_aligned->buf,                                    rec->u.octet_aligned->len,                                    recid->buf, recid->len,                                    2);                            }                            if (r)                            {                                rr->errcode = 224;                                rr->errstring = "record exchange failed";                                break;                            }                        }                    }		}                zebra_end_trans (zh);	    }	}    }    else    {        yaz_log (LOG_WARN, "Unknown Extended Service(%d)",		 rr->esr->taskSpecificParameters->which);        rr->errcode = 221;	    }    return 0;}static void bend_start (struct statserv_options_block *sob){    if (sob->handle)	zebra_stop((ZebraService) sob->handle);    sob->handle = zebra_start(sob->configname);    if (!sob->handle)    {	yaz_log (LOG_FATAL, "Failed to read config `%s'", sob->configname);	exit (1);    }#ifdef WIN32    #else    if (!sob->inetd)     {	char pidfname[4096];        struct flock area;	int fd;	zebra_pidfname(sob->handle, pidfname);        fd = open (pidfname, O_EXCL|O_WRONLY|O_CREAT, 0666);        if (fd == -1)        {            if (errno != EEXIST)            {                yaz_log(LOG_FATAL|LOG_ERRNO, "lock file %s", pidfname);                exit(1);            }            fd = open(pidfname, O_RDWR, 0666);            if (fd == -1)            {                yaz_log(LOG_FATAL|LOG_ERRNO, "lock file %s", pidfname);                exit(1);            }        }        area.l_type = F_WRLCK;        area.l_whence = SEEK_SET;        area.l_len = area.l_start = 0L;        if (fcntl (fd, F_SETLK, &area) == -1)        {            yaz_log(LOG_ERRNO|LOG_FATAL, "Zebra server already running");            exit(1);        }        else        {	    char pidstr[30];		    sprintf (pidstr, "%ld", (long) getpid ());	    write (fd, pidstr, strlen(pidstr));        }    }#endif}static void bend_stop(struct statserv_options_block *sob){#ifdef WIN32#else    if (!sob->inetd && sob->handle)     {	char pidfname[4096];	zebra_pidfname(sob->handle, pidfname);        unlink (pidfname);    }#endif    if (sob->handle)    {	ZebraService service = sob->handle;	zebra_stop(service);    }}int main (int argc, char **argv){    struct statserv_options_block *sob;    sob = statserv_getcontrol ();    strcpy (sob->configname, "zebra.cfg");    sob->bend_start = bend_start;    sob->bend_stop = bend_stop;#ifdef WIN32    strcpy (sob->service_display_name, "Zebra Server");#endif    statserv_setcontrol (sob);    return statserv_main (argc, argv, bend_init, bend_close);}

⌨️ 快捷键说明

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