Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00032 #include <stdio.h>
00033 #include <stdlib.h>
00034 #include <string.h>
00035
00036 #include <eurephia_nullsafe.h>
00037 #include <certinfo.h>
00038
00047 #define comp_attrib(s, v) ( (v == NULL || strlen_nullsafe(v) < 1) ? 0 : (strcmp(v, s) == 0) )
00048
00056 certinfo *parse_tlsid(const char *input) {
00057 char tmp[130], *mainp, *origptr, *sub, *tok, *tok2;
00058 certinfo *ret = NULL;
00059
00060 if( (input == NULL) || strlen(input) < 5)
00061 return NULL;
00062
00063 ret = (certinfo *) malloc_nullsafe(NULL, sizeof(certinfo)+2);
00064 memset(&tmp, 0, 130);
00065
00066 mainp = strdup(input);
00067 origptr = mainp;
00068 tok = strsep(&mainp, "/\0");
00069 while( tok != NULL ) {
00070 if( (tok != NULL) && (strlen(tok) > 0 ) ) {
00071 sub = strdup(tok);
00072 tok2 = strsep(&sub, "=\0");
00073
00074 if( comp_attrib("O\0", tok2) ) {
00075 ret->org = strdup(strsep(&sub, "=\0"));
00076 } else if( comp_attrib("CN\0", tok2) ) {
00077 ret->common_name = strdup(strsep(&sub, "=\0"));
00078 } else if( comp_attrib("emailAddress\0", tok2) ) {
00079 ret->email = strdup(strsep(&sub, "=\0"));
00080 }
00081 if( tok2 != NULL ) {
00082 free(tok2); tok2 = NULL;
00083 }
00084 }
00085 tok = strsep(&mainp, "/\0");
00086 }
00087 free(origptr); mainp = NULL; origptr = NULL;
00088
00089
00090 if( ret->org == NULL ) {
00091 ret->org = strdup("\0");
00092 }
00093 if( ret->common_name == NULL ) {
00094 ret->common_name = strdup("\0");
00095 }
00096 if( ret->email == NULL ) {
00097 ret->email = strdup("\0");
00098 }
00099
00100 return ret;
00101 }
00102
00103
00109 void free_certinfo(certinfo *p) {
00110 if( p == NULL )
00111 return;
00112
00113 if( p->digest != NULL )
00114 free(p->digest);
00115 if( p->org != NULL )
00116 free(p->org);
00117 if( p->common_name != NULL )
00118 free(p->common_name);
00119 if( p->email != NULL )
00120 free(p->email);
00121
00122 free(p);
00123 }