install-ds.c
来自「支持SSL v2/v3, TLS, PKCS #5, PKCS #7, PKCS」· C语言 代码 · 共 1,542 行 · 第 1/3 页
C
1,542 行
}/*//////////////////////////////////////////////////////////////////////////// Method: ~Pk11Install_Info// Class: Pk11Install_Info*/voidPk11Install_Info_delete(Pk11Install_Info* _this){ Pk11Install_Info_Cleanup(_this);}/*//////////////////////////////////////////////////////////////////////////// Method: Cleanup// Class: Pk11Install_Info*/voidPk11Install_Info_Cleanup(Pk11Install_Info* _this){ int i; if(_this->platforms) { for (i=0;i<_this->numPlatforms;i++) { Pk11Install_Platform_delete(&_this->platforms[i]); } PR_Free(&_this->platforms); _this->platforms = NULL; _this->numPlatforms = 0; } if(_this->forwardCompatible) { for (i=0;i<_this->numForwardCompatible;i++) { Pk11Install_PlatformName_delete(&_this->forwardCompatible[i]); } PR_Free(&_this->forwardCompatible); _this->numForwardCompatible = 0; }}/*//////////////////////////////////////////////////////////////////////////// Method: Generate// Class: Pk11Install_Info// Takes: Pk11Install_ValueList *list, the top-level list// resulting from parsing an installer file.// Returns: char*, NULL if successful, otherwise an error string.// Caller is responsible for freeing memory.*/char*Pk11Install_Info_Generate(Pk11Install_Info* _this, const Pk11Install_ValueList *list){ char *errStr; Pk11Install_ListIter *iter; Pk11Install_Value *val; Pk11Install_Pair *pair; Pk11Install_ListIter *subiter; Pk11Install_Value *subval; Pk11Install_Platform *first, *second; int i, j; errStr=NULL; iter=subiter=NULL; Pk11Install_Info_Cleanup(_this); iter = Pk11Install_ListIter_new(list); for( ; (val=iter->current); Pk11Install_ListIter_nextItem(iter)) { if(val->type == PAIR_VALUE) { pair = val->pair; if(!PORT_Strcasecmp(pair->key, FORWARD_COMPATIBLE_STRING)) { subiter = Pk11Install_ListIter_new(pair->list); _this->numForwardCompatible = pair->list->numStrings; _this->forwardCompatible = (Pk11Install_PlatformName*) PR_Malloc(sizeof(Pk11Install_PlatformName)* _this->numForwardCompatible); for(i=0; i < _this->numForwardCompatible; i++, Pk11Install_ListIter_nextItem(subiter)) { subval = subiter->current; if(subval->type == STRING_VALUE) { errStr = Pk11Install_PlatformName_Generate( &_this->forwardCompatible[i], subval->string); if(errStr) { goto loser; } } } Pk11Install_ListIter_delete(subiter); PR_Free(subiter); subiter = NULL; } else if(!PORT_Strcasecmp(pair->key, PLATFORMS_STRING)) { subiter = Pk11Install_ListIter_new(pair->list); _this->numPlatforms = pair->list->numPairs; _this->platforms = (Pk11Install_Platform*) PR_Malloc(sizeof(Pk11Install_Platform)* _this->numPlatforms); for(i=0; i < _this->numPlatforms; i++, Pk11Install_ListIter_nextItem(subiter)) { Pk11Install_Platform_init(&_this->platforms[i]); subval = subiter->current; if(subval->type == PAIR_VALUE) { errStr = Pk11Install_Platform_Generate(&_this->platforms[i],subval->pair); if(errStr) { goto loser; } } } Pk11Install_ListIter_delete(subiter); PR_Free(subiter); subiter = NULL; } } } if(_this->numPlatforms == 0) { errStr = PR_smprintf(errString[NO_PLATFORMS]); goto loser; }/* // // Now process equivalent platforms // // First the naive pass*/ for(i=0; i < _this->numPlatforms; i++) { if(_this->platforms[i].usesEquiv) { _this->platforms[i].equiv = NULL; for(j=0; j < _this->numPlatforms; j++) { if (Pk11Install_PlatformName_equal(&_this->platforms[i].equivName, &_this->platforms[j].name)) { if(i==j) { errStr = PR_smprintf(errString[EQUIV_LOOP], Pk11Install_PlatformName_GetString(&_this->platforms[i].name)); goto loser; } _this->platforms[i].equiv = &_this->platforms[j]; break; } } if(_this->platforms[i].equiv == NULL) { errStr = PR_smprintf(errString[BOGUS_EQUIV], Pk11Install_PlatformName_GetString(&_this->platforms[i].name)); goto loser; } } }/* // Now the intelligent pass, which will also detect loops. // We will send two pointers through the linked list of equivalent // platforms. Both start with the current node. "first" traverses // two nodes for each iteration. "second" lags behind, only traversing // one node per iteration. Eventually one of two things will happen: // first will hit the end of the list (a platform that doesn't use // an equivalency), or first will equal second if there is a loop.*/ for(i=0; i < _this->numPlatforms; i++) { if(_this->platforms[i].usesEquiv) { second = _this->platforms[i].equiv; if(!second->usesEquiv) { /* The first link is the terminal node */ continue; } first = second->equiv; while(first->usesEquiv) { if(first == second) { errStr = PR_smprintf(errString[EQUIV_LOOP], Pk11Install_PlatformName_GetString(&_this->platforms[i].name)); goto loser; } first = first->equiv; if(!first->usesEquiv) { break; } if(first == second) { errStr = PR_smprintf(errString[EQUIV_LOOP], Pk11Install_PlatformName_GetString(&_this->platforms[i].name)); goto loser; } second = second->equiv; first = first->equiv; } _this->platforms[i].equiv = first; } }loser: if(iter) { Pk11Install_ListIter_delete(iter); PR_Free(iter); iter = NULL; } if(subiter) { Pk11Install_ListIter_delete(subiter); PR_Free(subiter); subiter = NULL; } return errStr;}/*//////////////////////////////////////////////////////////////////////////// Method: GetBestPlatform// Class: Pk11Install_Info// Takes: char *myPlatform, the platform we are currently running// on.*/Pk11Install_Platform*Pk11Install_Info_GetBestPlatform(Pk11Install_Info* _this, char *myPlatform){ Pk11Install_PlatformName plat; char *errStr; int i, j; errStr=NULL; Pk11Install_PlatformName_init(&plat); if( (errStr=Pk11Install_PlatformName_Generate(&plat, myPlatform)) ) { PR_smprintf_free(errStr); return NULL; } /* First try real platforms */ for(i=0; i < _this->numPlatforms; i++) { if(Pk11Install_PlatformName_equal(&_this->platforms[i].name,&plat)) { if(_this->platforms[i].equiv) { return _this->platforms[i].equiv; } else { return &_this->platforms[i]; } } } /* Now try forward compatible platforms */ for(i=0; i < _this->numForwardCompatible; i++) { if(Pk11Install_PlatformName_lteq(&_this->forwardCompatible[i],&plat)) { break; } } if(i == _this->numForwardCompatible) { return NULL; } /* Got a forward compatible name, find the actual platform. */ for(j=0; j < _this->numPlatforms; j++) { if(Pk11Install_PlatformName_equal(&_this->platforms[j].name, &_this->forwardCompatible[i])) { if(_this->platforms[j].equiv) { return _this->platforms[j].equiv; } else { return &_this->platforms[j]; } } } return NULL;}/*//////////////////////////////////////////////////////////////////////////// Method: Print// Class: Pk11Install_Info*/voidPk11Install_Info_Print(Pk11Install_Info* _this, int pad){ int i; PAD(pad); printf("Forward Compatible:\n"); for(i = 0; i < _this->numForwardCompatible; i++) { Pk11Install_PlatformName_Print(&_this->forwardCompatible[i],pad+PADINC); PAD(pad); printf("-------------------\n"); } PAD(pad); printf("Platforms:\n"); for( i = 0; i < _this->numPlatforms; i++) { Pk11Install_Platform_Print(&_this->platforms[i],pad+PADINC); PAD(pad); printf("-------------------\n"); }}/*//////////////////////////////////////////////////////////////////////////*/static char*PR_Strdup(const char* str){ char *tmp; tmp = (char*) PR_Malloc((unsigned int)(strlen(str)+1)); strcpy(tmp, str); return tmp;}/* The global value list, the top of the tree */Pk11Install_ValueList* Pk11Install_valueList=NULL;/****************************************************************************/voidPk11Install_ValueList_AddItem(Pk11Install_ValueList* _this, Pk11Install_Value *item){ _this->numItems++; if (item->type == STRING_VALUE) { _this->numStrings++; } else { _this->numPairs++; } item->next = _this->head; _this->head = item;}/****************************************************************************/Pk11Install_ListIter*Pk11Install_ListIter_new_default(){ Pk11Install_ListIter* new_this; new_this = (Pk11Install_ListIter*) PR_Malloc(sizeof(Pk11Install_ListIter)); Pk11Install_ListIter_init(new_this); return new_this;}/****************************************************************************/voidPk11Install_ListIter_init(Pk11Install_ListIter* _this){ _this->list = NULL; _this->current = NULL;}/****************************************************************************/Pk11Install_ListIter*Pk11Install_ListIter_new(const Pk11Install_ValueList *_list){ Pk11Install_ListIter* new_this; new_this = (Pk11Install_ListIter*) PR_Malloc(sizeof(Pk11Install_ListIter)); new_this->list = _list; new_this->current = _list->head; return new_this;}/****************************************************************************/voidPk11Install_ListIter_delete(Pk11Install_ListIter* _this){ _this->list=NULL; _this->current=NULL;}/****************************************************************************/voidPk11Install_ListIter_reset(Pk11Install_ListIter* _this){ if(_this->list) { _this->current = _this->list->head; }}/*************************************************************************/Pk11Install_Value*Pk11Install_ListIter_nextItem(Pk11Install_ListIter* _this){ if(_this->current) { _this->current = _this->current->next; } return _this->current;}/****************************************************************************/Pk11Install_ValueList*Pk11Install_ValueList_new(){ Pk11Install_ValueList* new_this; new_this = (Pk11Install_ValueList*) PR_Malloc(sizeof(Pk11Install_ValueList)); new_this->numItems = 0; new_this->numPairs = 0; new_this->numStrings = 0; new_this->head = NULL; return new_this;}/****************************************************************************/voidPk11Install_ValueList_delete(Pk11Install_ValueList* _this){ Pk11Install_Value *tmp; Pk11Install_Value *list; list = _this->head; while(list != NULL) { tmp = list; list = list->next; PR_Free(tmp); } PR_Free(_this);}/****************************************************************************/Pk11Install_Value*Pk11Install_Value_new_default(){ Pk11Install_Value* new_this; new_this = (Pk11Install_Value*)PR_Malloc(sizeof(Pk11Install_Value)); new_this->type = STRING_VALUE; new_this->string = NULL; new_this->pair = NULL; new_this->next = NULL; return new_this;}/****************************************************************************/Pk11Install_Value*Pk11Install_Value_new(ValueType _type, Pk11Install_Pointer ptr){ Pk11Install_Value* new_this; new_this = Pk11Install_Value_new_default(); new_this->type = _type; if(_type == STRING_VALUE) { new_this->pair = NULL; new_this->string = ptr.string; } else { new_this->string = NULL; new_this->pair = ptr.pair; } return new_this;}/****************************************************************************/voidPk11Install_Value_delete(Pk11Install_Value* _this){ if(_this->type == STRING_VALUE) { PR_Free(_this->string); } else { PR_Free(_this->pair); }}/****************************************************************************/Pk11Install_Pair*Pk11Install_Pair_new_default(){ return Pk11Install_Pair_new(NULL,NULL);}/****************************************************************************/Pk11Install_Pair*Pk11Install_Pair_new(char *_key, Pk11Install_ValueList *_list){ Pk11Install_Pair* new_this; new_this = (Pk11Install_Pair*)PR_Malloc(sizeof(Pk11Install_Pair)); new_this->key = _key; new_this->list = _list; return new_this;}/****************************************************************************/voidPk11Install_Pair_delete(Pk11Install_Pair* _this){ PR_Free(_this->key); Pk11Install_ValueList_delete(_this->list); PR_Free(_this->list);}/*************************************************************************/voidPk11Install_Pair_Print(Pk11Install_Pair* _this, int pad){ while (_this) { /*PAD(pad); printf("**Pair\n"); PAD(pad); printf("***Key====\n");*/ PAD(pad); printf("%s {\n", _this->key); /*PAD(pad); printf("====\n");*/ /*PAD(pad); printf("***ValueList\n");*/ Pk11Install_ValueList_Print(_this->list,pad+PADINC); PAD(pad); printf("}\n"); }}/*************************************************************************/voidPk11Install_ValueList_Print(Pk11Install_ValueList* _this, int pad){ Pk11Install_Value *v; /*PAD(pad);printf("**Value List**\n");*/ for(v = _this->head; v != NULL; v=v->next) { Pk11Install_Value_Print(v,pad); }}/*************************************************************************/voidPk11Install_Value_Print(Pk11Install_Value* _this, int pad){ /*PAD(pad); printf("**Value, type=%s\n", type==STRING_VALUE ? "string" : "pair");*/ if(_this->type==STRING_VALUE) { /*PAD(pad+PADINC); printf("====\n");*/ PAD(pad); printf("%s\n", _this->string); /*PAD(pad+PADINC); printf("====\n");*/ } else { Pk11Install_Pair_Print(_this->pair,pad+PADINC); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?