예제 #1
0
static char *getOidString(SmiNode *smiNode, int importedParent)
{
    SmiNode	 *parentNode;
    SmiModule	 *smiModule;
    static char	 s[200];
    char	 append[200];
    unsigned int i;
    
    append[0] = 0;

    parentNode = smiNode;
    smiModule = smiGetNodeModule(smiNode);
    
    do {

	if (parentNode->oidlen <= 1) {
	    break;
	}
	
	/* prepend the cut-off subidentifier to `append'. */
	strcpy(s, append);
	sprintf(append, ".%u%s", parentNode->oid[parentNode->oidlen-1], s);

	/* retrieve the parent SmiNode */
	parentNode = smiGetParentNode(parentNode);

	if (!parentNode) {
	    sprintf(s, "%s", append);
	    return s;
	}

	/* found an imported or a local parent node? */
	if ((parentNode->name && strlen(parentNode->name)) &&
	    (smiIsImported(smiModule, NULL, parentNode->name) ||
	     (!importedParent &&
	      (smiGetNodeModule(parentNode) == smiModule)) ||
	     (parentNode->oidlen == 1))) {
	    sprintf(s, "%s%s", parentNode->name, append);
	    return s;
	}
	
    } while (parentNode);

    s[0] = 0;
    for (i=0; i < smiNode->oidlen; i++) {
	if (i) strcat(s, ".");
	sprintf(&s[strlen(s)], "%u", smiNode->oid[i]);
    }
    return s;
}
예제 #2
0
파일: dump-xml.c 프로젝트: pan0007/libsmi
static void fprintRefinement(FILE *f, int indent, SmiRefinement *smiRefinement)
{
    SmiModule *smiModule;
    SmiNode   *smiNode;
    SmiType   *smiType;

    smiNode = smiGetRefinementNode(smiRefinement);
    smiModule = smiGetNodeModule(smiNode);

    fprintSegment(f, indent, "<refinement ", 0);
    fprintf(f, "module=\"%s\" name=\"%s\">\n", smiModule->name, smiNode->name);

    smiType = smiGetRefinementType(smiRefinement);
    if (smiType) {
	fprintSegment(f, indent + INDENT, "<syntax>\n", 0);
	fprintTypedef(f, indent + 2 * INDENT, smiType);
	fprintSegment(f, indent + INDENT, "</syntax>\n", 0);
    }
    
    smiType = smiGetRefinementWriteType(smiRefinement);
    if (smiType) {
	fprintSegment(f, indent + INDENT, "<writesyntax>\n", 0);
	fprintTypedef(f, indent + 2 * INDENT, smiType);
	fprintSegment(f, indent + INDENT, "</writesyntax>\n", 0);
    }

    if (smiRefinement->access != SMI_ACCESS_UNKNOWN) {
	fprintAccess(f, indent + INDENT, smiRefinement->access);
    }
    fprintDescription(f, indent + INDENT, smiRefinement->description);
    fprintSegment(f, indent, "</refinement>\n", 0);
}
예제 #3
0
파일: dump-xml.c 프로젝트: pan0007/libsmi
static void fprintComplGroups(FILE *f, int indent, SmiNode *smiNode)
{
    SmiNode   *optSmiNode;
    SmiModule *optSmiModule;
    SmiOption *smiOption;

    if (! smiGetFirstElement(smiNode) && !smiGetFirstOption(smiNode)) {
	return;
    }
    
    fprintSegment(f, indent, "<requires>\n", 0);
    fprintElementList(f, indent + INDENT, "mandatory",
		      smiGetFirstElement(smiNode));

    for(smiOption = smiGetFirstOption(smiNode);
	smiOption;
	smiOption = smiGetNextOption(smiOption)) {
	optSmiNode = smiGetOptionNode(smiOption);
	optSmiModule = smiGetNodeModule(optSmiNode);
	fprintSegment(f, indent + INDENT, "", 0);
	fprint(f, "<option module=\"%s\" name=\"%s\">\n",
	       optSmiModule->name, optSmiNode->name);
	fprintDescription(f, indent + 2 * INDENT, smiOption->description);
	fprintSegment(f, indent + INDENT, "</option>\n", 0);
    }
    
    fprintSegment(f, indent, "</requires>\n", 0);
}
예제 #4
0
파일: dump-xml.c 프로젝트: pan0007/libsmi
static void fprintIndex(FILE *f, int indent, SmiNode *smiNode)
{
    SmiNode   *relatedNode;
    SmiModule *relatedModule = NULL;

    fprintSegment(f, indent, "<linkage", 0);
    if (smiNode->implied) {
	fprint(f, " implied=\"true\"");
    }
    fprint(f, ">\n");

    relatedNode = smiGetRelatedNode(smiNode);
    if (relatedNode) {
	relatedModule = smiGetNodeModule(relatedNode);
    }
    switch (smiNode->indexkind) {
    case SMI_INDEX_INDEX:
	fprintElementList(f, indent + INDENT, "index",
			  smiGetFirstElement(smiNode));
	break;
    case SMI_INDEX_AUGMENT:
	if (relatedNode && relatedModule) {
	    fprintSegment(f, indent + INDENT, "", 0);
	    fprint(f, "<augments module=\"%s\" name=\"%s\"/>\n",
		   relatedModule->name, relatedNode->name);
	} /* TODO: else print error */
	break;
    case SMI_INDEX_REORDER:
	if (relatedNode && relatedModule) {
	    fprintSegment(f, indent + INDENT, "", 0);
	    fprint(f, "<reorders module=\"%s\" name=\"%s\"/>\n",
		   relatedModule->name, relatedNode->name);
	    fprintElementList(f, indent + INDENT, "index",
			      smiGetFirstElement(smiNode));
	} /* TODO: else print error */
	break;
    case SMI_INDEX_SPARSE:
	if (relatedNode && relatedModule) {
	    fprintSegment(f, indent + INDENT, "", 0);
	    fprint(f, "<sparse module=\"%s\" name=\"%s\"/>\n",
		   relatedModule->name, relatedNode->name);
	} /* TODO: else print error */
	break;
    case SMI_INDEX_EXPAND:
	if (relatedNode && relatedModule) {
	    fprintSegment(f, indent + INDENT, "", 0);
	    fprint(f, "<expands module=\"%s\" name=\"%s\"/>\n",
		   relatedModule->name, relatedNode->name);
	    fprintElementList(f, indent + INDENT, "index",
			      smiGetFirstElement(smiNode));
	} /* TODO: else print error */
	break;
    case SMI_INDEX_UNKNOWN:
	break;
    }
    fprintSegment(f, indent, "</linkage>\n", 0);
}
static void
incrTypeAndNodeUsageCounter(SmiModule *smiModule, SmiNode *smiNode, int flags)
{
    SmiType *smiType;
    char *extModule;

    /*
     * First check whether the node is external. If yes, increment the
     * external node counter and we are done.
     */

    extModule = smiGetNodeModule(smiNode)->name;
    if (extModule
	&& strcmp(extModule, smiModule->name) != 0) {
	if (flags & INCR_NODE) {
	    extNodeList = incrUsageCounter(extNodeList,
					   extModule, smiNode->name, 1);
	    extModuleList = incrUsageCounter(extModuleList, extModule, NULL, 1);
	}
	return;
    }
    
    /*
     * Next, check whether the type of the node is external. If yes,
     * increment the external type counter and we are done. Do not
     * count base types (that is types that have no parent type).
     */

    smiType = smiGetNodeType(smiNode);
    if (! smiType) {
	return;
    }

    if (smiType->name && smiGetParentType(smiType)) {
	char *extModule = smiGetTypeModule(smiType)->name;
	if (extModule /* && *extModule */
	    && strcmp(extModule, smiModule->name) != 0) {
	    if (flags & INCR_TYPE) {
		extTypeList = incrUsageCounter(extTypeList,
					       extModule, smiType->name, 1);
		extModuleList = incrUsageCounter(extModuleList, extModule, NULL, 1);
	    }
	}
    }

    /*
     * Finally, count the type name (whether external or not does not
     * matter here nor does it matter whether it is a base type or
     * not).
     */

    if (! smiType->name && smiGetParentType(smiType)) {
	smiType = smiGetParentType(smiType);
    }
    typeList = incrUsageCounter(typeList, smiGetTypeModule(smiType)->name,
				smiType->name, 1);
}
예제 #6
0
파일: dump-xml.c 프로젝트: pan0007/libsmi
static void fprintElementList(FILE *f, int indent, const char *tag,
			      SmiElement *smiElement)
{
    SmiModule *smiModule;
    SmiNode   *smiNode;

    for (; smiElement; smiElement = smiGetNextElement(smiElement)) {
	smiNode = smiGetElementNode(smiElement);
	smiModule = smiGetNodeModule(smiNode);
	fprintSegment(f, indent, "", 0);
	fprint(f, "<%s module=\"%s\" name=\"%s\"/>\n",
	       tag, smiModule->name, smiNode->name);
    }
}
예제 #7
0
int MibViewLoader::IsPartOfLoadedModules(SmiNode *smiNode)
{
    SmiModule *smiModule;
    int i;
    
    smiModule = smiGetNodeModule(smiNode);
    
    for (i = 0; i < pmodc; i++) {
        if (strcmp(pmodv[i]->name, smiModule->name) == 0) {
            return 1;
        }
    }
    return 0;
}
예제 #8
0
파일: dump-cm.c 프로젝트: pan0007/libsmi
/*
 * prints all columns objects of the given node
 */
static void diaPrintXMLAllColumns(GraphNode *node)
{
    SmiModule *module  = NULL;
    SmiNode   *smiNode = NULL;
    SmiNode   *ppNode;

    module  = smiGetNodeModule(node->smiNode);

    for (smiNode = smiGetFirstNode(module, SMI_NODEKIND_COLUMN);
	 smiNode;
	 smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_COLUMN)) {
	ppNode = smiGetParentNode(smiNode);
	ppNode = smiGetParentNode(ppNode);
	
	if (!algIsIndexElement(node->smiNode, smiNode) &&
	    cmpSmiNodes(node->smiNode, ppNode))
	    diaPrintXMLAttribute(smiNode, 0);
    }
}
예제 #9
0
int MibViewLoader::PruneSubTree(SmiNode *smiNode)
{
    SmiNode   *childNode;
    
    const int confmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE);
    const int leafmask = (SMI_NODEKIND_GROUP | SMI_NODEKIND_COMPLIANCE
                          | SMI_NODEKIND_COLUMN | SMI_NODEKIND_SCALAR
                          | SMI_NODEKIND_ROW | SMI_NODEKIND_NOTIFICATION);
    
    if (! smiNode) {
        return 1;
    }
    
    /*
     * First, prune all nodes which the user has told us to ignore.
     * In the case of ignoreleafs, we have to special case nodes with
     * an unknown status (which actually represent OBJECT-IDENTITY
     * definitions). More special case code is needed to exclude
     * module identity nodes.
     */
    
    if (ignoreconformance && (smiNode->nodekind & confmask)) {
        return 1;
    }
    
    if (ignoreleafs) {
        if (smiNode->nodekind & leafmask) {
            return 1;
        }
        if (smiNode->nodekind == SMI_NODEKIND_NODE
            && smiNode->status != SMI_STATUS_UNKNOWN) {
            SmiModule *smiModule = smiGetNodeModule(smiNode);
            if (smiModule && smiNode != smiGetModuleIdentityNode(smiModule)) {
                return 1;
            }
        }
    }
    
    /*
      * Next, generally do not prune nodes that belong to the set of
      * modules we are looking at.
      */
    
    if (IsPartOfLoadedModules(smiNode)) {
        if (!ignoreconformance || !smiGetFirstChildNode(smiNode)) {
            return 0;
        }
    }
    
    /*
     * Finally, prune all nodes where all child nodes are pruned.
     */
    
    for (childNode = smiGetFirstChildNode(smiNode);
    childNode;
    childNode = smiGetNextChildNode(childNode)) {
        
        /*
         * In the case of ignoreleafs, we have to peek at the child
         * nodes. Otherwise, we would prune too much. we still want to
         * see the path to the leafs we have pruned away. This also
         * interact with the semantics of ignoreconformance since we
         * still want in combination with ignoreleafs to see the path
         * to the pruned conformance leafs.
         */
        
        if (ignoreleafs && (childNode->nodekind & leafmask)) {
            if (IsPartOfLoadedModules(childNode)) {
                if (ignoreconformance && (childNode->nodekind & confmask)) {
                    return 1;
                }
                return 0;
            }
        }
        
        if (! PruneSubTree(childNode)) {
            return 0;
        }
    }
    
    return 1;
}
예제 #10
0
static void fprintGroup(FILE *f, SmiNode *smiNode, char c,
			int *typelen, int *namelen, int pass)
{
    SmiElement *smiElement;
    SmiNode *smiObject;
    SmiModule *smiModule;
    char *type_name;
    int tlen = 9, nlen = 9;

    switch (smiNode->nodekind) {
    case SMI_NODEKIND_GROUP:
	for (smiElement = smiGetFirstElement(smiNode);
	     smiElement;
	     smiElement = smiGetNextElement(smiElement)) {
	    smiObject = smiGetElementNode(smiElement);
	    smiModule = smiGetNodeModule(smiNode);
	    type_name = getTypeName(smiObject);
	    if (pass == 1) {
		if (type_name) {
		    int newlen = strlen(type_name);
		    tlen = (tlen < newlen) ? newlen : tlen;
		}
		if (smiObject->name) {
		    int newlen = strlen(smiObject->name);
		    nlen = (nlen < newlen) ? newlen : nlen;
		}
	    } else if (pass == 2) {
		fprintf(f, "  %c%c%s %-*s %-*s (%s)\n",
			getStatusChar(smiObject->status), c,
			getFlags(smiObject),
			*typelen, type_name ? type_name : "-",
			*namelen, smiObject->name, smiNode->name);
	    }
	    xfree(type_name);
	}
	break;
    case SMI_NODEKIND_SCALAR:
    case SMI_NODEKIND_COLUMN:
	smiObject = smiNode;
	type_name = getTypeName(smiObject);
	if (pass == 1) {
	    if (type_name) {
		int newlen = strlen(type_name);
		tlen = tlen < newlen ? newlen : tlen;
	    }
	    if (smiObject->name) {
		int newlen = strlen(smiObject->name);
		nlen = (nlen < newlen) ? newlen : nlen;
	    }
	} else if (pass == 2) {
	    fprintf(f, "  %c%c%s %-*s %s\n",
		    getStatusChar(smiObject->status), 'r',
		    getFlags(smiObject),
		    *typelen, type_name ? type_name : "-",
		    smiObject->name);
	}
	xfree(type_name);
	break;
    default:
	break;
    }

    if (pass == 1) {
	if (typelen) *typelen = tlen;
	if (namelen) *namelen = nlen;
    }
}
예제 #11
0
파일: dump-cm.c 프로젝트: pan0007/libsmi
/*
 * diaCalcSize
 *
 * Calculates the size of a given node for the UML representation.
 */
static GraphNode *diaCalcSize(GraphNode *node)
{
    GraphEdge  *tEdge;
    SmiNode    *tNode,*ppNode;
    SmiElement *smiElement;
    SmiModule  *module;

    if (node->smiNode->nodekind == SMI_NODEKIND_SCALAR) return node;
    
    node->dia.w = (strlen(node->smiNode->name)+4) * HEADFONTSIZETABLE
	+ HEADSPACESIZETABLE;
    
    node->dia.h = TABLEHEIGHT;
    for (smiElement = smiGetFirstElement(
	smiGetFirstChildNode(node->smiNode));
	 smiElement;
	 smiElement = smiGetNextElement(smiElement)) {
	
	tNode = smiGetElementNode(smiElement);
	
	node->dia.w = max(node->dia.w, (strlen(tNode->name) +
					strlen(algGetTypeName(tNode)) +
					strlen(INDEXPROPERTY))
		      * ATTRFONTSIZE
		      + ATTRSPACESIZE);
	node->dia.h += TABLEELEMHEIGHT;
    }
    
    for (tEdge = graphGetFirstEdgeByNode(graph,node);
	 tEdge;
	 tEdge = graphGetNextEdgeByNode(graph, tEdge, node)) {
	if (tEdge->startNode == node &&
	    tEdge->endNode->smiNode->nodekind == SMI_NODEKIND_SCALAR) {
	    node->dia.h += TABLEELEMHEIGHT;
	    tNode = tEdge->endNode->smiNode;
	    
	    node->dia.w = max(node->dia.w, (strlen(tNode->name) +
				    strlen(algGetTypeName(tNode)))
			  * ATTRFONTSIZE
			  + ATTRSPACESIZE);		
	}
    }

    if (PRINT_DETAILED_ATTR && node->smiNode->nodekind == SMI_NODEKIND_TABLE) {
	module  = smiGetNodeModule(node->smiNode);

	for (tNode = smiGetFirstNode(module, SMI_NODEKIND_COLUMN);
	     tNode;
	     tNode = smiGetNextNode(tNode, SMI_NODEKIND_COLUMN)) {
	    ppNode = smiGetParentNode(tNode);
	    ppNode = smiGetParentNode(ppNode);

	    if (cmpSmiNodes(node->smiNode, ppNode)) {
		int len;
		char *typeName;

		typeName = algGetTypeName(tNode);
		len = strlen(tNode->name) + (typeName ? strlen(typeName) : 0);
		node->dia.h += TABLEELEMHEIGHT;
		node->dia.w = max(node->dia.w, len)
		    * ATTRFONTSIZE
		    + ATTRSPACESIZE;
	    }
	}
    }
    
    return node;
}