示例#1
0
char *ServerFindServers(void **ctx, char *wild_match)
{
#ifndef HAVE_WINDOWS_H
  char *ans = 0;
  DIR *dir = (DIR *)*ctx;
  if (dir == 0)
  {
    char *serverdir = getenv("MDSIP_SERVER_LOGDIR");
    if (serverdir)
      *ctx = dir = opendir(serverdir);
  }
  if (dir)
  {
    int done = 0;
    while (!done)
    {
      struct dirent *entry = readdir(dir);
      done = 1;
      if (entry)
      {
        static char *ans_c = 0;
        if (ans_c)
          free(ans_c);
        ans_c = strcpy(malloc(strlen(entry->d_name)+1),entry->d_name);
        if ((strcmp(ans_c,".") == 0) || (strcmp(ans_c,"..") == 0))
          done = 0;
        else
	{
          struct descriptor ans_d = {0,DTYPE_T,CLASS_S,0};
          struct descriptor wild_d = {0,DTYPE_T,CLASS_S,0};
          ans_d.pointer = ans_c;
          ans_d.length = strlen(ans_c);
          wild_d.pointer = wild_match;
          wild_d.length = strlen(wild_match);
          if (!(StrMatchWild(&ans_d,&wild_d) & 1))
            done = 0;
          else
            ans = ans_c;
        }
      }
      else
        closedir(dir);
    }
  }
  return ans;
#else
  return 0;
#endif
}
示例#2
0
/*****************************************************
  Routine to return a new tag search data structure.
******************************************************/
static TAG_SEARCH *NewTagSearch(char *tagnam_ptr)
{
    static    DESCRIPTOR(top, "TOP");
    static    DESCRIPTOR(colons, "::");
    TAG_SEARCH *ctx = (TAG_SEARCH *) malloc(sizeof(TAG_SEARCH));
    static struct descriptor_d empty = {0, DTYPE_T, CLASS_D, 0};
    struct descriptor tag_dsc = {0, DTYPE_T, CLASS_S, 0};
    unsigned short tree_len;
    char *cptr;
    static unsigned short one = 1;
    tag_dsc.length = strlen(tagnam_ptr);
    tag_dsc.pointer = tagnam_ptr;
    ctx->search_tag = empty;
    ctx->search_tree = empty;
    ctx->next_tag = -1;
    ctx->this_tree_info = 0;
    ctx->remote = 0;
    if (*(char *) tag_dsc.pointer == '\\')
    {
        tag_dsc.length--;
        (char *) tag_dsc.pointer++;
    }
    if ((cptr = strstr(tagnam_ptr,"::")) != 0)
    {
        tree_len = cptr - tagnam_ptr;
        StrCopyR(&ctx->search_tree, &tree_len, tag_dsc.pointer);
        tag_dsc.length -= (tree_len + 2);
        tag_dsc.pointer += (tree_len + 2);
    }
    else
        StrCopyR(&ctx->search_tree, &one, "*");
    if (tag_dsc.length)
        StrCopyDx(&ctx->search_tag, &tag_dsc);
    else
        StrCopyR(&ctx->search_tag, &one, "*");
    StrUpcase(&ctx->search_tree,&ctx->search_tree);
    StrUpcase(&ctx->search_tag,&ctx->search_tag);
    ctx->top_match = StrMatchWild(&top, &ctx->search_tag) & 1;
    return ctx;
}
示例#3
0
/********************************************
  Routine to return the next subtree in this
  tree which matches the wildcard tree spec.
*********************************************/
static int NextTagTree(PINO_DATABASE *dblist, TAG_SEARCH *ctx)
{
    unsigned char found = 0;
    if (ctx->this_tree_info == (TREE_INFO *) 0)
        ctx->this_tree_info = dblist->tree_info;
    else
        ctx->this_tree_info = ctx->this_tree_info->next_info;
    for (found = 0; !found && ctx->this_tree_info; ctx->this_tree_info = ctx->this_tree_info->next_info)
    {
        struct descriptor treenam = {0, DTYPE_T, CLASS_S, 0};
        treenam.length = strlen(ctx->this_tree_info->treenam);
        treenam.pointer = ctx->this_tree_info->treenam;
        if (StrMatchWild(&treenam, &ctx->search_tree) & 1)
        {
            found = 1;
            break;
        }
    }
    if (found)
        return 1;
    else
        return TreeNMT;
}
示例#4
0
文件: verbs.c 项目: LucyScott/mdsplus
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
int ShowModule()
{
	char	db_tmp[64];		// enough space for a logical name and a cstring terminator	[2002.02.20]
	int 	i, numOfEntries, status = SUCCESS;

	static DESCRIPTOR( physical, "PHYSICAL" );
	static DESCRIPTOR( module_p, "MODULE" );
	static DESCRIPTOR( format_p, "FORMAT" );
	static DESCRIPTOR( blank, " " );

	static DESCRIPTOR( heading1, "  #  Logical Name                     Physical   Comment" );	// header
	static DESCRIPTOR( heading2, "==== ================================ ========== ========================================" );

	static DYNAMIC_DESCRIPTOR( wild );
	struct Module_	Mod, *pMod;
	
	struct descriptor pattern;

	int format = cli_present(&format_p) & 1;
	int physical_name = cli_present(&physical) & 1;	// 2002.01.16

	cli_get_value( &module_p, &wild );
	StrUpcase( &wild, &wild );						// convert to upper case

	if( MSGLVL(DETAILS) )
		printf("ShowModule(): in %s order\n", (physical_name) ? "physical" : "logical" );

	// check to see if db file memory mapped
	if( CTSdbFileIsMapped == FALSE ) {				// is not, so try
		if( map_data_file(CTS_DB) != SUCCESS ) {	// we're dead in the water
			if( MSGLVL(IMPORTANT) )
				fprintf( stderr, "error memory mapping database file\n" );

			status = FAILURE;		// MAP_ERROR;		[2001.07.12]
			goto Showmodule_Exit;
		}
	}

	// db file now mapped, continue
	pMod = &Mod;										// point to some actual storage
	if( (numOfEntries = get_file_count(CTS_DB)) > 0 ) {	// something to show
		printf( "%s\n",   heading1.pointer );
		printf( "%s%d\n", heading2.pointer, numOfEntries );
		for( i = 0; i < numOfEntries; i++ ) {
			parse_cts_db( CTSdb+i, pMod );		// extract info from db

			memset(db_tmp, ' ', 32);
			db_tmp[33] = '\0';

			if( physical_name ) 		// duh, physical name
				sprintf( db_tmp, "GK%c%d%02d:N%d", 
					pMod->adapter + 'A', pMod->id, pMod->crate, pMod->slot
					);
			else
				sprintf( db_tmp, "%s", pMod->name );

			pattern.pointer = db_tmp;
			pattern.length  = strlen(db_tmp);

			if( StrMatchWild( &pattern, &wild ) & 1 ) {
//				printf( "%s%3d: %.84s<%s\n", CYAN, i+1, (char *)CTSdb+(i * MODULE_ENTRY), NORMAL );	// fancy, with color
				printf( "%3d: %.84s<\n", i+1, (char *)CTSdb+(i * MODULE_ENTRY) );
			}

		} // end of for() loop

		printf( "%s\n", heading2.pointer );
	}
	else {
		if( MSGLVL(IMPORTANT) )
			fprintf( stderr, "db file is empty, no modules to show\n" );

		status = SUCCESS;		// Not necessarily an ERROR;	[2002.02.19]
		goto Showmodule_Exit;
	}
	
Showmodule_Exit:
	if( MSGLVL(DETAILS) ) {
		printf("ShowModule(): "); ShowStatus(status);
	}

	return status;
}
示例#5
0
文件: verbs.c 项目: LucyScott/mdsplus
//-------------------------------------------------------------------------
// deassign a module
//-------------------------------------------------------------------------
int Deassign()
{
	char			db_tmp[64];
	int 			i, index, modulesToDeassign, modulesDeassigned, numOfEntries, physical_name; 
	int				status = SUCCESS;
	struct Module_	Mod, *pMod;

	static DESCRIPTOR( physical, "PHYSICAL" );

	static DESCRIPTOR( modname_p, "MODULE" );
	static DYNAMIC_DESCRIPTOR( modname );

	static DYNAMIC_DESCRIPTOR( wild );

	struct descriptor pattern;

	// get user data
	cli_get_value( &modname_p, &wild );
	StrUpcase( &wild, &wild );

	physical_name = cli_present(&physical) & 1;

	if( MSGLVL(DETAILS) )
		printf("Deassign(): %s module: <%s>\n", physical_name ? "physical" : "logical", wild.pointer);

	// check to see if db file memory mapped
	if( CTSdbFileIsMapped == FALSE ) {				// is not, so try ...
		if( map_data_file(CTS_DB) != SUCCESS ) {	// we're dead in the water
			status = MAP_ERROR;						// [2002.02.21]
			goto Deassign_Exit;
		}
	}

	// get number of current entries
	if( (numOfEntries = get_file_count(CTS_DB)) == 0 ) {	// no entries in cts db file
		if( MSGLVL(IMPORTANT) )
			fprintf( stderr, "db file empty, no entries to remove\n" );

		status = DEASSIGN_ERROR;					// [2002.02.21]
		goto Deassign_Exit;
	}

	// if we get this far, then there are modules in the database
	modulesToDeassign = modulesDeassigned = 0;	// initialize counts
	pMod = &Mod;				// point to some actual storage

	// first, we need to count the number to deassign ...
	for( i = 0; i < numOfEntries; ++i ) {	// scan entire list
		// look up module name(s). NB! more than one logical name may be
		// assigned to the same, unique physical name.
		parse_cts_db( CTSdb+i, pMod );		// extract info from db

		memset(db_tmp, ' ', 32);	// clear out buffer
		db_tmp[33] = '\0';			// ensure buffer 'ends'

		if( physical_name ) 		// physical name
			sprintf( db_tmp, "GK%c%d%02d:N%d",
				pMod->adapter + 'A', 
				pMod->id, 
				pMod->crate,
				pMod->slot
				);
		else 						// logical name 
			sprintf( db_tmp, "%s", pMod->name );

		// prepare for 'wild' match
		pattern.pointer = db_tmp;
		pattern.length  = strlen(db_tmp);

		if( StrMatchWild( &pattern, &wild ) & 1 ) {
			++modulesToDeassign;	//
		}
	} // end of for() loop, all entries checked

	// now actually remove them
	while( modulesToDeassign ) {
		for( i = 0; i < get_file_count(CTS_DB); ++i ) {
			// look up module name(s). NB! more than one logical name may be
			// assigned to the same, unique physical name.
			parse_cts_db( CTSdb+i, pMod );		// extract info from db

			memset(db_tmp, ' ', 32);	// clear out buffer
			db_tmp[33] = '\0';			// ensure buffer 'ends'

			if( physical_name ) 		// physical name
				sprintf( db_tmp, "GK%c%d%02d:N%d",
					pMod->adapter + 'A', 
					pMod->id, 
					pMod->crate,
					pMod->slot
					);
			else 						// logical name 
				sprintf( db_tmp, "%s", pMod->name );

			// prepare for 'wild' match
			pattern.pointer = db_tmp;
			pattern.length  = strlen(db_tmp);

			if( StrMatchWild( &pattern, &wild ) & 1 ) {
				if( remove_entry(CTS_DB, i) != SUCCESS ) {	// removal failed
					status = DEASSIGN_ERROR;				// [2002.02.21]
					goto Deassign_Exit;
				}
				else 
					++modulesDeassigned;	// keep track of successes :)
			}
		}

		--modulesToDeassign;				// one less to remove ...
	}

Deassign_Exit:
	if( MSGLVL(DETAILS) ) {
		printf("Deassign(%d): ", modulesDeassigned); ShowStatus(status);
	}

	return status;
}  
示例#6
0
char *_TreeFindTagWild(void *dbid, char *wild, int *nidout, void **ctx_inout)
{
    PINO_DATABASE *dblist = (PINO_DATABASE *)dbid;
    /***************************
      check that there is a tree
      open.
     ****************************/
    if (!IS_OPEN(dblist))
        return NULL;
    if (dblist->remote)
        return FindTagWildRemote(dblist,wild,nidout,ctx_inout);
    else
    {
        NID *nid_ptr = (NID *)nidout;
        TAG_SEARCH **ctx = (TAG_SEARCH **)ctx_inout;
        int       status = 1;
        unsigned char found,done;
        static char answer[128];

        /**********************************
        If this is the first time then
        allocate a context block and fill
        it in with a parse of the tagname.
        ***********************************/
        if (*ctx == (TAG_SEARCH *) 0)
        {
            *ctx = NewTagSearch(wild);
            if (*ctx == (TAG_SEARCH *) 0)
                status = TreeNMT;
            else
                status = NextTagTree(dblist, *ctx);
        }

        /*************************************
         Loop looking for a tag that matches
        **************************************/
        for (found = 0, done = 0; (status & 1) && !found && !done;)
        {

            /*************************************
              if out of tags in this tree then
              see if there is another one
            **************************************/
            if ((*ctx)->next_tag >= (*ctx)->this_tree_info->header->tags)
            {
                status = NextTagTree(dblist, *ctx);
                if (status & 1)
                    (*ctx)->next_tag = -1;
                else
                {
                    done = 1;
                    break;
                }
            }
            else
            {

                /**********************************************
                  else if this is the first time for this tree
                try to return the \TOP tag.
                otherwise - move on to next tag for next
                time through the loop.
                ***********************************************/
                if ((*ctx)->next_tag == -1)
                {
                    if ((*ctx)->top_match)
                    {
                        done = 1;
                        found = 1;
                    }
                    else
                        ((*ctx)->next_tag)++;
                }
                else
                {

                    /****************************************
                    Else
                       loop looking for a tag that matches
                        *****************************************/
                    for (; !done && ((*ctx)->next_tag < (*ctx)->this_tree_info->header->tags);)
                    {
                        unsigned short len;
                        static struct descriptor_s s_tag_dsc = { sizeof(TAG_NAME), DTYPE_T, CLASS_S, 0};
                        static struct descriptor_d tag_dsc = {0, DTYPE_T, CLASS_D, 0};
                        s_tag_dsc.pointer =
                            (char *) (*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].name;
                        StrTrim(&tag_dsc, &s_tag_dsc,&len);
                        if (StrMatchWild(&tag_dsc, &((*ctx)->search_tag)) & 1)
                        {
                            done = 1;
                            found = 1;
                        }
                        else
                            ((*ctx)->next_tag)++;
                    }
                }
            }
        }
        /********************************************
          If done and found then fill in the answer
        *********************************************/
        if (found)
        {
            NODE     *nptr = (*ctx)->this_tree_info->node;
            static char tagname[sizeof(TAG_NAME)+1];
            if ((*ctx)->next_tag != -1)
            {
                static struct descriptor_s s_tag_name = {sizeof(TAG_NAME), DTYPE_T, CLASS_S, 0};
                static struct descriptor_s tag_name =  {sizeof(TAG_NAME), DTYPE_T, CLASS_S, tagname};
                unsigned short len;
                s_tag_name.pointer =
                    (char *) (*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].name;
                StrTrim(&tag_name, &s_tag_name,&len);
                tagname[len]='\0';
                nptr += swapint(&(*ctx)->this_tree_info->tag_info[swapint((char *)&(*ctx)->this_tree_info->tags[(*ctx)->next_tag])].node_idx);
            }
            else
                strcpy(tagname,"TOP");
            strcpy(answer,"\\");
            strcat(answer,(*ctx)->this_tree_info->treenam);
            strcat(answer,"::");
            strcat(answer,tagname);
            if (nid_ptr)
                node_to_nid(dblist, nptr, nid_ptr);
            ((*ctx)->next_tag)++;
            status = 1;
        }
        else
        {
            TreeFindTagEnd(ctx_inout);
            status = TreeNMT;
        }
        return (status & 1) ? answer : NULL;
    }
}