CgStringTokenizer *cg_string_tokenizer_new(char *value, char *delim) { CgStringTokenizer *strToken; cg_log_debug_l4("Entering...\n"); strToken = (CgStringTokenizer *)malloc(sizeof(CgStringTokenizer)); if ( NULL != strToken ) { #if defined(NOUSE_ZERO_COPY) strToken->value = cg_strdup(value); strToken->delim = cg_strdup(delim); #else strToken->value = value; strToken->delim = delim; #endif strToken->delimCnt = cg_strlen(strToken->delim); strToken->nextStartPos = 0; strToken->lastPos = cg_strlen(value) - 1; strToken->currToken = NULL; strToken->nextToken = NULL; cg_string_tokenizer_nexttoken(strToken); } return strToken; cg_log_debug_l4("Leaving...\n"); }
char *cg_net_uri_getupnpbasepath(CgNetURI *locationURL) { char *path, *c; int i; path = cg_strdup(cg_net_uri_getpath(locationURL)); cg_log_debug_s("Mangling url string: %s\n", path); i = cg_strlen(path); if ( 0 >= i ) { cg_log_debug("No base path, doing nothing.\n"); return NULL; } /* Truncating out the "file name" from path */ for ( c=( path + --i); 0<=i; c=( path + --i )) if ( '/' == *c ) { *( path + i + 1 ) = '\0'; cg_log_debug_s("Truncating string from place %d\n", i); break; } cg_log_debug_s("url string after mangling: %s\n", path); return path; }
CgStringTokenizer *cg_string_tokenizer_new(const char *value, const char *delim) { CgStringTokenizer *strToken; cg_log_debug_l4("Entering...\n"); strToken = (CgStringTokenizer *)malloc(sizeof(CgStringTokenizer)); if ( NULL != strToken ) { strToken->value = cg_strdup(value); strToken->delim = cg_strdup(delim); strToken->delimCnt = cg_strlen(strToken->delim); strToken->nextStartPos = 0; strToken->lastPos = cg_strlen(value) - 1; strToken->currToken = NULL; strToken->nextToken = NULL; cg_string_tokenizer_nexttoken(strToken); } cg_log_debug_l4("Leaving...\n"); return strToken; }
/** * Add new logging target * @param target String identifying the logging target (Currently stdout|stderr|FILENAME) * @param mask Bitmask defining what messages are to be printed into this target */ int cg_log_add_target(char *target, int mask) { struct fd_list *temp = NULL; FILE *r_target = NULL; initialized = 1; /* Checking if target is standard stream or should we create * new stream for file output. */ if (!strcmp(target, "stdout")) r_target=stdout; else if (!strcmp(target, "stderr")) r_target=stderr; else { /* Try to use existing fd */ for (temp = descriptor_list; temp; temp=temp->next) { if (!strcmp(target, temp->name)) r_target = temp->fd; } /* User is adding new file for output, note that file is cleared if * it is not already open. */ if ( NULL == r_target) r_target=fopen(target, "w"); } if (NULL == (temp = (struct fd_list*)malloc(sizeof(struct fd_list)))) { return -1; } /* Adding new target into single linked list */ temp->next=descriptor_list; temp->apply_mask = mask; temp->name = cg_strdup(target); temp->fd = r_target; descriptor_list = temp; return 1; }
CgXmlNode *cg_soap_request_getbodynode(CgSoapRequest *soapReq) { CgXmlNode *envNode; CgXmlNode *bodyNode = NULL; CgXmlAttribute *attr; char *name; CgStringTokenizer *tok; char *nsPrefix; size_t bodyLen; char *body; cg_log_debug_l4("Entering...\n"); envNode = cg_soap_request_getenvelopenode(soapReq); if (envNode == NULL) return NULL; if (cg_xml_node_haschildnodes(envNode) == FALSE) return NULL; /* We cannot assume the namespace prefix for Body is 's'. According to spec, it could be anything... */ for (attr = cg_xml_node_getattributes(envNode); attr != NULL; attr = cg_xml_attribute_next(attr)) { /* First, find the namespace declaration attribute. */ /* Note: We must take a copy of the attr name. Tokenizer doesn't do it (by default) */ name = cg_strdup( cg_xml_attribute_getname(attr) ); tok = cg_string_tokenizer_new(name, ":"); nsPrefix = cg_string_tokenizer_nexttoken(tok); if ( -1 != cg_strstr(nsPrefix, "xmlns")) { /* This attribute is a namespace declaration. Check is it the one defined for SOAP. */ if (cg_strcmp(cg_xml_attribute_getvalue(attr), CG_SOAP_XMLNS_URL) == 0) { /* This namespace declaration is correct. Use it to find the body node... */ if (cg_string_tokenizer_hasmoretoken(tok)) { /* There is a prefix */ nsPrefix = cg_string_tokenizer_nexttoken(tok); bodyLen = cg_strlen(nsPrefix) + cg_strlen(CG_SOAP_DELIM) + cg_strlen(CG_SOAP_BODY) + 1; /* +1 for trailing '\0'*/ body = (char*)malloc(bodyLen); if ( NULL == body ) { cg_log_debug_s("Memory allocation failure!\n"); return NULL; } #if defined(HAVE_SNPRINTF) snprintf(body, bodyLen, "%s%s%s", nsPrefix, CG_SOAP_DELIM, CG_SOAP_BODY); #else sprintf(body, "%s%s%s", nsPrefix, CG_SOAP_DELIM, CG_SOAP_BODY); #endif bodyNode = cg_xml_node_getchildnode(envNode, body); free(body); } else { /* No prefix */ bodyNode = cg_xml_node_getchildnode(envNode, CG_SOAP_BODY); } /* Free memory before leaving the loop */ cg_string_tokenizer_delete(tok); free(name); break; } } cg_string_tokenizer_delete(tok); free(name); } cg_log_debug_l4("Leaving...\n"); return bodyNode; }
/** * Set log item separator * @param s String to use as a log item separator */ void cg_log_set_separator(char *s) { if (separator != NULL) free(separator); separator = cg_strdup(s); }