void GWEN_RefPtr_free(GWEN_REFPTR *rp) { if (rp) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Freeing GWEN_RefPtr"); GWEN_RefPtrObject_free(rp->objectPtr); GWEN_FREE_OBJECT(rp); } }
int GWEN_Directory_FindPathForFile(const GWEN_STRINGLIST *paths, const char *filePath, GWEN_BUFFER *fbuf) { GWEN_STRINGLISTENTRY *se; se=GWEN_StringList_FirstEntry(paths); while(se) { GWEN_BUFFER *tbuf; FILE *f; tbuf=GWEN_Buffer_new(0, 256, 0, 1); GWEN_Buffer_AppendString(tbuf, GWEN_StringListEntry_Data(se)); GWEN_Buffer_AppendString(tbuf, DIRSEP); GWEN_Buffer_AppendString(tbuf, filePath); DBG_VERBOUS(GWEN_LOGDOMAIN, "Trying \"%s\"", GWEN_Buffer_GetStart(tbuf)); f=fopen(GWEN_Buffer_GetStart(tbuf), "r"); if (f) { fclose(f); DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" found in folder \"%s\"", filePath, GWEN_StringListEntry_Data(se)); GWEN_Buffer_AppendString(fbuf, GWEN_StringListEntry_Data(se)); GWEN_Buffer_free(tbuf); return 0; } GWEN_Buffer_free(tbuf); se=GWEN_StringListEntry_Next(se); } DBG_INFO(GWEN_LOGDOMAIN, "File \"%s\" not found", filePath); return GWEN_ERROR_NOT_FOUND; }
void GWEN_RefPtrInfo_free(GWEN_REFPTR_INFO *rpi) { if (rpi) { assert(rpi->refCount); if (--(rpi->refCount)==0) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Freeing GWEN_RefPtrInfo"); GWEN_FREE_OBJECT(rpi); } } }
void GWEN_InheritData_freeData(GWEN_INHERITDATA *d) { if (d) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Freeing data for type \"%s\"", d->typeName); if (d->freeDataFn) d->freeDataFn(d->baseData, d->data); d->freeDataFn=NULL; d->data=NULL; } }
IPCMESSAGE *CTService_Message_Create(int msgCode, int msgVersion, int msgId, int msgReply, int msgSize) { IPCMESSAGE *msg; ERRORCODE err; DBG_ENTER; DBG_VERBOUS("Creating message: %d, %d, %d, %d\n", msgCode, msgVersion, msgId, msgReply); msg=IPCMessage_new(); err=IPCMessage_SetBuffer(msg, 0, msgSize); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(msg); return 0; } /* add msg code */ err=IPCMessage_AddIntParameter(msg, msgCode); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(msg); DBG_LEAVE; return 0; } /* add msg version */ err=IPCMessage_AddIntParameter(msg,msgVersion); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(msg); DBG_LEAVE; return 0; } /* add message id */ err=IPCMessage_AddIntParameter(msg, msgId); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(msg); DBG_LEAVE; return 0; } /* add msg reply code */ err=IPCMessage_AddIntParameter(msg, msgReply); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(msg); DBG_LEAVE; return 0; } DBG_LEAVE; return msg; }
CTSERVICEREQUEST *CTService_Request_FindRequest(int id, CTSERVICEREQUEST **head) { CTSERVICEREQUEST *curr; DBG_ENTER; assert(head); curr=*head; while(curr) { if (curr->requestId==id) { DBG_VERBOUS("Found request %d", id); return curr; } curr=curr->next; } /* while */ DBG_LEAVE; DBG_VERBOUS("Request %d not found", id); return 0; }
void Error_ModuleInit() { int i; DBG_VERBOUS("Error_ModuleInit"); if (!error_is_initialized) { // init all ptrs to zero for (i=0; i<ERROR_MAX_TYPES; i++) error_type_ptr[i]=(ERRORTYPEREGISTRATIONFORM*)0; error_type_ptr[0]=&error_error_descr; error_is_initialized=1; } // if not initialized }
GWEN_INHERITDATA *GWEN_Inherit_FindEntry(GWEN_INHERITDATA_LIST *l, uint32_t id, int wantCreate) { GWEN_INHERITDATA *ih; assert(l); DBG_VERBOUS(GWEN_LOGDOMAIN, "Searching for inheritance id \"%08x\"", id); ih=GWEN_InheritData_List_First(l); while(ih) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Checking type \"%s\" (%08x) against %08x", ih->typeName, ih->id, id); if (ih->id==id) return ih; ih=GWEN_InheritData_List_Next(ih); } /* while */ if (!wantCreate) { DBG_WARN(GWEN_LOGDOMAIN, "Type \"%08x\" not derived from this base type", id); } return 0; }
void AB_Provider_free(AB_PROVIDER *pro){ if (pro) { assert(pro->usage); if (--(pro->usage)==0) { DBG_VERBOUS(AQBANKING_LOGDOMAIN, "Destroying AB_PROVIDER (%s)", pro->name); GWEN_INHERIT_FINI(AB_PROVIDER, pro); GWEN_Plugin_free(pro->plugin); free(pro->name); free(pro->escName); GWEN_LIST_FINI(AB_PROVIDER, pro); GWEN_FREE_OBJECT(pro); } } }
void GWEN_RefPtrObject_free(GWEN_REFPTR_POBJECT *rpo) { if (rpo) { assert(rpo->refCount); if (--(rpo->refCount)==0) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Freeing GWEN_RefPtrObject"); if ((rpo->flags & GWEN_REFPTR_FLAGS_AUTODELETE) && rpo->infoPtr && rpo->ptr) { if (rpo->infoPtr->freeFn) rpo->infoPtr->freeFn(rpo->ptr); } GWEN_FREE_OBJECT(rpo); } } }
int GWEN_LibLoader_Resolve(GWEN_LIBLOADER *h, const char *name, void **p) { assert(h); assert(name); assert(p); if (!h->handle) return GWEN_ERROR_NOT_OPEN; *p=dlsym(h->handle, name); if (!*p) { DBG_INFO(GWEN_LOGDOMAIN, "Error resolving symbol \"%s\": %s\n", name, dlerror()); return GWEN_ERROR_COULD_NOT_RESOLVE; } DBG_VERBOUS(GWEN_LOGDOMAIN, "Resolved symbol \"%s\": %p\n", name, *p); return 0; }
GWEN_INHERITDATA *GWEN_InheritData_new(const char *t, uint32_t id, void *data, void *baseData, GWEN_INHERIT_FREEDATAFN freeDataFn) { GWEN_INHERITDATA *d; assert(t); GWEN_NEW_OBJECT(GWEN_INHERITDATA, d); GWEN_LIST_INIT(GWEN_INHERITDATA, d); d->typeName=strdup(t); d->id=id; d->data=data; d->baseData=baseData; d->freeDataFn=freeDataFn; DBG_VERBOUS(GWEN_LOGDOMAIN, "Created inheritance for type \"%s\" (%08x)", t, id); return d; }
GWEN_DATE *GWEN_Date_fromDb(GWEN_DB_NODE *db) { const char *s; s=GWEN_DB_GetCharValue(db, "dateString", 0, NULL); if (s && *s) { GWEN_DATE *dt; dt=GWEN_Date_fromString(s); if (dt==NULL) { DBG_INFO(GWEN_LOGDOMAIN, "Invalid date [%s]", s); return NULL; } return dt; } else { DBG_VERBOUS(GWEN_LOGDOMAIN, "no or empty date"); return NULL; } }
uint32_t GWEN_Inherit_MakeId(const char *typeName) { unsigned int i, j; uint32_t result; result=0; j=strlen(typeName); for (i=0; i<j; i++) { uint32_t tmpResult; unsigned char c; tmpResult=result<<8; c=((result>>24)&0xff); result=tmpResult|c; result^=(unsigned char)(typeName[i]); } DBG_VERBOUS(GWEN_LOGDOMAIN, "Id for type \"%s\" is \"%08x\"", typeName, result); return result; }
GWEN_TIME *GWEN_Time_fromDb(GWEN_DB_NODE *db) { GWEN_TIME *t; GWEN_DB_NODE *dbT; int day, month, year; int hour, min, sec; int inUtc; day=month=year=0; hour=min=sec=0; inUtc=GWEN_DB_GetIntValue(db, "inUtc", 0, 0); dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "date"); if (dbT) { day=GWEN_DB_GetIntValue(dbT, "day", 0, 0); month=GWEN_DB_GetIntValue(dbT, "month", 0, 1)-1; year=GWEN_DB_GetIntValue(dbT, "year", 0, 0); if (!day || !year) { DBG_INFO(GWEN_LOGDOMAIN, "Bad date in DB"); return 0; } } dbT=GWEN_DB_GetGroup(db, GWEN_PATH_FLAGS_NAMEMUSTEXIST, "time"); if (dbT) { hour=GWEN_DB_GetIntValue(dbT, "hour", 0, 0); min=GWEN_DB_GetIntValue(dbT, "min", 0, 0); sec=GWEN_DB_GetIntValue(dbT, "sec", 0, 0); } DBG_VERBOUS(GWEN_LOGDOMAIN, "Creating time from this: %04d/%02d/%02d - %02d:%02d:%02d (%d)", year, month, day, hour, min, sec, inUtc); t=GWEN_Time_new(year, month, day, hour, min, sec, inUtc); if (!t) { DBG_INFO(GWEN_LOGDOMAIN, "Bad date/time"); return 0; } return t; }
int GWEN_XML__ReadTag(GWEN_XML_CONTEXT *ctx, GWEN_FAST_BUFFER *fb, GWEN_UNUSED uint32_t flags, GWEN_BUFFER *dbuf) { int chr; unsigned char uc=0; int rv; /* skip blanks */ for (;;) { GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc>32) break; } if (uc=='/') { /* read end tag */ GWEN_Buffer_AppendByte(dbuf, uc); for (;;) { GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc=='>' || uc<33) break; GWEN_Buffer_AppendByte(dbuf, uc); } rv=GWEN_XmlCtx_StartTag(ctx, GWEN_Buffer_GetStart(dbuf)); if (rv) { return rv; } if (uc!='>') { for (;;) { /* skip blanks, expect '>' */ GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc>32) break; } } if (uc!='>') { DBG_ERROR(GWEN_LOGDOMAIN, "Unexpected character"); return GWEN_ERROR_BAD_DATA; } /* tag finished */ rv=GWEN_XmlCtx_EndTag(ctx, 0); if (rv) { return rv; } return 0; } else if (uc=='!') { /* check for comment */ GWEN_FASTBUFFER_PEEKBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc=='-') { fb->bufferReadPos++; GWEN_FASTBUFFER_PEEKBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc=='-') { GWEN_BUFFER *cbuf; /* found comment */ fb->bufferReadPos++; cbuf=GWEN_Buffer_new(0, 256, 0, 1); for (;;) { GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { GWEN_Buffer_free(cbuf); return chr; } uc=(unsigned char) chr; GWEN_Buffer_AppendByte(cbuf, uc); if (GWEN_Buffer_GetUsedBytes(cbuf)>2) { char *p; p=GWEN_Buffer_GetStart(cbuf); p+=GWEN_Buffer_GetUsedBytes(cbuf)-3; if (strcmp(p, "-->")==0) { *p=0; rv=GWEN_XmlCtx_AddComment(ctx, GWEN_Buffer_GetStart(cbuf)); if (rv) { GWEN_Buffer_free(cbuf); return rv; } GWEN_Buffer_free(cbuf); return 0; } } } } else { GWEN_Buffer_AppendString(dbuf, "!-"); } } else uc='!'; } /* read name */ for (;;) { if (uc==' ' || uc=='>' || uc=='/') break; else if (GWEN_Buffer_GetUsedBytes(dbuf)) { unsigned char fc; fc=*GWEN_Buffer_GetStart(dbuf); if ((fc=='!' && uc=='!') || (fc=='?' && uc=='?')) { GWEN_FASTBUFFER_PEEKBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc=='>') { fb->bufferReadPos++; break; } } } GWEN_Buffer_AppendByte(dbuf, uc); GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { if (chr==GWEN_ERROR_EOF) { return chr; } else { return chr; } } uc=(unsigned char) chr; } /* tag started */ if (GWEN_Buffer_GetUsedBytes(dbuf)==0) { DBG_ERROR(GWEN_LOGDOMAIN, "Element name missing"); return GWEN_ERROR_BAD_DATA; } rv=GWEN_XmlCtx_StartTag(ctx, GWEN_Buffer_GetStart(dbuf)); if (rv) { return rv; } if (uc=='/' || uc=='?' || uc=='!') { GWEN_FASTBUFFER_PEEKBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc=='>') { fb->bufferReadPos++; rv=GWEN_XmlCtx_EndTag(ctx, 1); if (rv) { return rv; } /* tag finished */ return 0; } } if (uc=='>') { rv=GWEN_XmlCtx_EndTag(ctx, 0); if (rv) { return rv; } /* tag finished */ return 0; } /* read attributes */ for (;;) { GWEN_BUFFER *nbuf; GWEN_BUFFER *vbuf=NULL; nbuf=GWEN_Buffer_new(0, 256, 0, 1); /* skip blanks */ for (;;) { GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { GWEN_Buffer_free(nbuf); return chr; } uc=(unsigned char) chr; if (uc>32) break; } /* read attribute name */ for (;;) { if (uc=='/' || uc=='!' || uc=='?' || uc=='=' || uc=='>') break; GWEN_Buffer_AppendByte(nbuf, uc); GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { GWEN_Buffer_free(nbuf); return chr; } uc=(unsigned char) chr; } if (GWEN_Buffer_GetUsedBytes(nbuf)) { if (uc=='=') { /* read attribute value if there is an equation mark */ int inQuote=0; vbuf=GWEN_Buffer_new(0, 256, 0, 1); for (;;) { GWEN_FASTBUFFER_READBYTE(fb, chr); if (chr<0) { GWEN_Buffer_free(nbuf); return chr; } uc=(unsigned char) chr; if (uc=='"') { if (inQuote) { inQuote=0; break; } else inQuote=1; } else { if (!inQuote) { if (uc=='>' || uc<33) break; else if (uc=='<') { DBG_ERROR(GWEN_LOGDOMAIN, "Nested element definitions"); GWEN_Buffer_free(vbuf); GWEN_Buffer_free(nbuf); return GWEN_ERROR_BAD_DATA; } else if (GWEN_Buffer_GetUsedBytes(dbuf)) { if (uc=='/' || uc=='!' || uc=='?') { unsigned char tc; GWEN_FASTBUFFER_PEEKBYTE(fb, chr); if (chr<0) { GWEN_Buffer_free(vbuf); GWEN_Buffer_free(nbuf); return chr; } tc=(unsigned char) chr; if (tc=='>') { break; } } } } GWEN_Buffer_AppendByte(vbuf, uc); } } if (inQuote) { DBG_ERROR(GWEN_LOGDOMAIN, "No matching number of quote chars"); GWEN_Buffer_free(vbuf); GWEN_Buffer_free(nbuf); return GWEN_ERROR_BAD_DATA; } if (GWEN_Buffer_GetUsedBytes(vbuf)==0) { GWEN_Buffer_free(vbuf); vbuf=NULL; } } rv=GWEN_XmlCtx_AddAttr(ctx, GWEN_Buffer_GetStart(nbuf), vbuf?GWEN_Buffer_GetStart(vbuf):NULL); if (rv) { GWEN_Buffer_free(vbuf); GWEN_Buffer_free(nbuf); return rv; } } GWEN_Buffer_free(vbuf); GWEN_Buffer_free(nbuf); if (uc=='>' || uc=='?' || uc=='!' || uc=='/') break; } if (uc=='?' || uc=='!' || uc=='/') { unsigned char ucsave=uc; GWEN_FASTBUFFER_PEEKBYTE(fb, chr); if (chr<0) { return chr; } uc=(unsigned char) chr; if (uc=='>') { DBG_VERBOUS(GWEN_LOGDOMAIN, "Ending tag [%s]", GWEN_Buffer_GetStart(dbuf)); fb->bufferReadPos++; rv=GWEN_XmlCtx_EndTag(ctx, 1); if (rv) { return rv; } /* tag finished */ return 0; } else { DBG_ERROR(GWEN_LOGDOMAIN, "Got an unexpected character here (after %02x[%c]): %02x[%c], " "maybe the text contains unescaped XML characters?", ucsave, ucsave, uc, uc); } } else if (uc=='>') { rv=GWEN_XmlCtx_EndTag(ctx, 0); if (rv) { return rv; } /* tag finished */ return 0; } DBG_ERROR(GWEN_LOGDOMAIN, "Internal error: Should never reach this point"); return GWEN_ERROR_INTERNAL; }
void *GWEN_Directory_HandlePathElement(const char *entry, void *data, unsigned int flags) { char *p; struct stat st; int exists; int withDrive; GWEN_BUFFER *buf; GWEN_BUFFER *ebuf = 0; withDrive=0; #ifdef OS_WIN32 if (entry && isalpha(*entry)) { int len; /* append backslash if entry only consists of a drive specification */ len=strlen(entry); if ( (len==2) && (entry[1] == ':') ) { ebuf=GWEN_Buffer_new(0, len+2, 0, 1); GWEN_Buffer_AppendString(ebuf, entry); GWEN_Buffer_AppendByte(ebuf, '\\'); withDrive=1; entry=GWEN_Buffer_GetStart(ebuf); } } #endif /* OS_WIN32 */ if (strcasecmp(entry, "..")==0) { DBG_ERROR(GWEN_LOGDOMAIN, "\"..\" detected"); GWEN_Buffer_free(ebuf); return 0; } buf=(GWEN_BUFFER*)data; if (GWEN_Buffer_GetUsedBytes(buf) && !withDrive) { char c; c=GWEN_Buffer_GetStart(buf)[GWEN_Buffer_GetUsedBytes(buf)-1]; #ifdef OS_WIN32 if (c!='\\') GWEN_Buffer_AppendByte(buf, '\\'); #else if (c!='/') GWEN_Buffer_AppendByte(buf, '/'); #endif /* OS_WIN32 */ } GWEN_Buffer_AppendString(buf, entry); /* check for existence of the file/folder */ p=GWEN_Buffer_GetStart(buf); DBG_VERBOUS(GWEN_LOGDOMAIN, "Checking path \"%s\"", p); if (stat(p, &st)) { exists=0; DBG_DEBUG(GWEN_LOGDOMAIN, "stat: %s (%s)", strerror(errno), p); if ((flags & GWEN_PATH_FLAGS_PATHMUSTEXIST) || ((flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_PATH_FLAGS_NAMEMUSTEXIST))) { DBG_INFO(GWEN_LOGDOMAIN, "Path \"%s\" does not exist (it should)", p); GWEN_Buffer_free(ebuf); return 0; } } else { DBG_VERBOUS(GWEN_LOGDOMAIN, "Checking for type"); exists=1; if (flags & GWEN_PATH_FLAGS_VARIABLE) { if (!S_ISREG(st.st_mode)) { DBG_INFO(GWEN_LOGDOMAIN, "%s not a regular file", p); GWEN_Buffer_free(ebuf); return 0; } } else { if (!S_ISDIR(st.st_mode)) { DBG_INFO(GWEN_LOGDOMAIN, "%s not a direcory", p); GWEN_Buffer_free(ebuf); return 0; } } if ((flags & GWEN_PATH_FLAGS_PATHMUSTNOTEXIST) || ((flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_PATH_FLAGS_NAMEMUSTNOTEXIST))) { DBG_INFO(GWEN_LOGDOMAIN, "Path \"%s\" exists (it should not)", p); GWEN_Buffer_free(ebuf); return 0; } } /* if stat is ok */ if (!exists) { int isPublic; DBG_DEBUG(GWEN_LOGDOMAIN, "Entry \"%s\" does not exist", p); isPublic=( ((flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_DIR_FLAGS_PUBLIC_NAME)) || (!(flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_DIR_FLAGS_PUBLIC_PATH)) ); if (flags & GWEN_PATH_FLAGS_VARIABLE) { /* create file */ int fd; DBG_DEBUG(GWEN_LOGDOMAIN, "Creating file \"%s\"", p); if (isPublic) fd=open(p, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR #ifdef S_IRGRP | S_IRGRP #endif #ifdef S_IROTH | S_IROTH #endif ); else fd=open(p, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd==-1) { DBG_ERROR(GWEN_LOGDOMAIN, "open: %s (%s)", strerror(errno), p); GWEN_Buffer_free(ebuf); return 0; } close(fd); DBG_VERBOUS(GWEN_LOGDOMAIN, "Successfully created"); } else { /* create dir */ DBG_VERBOUS(GWEN_LOGDOMAIN, "Creating folder \"%s\"", p); if (isPublic) { if (GWEN_Directory_CreatePublic(p)) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not create directory \"%s\"", p); GWEN_Buffer_free(ebuf); return 0; } } else { if (GWEN_Directory_Create(p)) { DBG_ERROR(GWEN_LOGDOMAIN, "Could not create directory \"%s\"", p); GWEN_Buffer_free(ebuf); return 0; } } } } /* if exists */ else { DBG_VERBOUS(GWEN_LOGDOMAIN, "Entry \"%s\" exists", p); } DBG_VERBOUS(GWEN_LOGDOMAIN, "Returning this: %s", p); GWEN_Buffer_free(ebuf); return buf; }
void* GWEN_XMLNode_HandlePath(const char *entry, void *data, int idx, uint32_t flags) { GWEN_XMLNODE *n; GWEN_XMLNODE *nn; int i; n=(GWEN_XMLNODE*)data; if (flags & GWEN_PATH_FLAGS_VARIABLE) { DBG_ERROR(GWEN_LOGDOMAIN, "GWEN_PATH_FLAGS_VARIABLE not allowed for XPATH"); return 0; } if (flags & GWEN_PATH_FLAGS_ROOT) { while(n->parent) n=n->parent; if (*entry=='/') entry++; } if (strcasecmp(entry, "..")==0) { return n->parent; } else if (strcasecmp(entry, ".")==0 || strcasecmp(entry, "here()")==0) { return n; } /* check whether we are allowed to simply create the node */ if ( ((flags & GWEN_PATH_FLAGS_LAST) && (((flags & GWEN_PATH_FLAGS_VARIABLE) && (flags & GWEN_PATH_FLAGS_CREATE_VAR)) || (!(flags & GWEN_PATH_FLAGS_VARIABLE) && (flags & GWEN_PATH_FLAGS_CREATE_GROUP))) ) || ( !(flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_PATH_FLAGS_PATHCREATE)) ) { /* simply create the new variable/group */ if (flags & GWEN_PATH_FLAGS_VARIABLE) { /* not allowed for now */ return 0; } else { if (idx!=0) { DBG_ERROR(GWEN_LOGDOMAIN, "Can not create tag with index!=1 (%s)", entry); return 0; } DBG_VERBOUS(GWEN_LOGDOMAIN, "Unconditionally creating tag \"%s\"", entry); nn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, entry); GWEN_XMLNode_AddChild(n, nn); return nn; } } /* find the node */ i=idx; nn=GWEN_XMLNode_FindFirstTag(n, entry, 0, 0); while(nn && i--) { nn=GWEN_XMLNode_FindNextTag(nn, entry, 0, 0); } if (!nn) { /* node not found, check, if we are allowed to create it */ if ( (!(flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_PATH_FLAGS_PATHMUSTEXIST)) || (flags & GWEN_PATH_FLAGS_NAMEMUSTEXIST) ) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Tag \"%s\" does not exist", entry); return 0; } /* create the new variable/group */ if (idx!=0) { DBG_ERROR(GWEN_LOGDOMAIN, "Can not create tag with index!=1 (%s)", entry); return 0; } DBG_VERBOUS(GWEN_LOGDOMAIN, "Tag \"%s\" not found, creating", entry); nn=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, entry); GWEN_XMLNode_AddChild(n, nn); } /* if node not found */ else { /* node does exist, check whether this is ok */ if ( ((flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_PATH_FLAGS_NAMEMUSTNOTEXIST)) || (!(flags & GWEN_PATH_FLAGS_LAST) && (flags & GWEN_PATH_FLAGS_PATHMUSTNOTEXIST)) ) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Entry \"%s\" already exists", entry); return 0; } } return nn; }
GWEN_TIME *GWEN_Time__fromString(const char *s, const char *tmpl, int inUtc) { int year, month, day; int hour, min, sec; const char *p; const char *t; GWEN_TIME *gwt; assert(s); assert(tmpl); year=month=day=0; hour=min=sec=0; p=s; t=tmpl; while(*t && *p) { int i; if (*t=='*') { t++; if (!*t) { DBG_ERROR(GWEN_LOGDOMAIN, "Bad pattern: Must not end with \"*\""); return 0; } i=0; while(*p) { if (!isdigit((int)*p)) break; if (*p==*t) break; i*=10; i+=(*p)-'0'; p++; } /* while */ } else { if (isdigit((int)*p)) i=(*p)-'0'; else i=-1; p++; } if (i==-1 && strchr("YMDhms", *t)!=NULL) { DBG_INFO(GWEN_LOGDOMAIN, "No more digits at [%s], continuing", t); p--; } else { switch(*t) { case 'Y': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } year*=10; year+=i; break; case 'M': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } month*=10; month+=i; break; case 'D': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } day*=10; day+=i; break; case 'h': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } hour*=10; hour+=i; break; case 'm': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } min*=10; min+=i; break; case 's': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } sec*=10; sec+=i; break; default: DBG_VERBOUS(GWEN_LOGDOMAIN, "Unknown character in template, will skip in both strings"); break; } } t++; } /* while */ if (year<100) year+=2000; if (day==0) day=1; DBG_DEBUG(GWEN_LOGDOMAIN, "Got this date/time: %04d/%02d/%02d, %02d:%02d:%02d", year, month-1, day, hour, min, sec); /* get time in local time */ gwt=GWEN_Time_new(year, month-1, day, hour, min, sec, inUtc); if (!gwt) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } return gwt; }
GWEN_DATE *GWEN_Date_fromStringWithTemplate(const char *s, const char *tmpl) { int year, month, day; const char *p; const char *t; GWEN_DATE *gwt; assert(s); assert(tmpl); year=month=day=0; p=s; t=tmpl; while(*t && *p) { int i; if (*t=='*') { t++; if (!*t) { DBG_ERROR(GWEN_LOGDOMAIN, "Bad pattern: Must not end with \"*\""); return 0; } i=0; while(*p) { if (!isdigit((int)*p)) break; if (*p==*t) break; i*=10; i+=(*p)-'0'; p++; } /* while */ } else { if (isdigit((int)*p)) i=(*p)-'0'; else i=-1; p++; } if (i==-1 && strchr("YMD", *t)!=NULL) { DBG_INFO(GWEN_LOGDOMAIN, "No more digits at [%s], continuing", t); p--; } else { switch(*t) { case 'Y': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } year*=10; year+=i; break; case 'M': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } month*=10; month+=i; break; case 'D': if (i==-1) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } day*=10; day+=i; break; default: DBG_VERBOUS(GWEN_LOGDOMAIN, "Unknown character in template, will skip in both strings"); break; } } t++; } /* while */ if (year<100) year+=2000; DBG_DEBUG(GWEN_LOGDOMAIN, "Got this date/time: %04d/%02d/%02d", year, month, day); /* get time in local time */ gwt=GWEN_Date_fromGregorian(year, month, day); if (!gwt) { DBG_INFO(GWEN_LOGDOMAIN, "here"); return 0; } return gwt; }
IPCMESSAGE *CTService_EncryptMessage(CTSERVICEDATA *pd, IPCMESSAGE *msg) { unsigned char *cryptbuffer; int cryptbuffersize; int endbuffersize; ERRORCODE err; IPCMESSAGE *tmpmsg; IPCMESSAGE *endmsg; DBG_ENTER; assert(pd); assert(msg); assert(pd->sessionKey); /* create intermediate message * This message contains: * - original message * - signature id (if sign!=0) * - signature (if sign!=0) */ tmpmsg=IPCMessage_new(); IPCMessage_SetBuffer(tmpmsg,0,IPCMESSAGE_MAXMSGSIZE); /* add original message */ DBG_VERBOUS("Adding original message"); err=IPCMessage_AddParameter(tmpmsg, IPCMessage_GetMessageBegin(msg), IPCMessage_GetMessageSize(msg)); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(tmpmsg); DBG_LEAVE; return 0; } /* finalize intermediate message */ DBG_VERBOUS("Finalizing message"); err=IPCMessage_BuildMessage(tmpmsg); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(tmpmsg); DBG_LEAVE; return 0; } /* encrypt intermediate message */ DBG_VERBOUS("Encrypting message"); err=Cryp_Encrypt((CRYP_BFKEY*)pd->sessionKey, CryptAlgoBlowfish, IPCMessage_GetMessageBegin(tmpmsg), IPCMessage_GetMessageSize(tmpmsg), &cryptbuffer, &cryptbuffersize); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(tmpmsg); DBG_LEAVE; return 0; } /* now the cryptbuffer contains the encrypted message */ /* free unneeded buffers */ IPCMessage_free(tmpmsg); /* create final message */ DBG_VERBOUS("Building final message"); endbuffersize=cryptbuffersize+32; if (endbuffersize>IPCMESSAGE_MAXMSGSIZE) endbuffersize=IPCMESSAGE_MAXMSGSIZE; endmsg=IPCMessage_new(); IPCMessage_SetBuffer(endmsg,0, endbuffersize); /* add message code */ err=IPCMessage_AddIntParameter(endmsg,CTSERVICE_MSGCODE_BF); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(endmsg); free(cryptbuffer); DBG_LEAVE; return 0; } /* add message version */ err=IPCMessage_AddIntParameter(endmsg,CTSERVICE_MSGCODE_BF_VERSION); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(endmsg); free(cryptbuffer); DBG_LEAVE; return 0; } /* add encrypted message */ err=IPCMessage_AddParameter(endmsg, cryptbuffer, cryptbuffersize); free(cryptbuffer); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(endmsg); DBG_LEAVE; return 0; } /* finalize final message */ err=IPCMessage_BuildMessage(endmsg); if (!Error_IsOk(err)) { DBG_ERROR_ERR(err); IPCMessage_free(endmsg); DBG_LEAVE; return 0; } /* return encrypted message */ DBG_LEAVE; return endmsg; }
int GWEN_Error_ModuleInit(void) { DBG_VERBOUS(GWEN_LOGDOMAIN, "Error_ModuleInit"); return 0; }
IPCMESSAGE *CTService_DecryptMessage(CTSERVICEDATA *pd, IPCMESSAGE *msg) { ERRORCODE err; unsigned char *decryptbuffer; int decryptbuffersize; char *endbuffer; char *pencmsg; int encmsgsize; char *pomsg; int omsgsize; int i; IPCMESSAGE *tmpmsg; IPCMESSAGE *endmsg; assert(pd); assert(msg); assert(pd->sessionKey); /* get message code */ err=IPCMessage_FirstIntParameter(msg, &i); if (!Error_IsOk(err)) { DBG_ERROR("No message code"); DBG_ERROR_ERR(err); return 0; } if (i!=CTSERVICE_MSGCODE_BF) { DBG_ERROR("Bad message code"); return 0; } /* get message version */ err=IPCMessage_NextIntParameter(msg, &i); if (!Error_IsOk(err)) { DBG_ERROR("No message version"); DBG_ERROR_ERR(err); return 0; } /* check message version (only major number) */ if ((i&0xff00)!=(CTSERVICE_MSGCODE_BF_VERSION&0xff00)) { DBG_ERROR("Bad message version"); return 0; } /* get encrypted message */ err=IPCMessage_NextParameter(msg, &pencmsg, &encmsgsize); if (!Error_IsOk(err)) { DBG_ERROR("No encrypted message within"); DBG_ERROR_ERR(err); return 0; } /* decrypt message */ DBG_VERBOUS("Decrypting message"); err=Cryp_Decrypt(pd->sessionKey, CryptAlgoBlowfish, pencmsg, encmsgsize, &decryptbuffer, &decryptbuffersize); if (!Error_IsOk(err)) { DBG_ERROR("Error when decrypting"); DBG_ERROR_ERR(err); return 0; } /* analyze message */ DBG_VERBOUS("Analyzing Decrypted message"); tmpmsg=IPCMessage_new(); err=IPCMessage_SetBuffer(tmpmsg, decryptbuffer, decryptbuffersize); if (!Error_IsOk(err)) { DBG_ERROR("Could not set buffer"); DBG_ERROR_ERR(err); IPCMessage_free(tmpmsg); return 0; } /* get original message */ DBG_VERBOUS("Getting original message"); err=IPCMessage_FirstParameter(tmpmsg, &pomsg, &omsgsize); if (!Error_IsOk(err)) { DBG_ERROR("No original message"); DBG_ERROR_ERR(err); IPCMessage_free(tmpmsg); return 0; } /* copy original message into new buffer */ endbuffer=(char*)malloc(omsgsize); assert(endbuffer); memmove(endbuffer, pomsg, omsgsize); IPCMessage_free(tmpmsg); /* create final message */ endmsg=IPCMessage_new(); err=IPCMessage_SetBuffer(endmsg, endbuffer, omsgsize); if (!Error_IsOk(err)) { DBG_ERROR("Could not set buffer in endmessage"); DBG_ERROR_ERR(err); IPCMessage_free(endmsg); return 0; } /* return decoded message */ DBG_DEBUG("Message decoded"); #if DEBUGMODE>5 Chameleon_DumpString(IPCMessage_GetMessageBegin(endmsg), IPCMessage_GetMessageSize(endmsg)); #endif return endmsg; }