/* replace the Content-Length value with the given value */ void set_cl(char* mes, int contentlen) { char *cl, *cr, *backup; if ((cl=STRSTR(ack, CON_LEN_STR)) == NULL && (cl=STRSTR(ack, CON_LEN_SHORT_STR)) == NULL) { printf("missing Content-Lenght in message\n"); return; } cr = strchr(cl, '\n'); cr++; backup=malloc(strlen(cr)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strncpy(backup, cr, strlen(cr)+1); if (*cl == 'C') cr=cl + CON_LEN_STR_LEN; else cr=cl + 3; snprintf(cr, 6, "%i\r\n", contentlen); cr=strchr(cr, '\n'); cr++; strncpy(cr, backup, strlen(backup)+1); free(backup); if (verbose > 1) printf("Content-Length set to %i\n", contentlen); if (verbose > 2) printf("New message with changed Content-Length:\n%s\n", mes); }
void cpy_to(char *reply, char *dest) { char *src_to, *dst_to, *backup, *tmp; /* find the position where we want to insert the To */ if ((dst_to=STRSTR(dest, "TO_STR"))==NULL && (dst_to=STRSTR(dest, "\nTO_SHORT_STR"))==NULL) { printf("error: could not find To in the reply\n"); exit_code(2); } /* find the To we want to copy */ if ((src_to=STRSTR(reply, "TO_STR"))==NULL && (src_to=STRSTR(reply, "\nTO_SHORT_STR"))==NULL) { if (verbose > 0) printf("warning: could not find To in reply. " "trying with original To\n"); } else { /* both To found, so copy it */ tmp=strchr(dst_to, '\n'); tmp++; backup=malloc(strlen(tmp)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strcpy(backup, tmp); tmp=strchr(src_to, '\n'); strncpy(dst_to, src_to, (size_t)(tmp-src_to+1)); strcpy(dst_to+(tmp-src_to+1), backup); free(backup); if (verbose >2) printf("reply with copyed To:\n%s\n", dest); } }
/* copy the via lines from the message to the message reply for correct routing of our reply. */ void cpy_vias(char *reply, char *dest){ char *first_via, *middle_via, *last_via, *backup; /* lets see if we find any via */ if ((first_via=STRSTR(reply, "VIA_STR"))==NULL && (first_via=STRSTR(reply, "\nVIA_SHORT_STR"))==NULL ){ printf("error: the received message doesn't contain a Via header\n"); exit_code(3); } last_via=first_via+4; middle_via=last_via; /* proceed additional via lines */ while ((middle_via=STRSTR(last_via, "VIA_STR"))!=NULL || (middle_via=STRSTR(last_via, "\nVIA_SHORT_STR"))!=NULL ) last_via=middle_via+4; last_via=strchr(last_via, '\n'); middle_via=strchr(dest, '\n')+1; /* make a backup, insert the vias after the first line and append backup */ backup=malloc(strlen(middle_via)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strcpy(backup, middle_via); strncpy(middle_via, first_via, (size_t)(last_via-first_via+1)); strcpy(middle_via+(last_via-first_via+1), backup); free(backup); if (verbose > 2) printf("message reply with vias included:\n%s\n", reply); }
/* add a Via Header Field in the message. */ void add_via(char *mes) { char *via_line, *via, *via2, *backup; /* first build our own Via-header-line */ via_line = malloc(VIA_SIP_STR_LEN+strlen(fqdn)+15); if (!via_line) { printf("failed to allocate memory\n"); exit_code(255); } snprintf(via_line, VIA_SIP_STR_LEN+strlen(fqdn)+5+10, "%s%s:%i;rport\r\n", VIA_SIP_STR, fqdn, lport); if (verbose > 2) printf("our Via-Line: %s\n", via_line); if (strlen(mes)+strlen(via_line)>= BUFSIZE){ printf("can't add our Via Header Line because file is too big\n"); exit_code(2); } via=STRSTR(mes, "\nVIA_STR"); via2=STRSTR(mes, "\nVIA_SHORT_STR"); if (via==NULL && via2==NULL ){ /* We doesn't find a Via so we insert our via direct after the first line. */ via=strchr(mes,'\n'); if(via == NULL) { printf("failed to find new line to insert Via\n"); return; } } else if (via!=NULL && via2!=NULL && via2<via){ /* the short via is above the long version */ via = via2; } else if (via==NULL && via2!=NULL){ /* their is only a short via */ via = via2; } via++; if (!via) { printf("failed to find Via header\n"); exit_code(1); } /* finnaly make a backup, insert our via and append the backup */ backup=malloc((strlen(via)+1)); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strncpy(backup, via, strlen(via)+1); strncpy(via, via_line, strlen(via_line)); strncpy(via+strlen(via_line), backup, strlen(backup)+1); if (verbose > 1) printf("New message with Via-Line:\n%s\n", mes); free(via_line); free(backup); }
int XmlApi::xmlreader_loadFile(const char *filename, XmlReaderCallback *only_this_object) { if (filename == NULL) return 0; String path; if(STRSTR(filename,"/") || STRSTR(filename,"\\")) { path=filename; char *p=(char *)path.getValue(); *((char *)Std::scanstr_back(p,"/\\",p)+1)=0; } return XmlReader::loadFile(Std::filename(filename), path.vs(), only_this_object); }
/* tryes to find the warning header filed and prints out the IP */ void warning_extract(char *message) { char *warning, *end, *mid, *server; int srvsize; if ((warning=STRSTR(message, "Warning:"))==NULL) { if (verbose > 0) printf("'no Warning header found' "); else printf("?? "); return; } end=strchr(warning, '"'); end--; warning=strchr(warning, '3'); warning=warning+4; mid=strchr(warning, ':'); if (mid) end=mid; srvsize=end - warning + 1; server=malloc((size_t)srvsize); if (!server) { printf("failed to allocate memory\n"); exit_code(255); } memset(server, 0, (size_t)srvsize); server=strncpy(server, warning, (size_t)(srvsize - 1)); printf("%s ", server); free(server); }
void increase_cseq(char *message) { int cs; char *cs_s, *eol, *backup; cs = cseq(message); if ((cs < 1) && (verbose > 1)) { printf("CSeq increase failed because unable to extract CSeq number\n"); return; } cs++; cs_s=STRSTR(message, CSEQ_STR); if (cs_s) { cs_s+=6; eol=strchr(cs_s, ' '); eol++; backup=malloc(strlen(eol)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strncpy(backup, eol, (size_t)(strlen(eol)+1)); snprintf(cs_s, 11, "%i ", cs); cs_s+=strlen(cs_s); strncpy(cs_s, backup, strlen(backup)); free(backup); } else if (verbose > 1) printf("'CSeq' not found in message\n"); }
ACPI_OBJECT_TYPE8 AcpiDbMatchArgument ( NATIVE_CHAR *UserArgument, ARGUMENT_INFO *Arguments) { UINT32 i; if (!UserArgument || UserArgument[0] == 0) { return (ACPI_TYPE_NOT_FOUND); } for (i = 0; Arguments[i].Name; i++) { if (STRSTR (Arguments[i].Name, UserArgument) == Arguments[i].Name) { return ((ACPI_OBJECT_TYPE8) i); } } /* Argument not recognized */ return (ACPI_TYPE_NOT_FOUND); }
void CContactInfo::CountMultiFields(AECHAR *pwzField, int &nCount) { if (NULL==pwzField ) return; nCount++; AECHAR pwzNewTag[]=NEW_FIELD; char pszNewtag[10]; SPRINTF(pszNewtag, "%S", pwzNewTag); char *pszTmp=NULL; int nLen=WSTRLEN(pwzField); pszTmp = (char*)MALLOC(nLen+1); if ( NULL==pszTmp ) return; WSTRTOSTR(pwzField, pszTmp, nLen+1); char *pNext=pszTmp; char *pFound=NULL; while ( NULL!=(pFound=STRSTR(pNext, pszNewtag))) { nCount++; pNext = pFound+1; } FREEIF(pszTmp); }
static size_t FindNext(const ElementType *SC,const CHAR_TYPE *text, size_t start) { size_t i; if (SC == NULL || text == NULL) return 0; for (i=start; i<SC->count;i++) { if (STRSTR(SC->contents[i],text)) { return i+1; } } return 0; }
/* check for the existence of a Max-Forwards header field. if its present it sets it to the given value, if not it will be inserted.*/ void set_maxforw(char *mes){ char *max, *backup, *crlfi; if ((max=STRSTR(mes, "MAX_FRW_STR"))==NULL){ /* no max-forwards found so insert it after the first line*/ max=strchr(mes,'\n'); if (!max) { printf("failed to find newline\n"); exit_code(254); } max++; backup=malloc(strlen(max)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strncpy(backup, max, (size_t)(strlen(max)+1)); snprintf(max, MAX_FRW_STR_LEN+6, "%s%i\r\n", MAX_FRW_STR, maxforw); max=strchr(max,'\n'); max++; strncpy(max, backup, strlen(backup)+1); free(backup); if (verbose > 1) printf("Max-Forwards %i inserted into header\n", maxforw); if (verbose > 2) printf("New message with inserted Max-Forwards:\n%s\n", mes); } else{ /* found max-forwards => overwrite the value with maxforw*/ crlfi=strchr(max,'\n'); crlfi++; backup=malloc(strlen(crlfi)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strncpy(backup, crlfi, strlen(crlfi)+1); crlfi=max + MAX_FRW_STR_LEN; snprintf(crlfi, 6, "%i\r\n", maxforw); crlfi=strchr(max,'\n'); crlfi++; strncpy(crlfi, backup, strlen(backup)+1); free(backup); if (verbose > 1) printf("Max-Forwards set to %i\n", maxforw); if (verbose > 2) printf("New message with changed Max-Forwards:\n%s\n", mes); } }
/* this function searches for search in mess and replaces it with replacement */ void replace_string(char *mess, char *search, char *replacement){ char *backup, *insert; insert=STRSTR(mess, search); if (insert==NULL){ if (verbose > 2) printf("warning: could not find this '%s' replacement string in " "message\n", search); } else { while (insert){ backup=malloc(strlen(insert)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strcpy(backup, insert+strlen(search)); strcpy(insert, replacement); strcpy(insert+strlen(replacement), backup); free(backup); insert=STRSTR(mess, search); } } }
/* build an ACK from the given invite and reply. * NOTE: space has to be allocated allready for the ACK */ void build_ack(char *invite, char *reply, char *ack) { char *body; int len; body = STRSTR(invite, "\r\n\r\n"); if (body) { body++; body++; len = body - invite; memcpy(ack, invite, len); *(ack+len+1) = '\0'; replace_string(ack, "INVITE", "ACK"); cpy_to(ack,reply); set_cl(ack, 0); } }
bool CContactInfo::SetValue(char **pszValue, char *pszXml, char *pszTag) { FREEIF(*pszValue); char pszT[20]; SPRINTF(pszT, "<%s>", pszTag); char *pszFound=NULL; char *pszNext = pszXml; if ( NULL != (pszFound=STRSTR(pszNext, pszT))) { //<ct><id>3</id></ct> SPRINTF(pszT, "</%s>", pszTag); char *pszEndTag=NULL; pszEndTag=STRSTR(pszFound, pszT); if ( NULL==pszEndTag ) return false; int nLen=0; SPRINTF(pszT, "<%s>", pszTag); int nTagLen = STRLEN(pszT); nLen = STRLEN(pszFound)-STRLEN(pszEndTag)-nTagLen; // len of <id>3 if ( nLen>0 ) { *pszValue = (char*)MALLOC((nLen+1)*sizeof(AECHAR)); if (NULL==(*pszValue)) return false; STRLCPY(*pszValue, pszFound+nTagLen, nLen+1); DBGPRINTF(*pszValue); } } return true; }
static ElementType *FindText(const ElementType *SC,const CHAR_TYPE *text) { ElementType *result = NULL; size_t i; for (i=0; i<SC->count;i++) { if (STRSTR(SC->contents[i],text)) { if (result == NULL) { result = iElementType.Create(sizeof(size_t)); if (result == NULL) return NULL; } if (iElementType.Add(result,SC->contents[i]) <= 0) break; } } return result; }
static Vector *FindTextIndex(const ElementType *SC,const CHAR_TYPE *text) { Vector *result = NULL; size_t i; for (i=0; i<SC->count;i++) { if (STRSTR(SC->contents[i],text)) { if (result == NULL) { result = iVector.Create(sizeof(size_t),10); if (result == NULL) return NULL; } if (iVector.Add(result,SC->contents[i]) <= 0) break; } } return result; }
ACLStr ACLStr::StripWord(IN const ACLStr& strToStrip) { ACLStr newString; if (strToStrip.Len()) { size_t lenStrToStrip(strToStrip.Len()); LPTSTR strBuffer(_string); LPTSTR findString(NULL); while ((findString = STRSTR(strBuffer, (LPCTSTR)strToStrip))) { newString.Append(strBuffer, (findString - strBuffer)); strBuffer = (findString + lenStrToStrip); } if (strBuffer) newString.Append(strBuffer); } return newString; } // StripWord
int cseq(char *message) { char *cseq; int num=-1; cseq=STRSTR(message, CSEQ_STR); if (cseq) { cseq+=6; num=atoi(cseq); if (num < 1) { if (verbose > 2) printf("CSeq found but not convertable\n"); return 0; } return num; } if (verbose > 2) printf("no CSeq found\n"); return 0; }
static Vector *FindTextPositions(const ElementType *SC,const CHAR_TYPE *text) { Vector *result = NULL; CHAR_TYPE *p; size_t i,idx; for (i=0; i<SC->count;i++) { if (NULL != (p=STRSTR(SC->contents[i],text))) { if (result == NULL) { result = iVector.Create(sizeof(size_t),10); if (result == NULL) return NULL; } idx = p - SC->contents[i]; if (iVector.Add(result,&i) <= 0) break; if (iVector.Add(result,&idx) <=0) break; } } return result; }
int ACLStr::Find(IN LPCTSTR toFind) { LPTSTR string = NULL; TCHAR internalBuffer[MAX_STRING]; // If there is a string to look at... if (toFind) { TCHAR upperFind[MAX_STRING]; CLEANSTRING(upperFind); CLEANSTRING(internalBuffer); // First create a couple of temporary upper case buffers. _UpperCase(toFind, upperFind, MAX_STRING, internalBuffer, MAX_STRING); // Go look for the starting poin of the string. // if we do NOT find it return STR_NOTFOUND string = STRSTR(internalBuffer, upperFind); } return (NULL == string) ? STR_NOTFOUND : (int)(string - internalBuffer); } // ::Find.
//##ModelId=474D306202C0 HINSTANCE CHyperLink::GotoURL(LPCTSTR url, int showcmd) { TCHAR key[MAX_PATH + MAX_PATH]; // First try ShellExecute() HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd); // If it failed, get the .htm regkey and lookup the program if ((UINT)result <= HINSTANCE_ERROR) { if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS) { lstrcat(key, _T("\\shell\\open\\command")); if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) { TCHAR *pos; pos = _tcsstr(key, _T("\"%1\"")); if (pos == NULL) { // No quotes found pos = STRSTR(key, _T("%1")); // Check for %1, without quotes if (pos == NULL) // No parameter at all... pos = key+lstrlen(key)-1; else *pos = '\0'; // Remove the parameter } else *pos = '\0'; // Remove the parameter lstrcat(pos, _T(" ")); lstrcat(pos, url); CStringA keyA = CTextConvert::ConvertToChar(key); result = (HINSTANCE)WinExec(keyA, showcmd); } } } return result; }
/* replaces the uri in first line of mes with the other uri */ void uri_replace(char *mes, char *uri) { char *foo, *backup; foo=strchr(mes, '\n'); if (!foo) { printf("failed to find newline\n"); exit_code(254); } foo++; backup=malloc(strlen(foo)+1); if (!backup) { printf("failed to allocate memory\n"); exit_code(255); } strncpy(backup, foo, strlen(foo)+1); foo=STRSTR(mes, "sip"); strncpy(foo, uri, strlen(uri)); strncpy(foo+strlen(uri), SIP20_STR, SIP20_STR_LEN); strncpy(foo+strlen(uri)+SIP20_STR_LEN, backup, strlen(backup)+1); free(backup); if (verbose > 2) printf("Message with modified uri:\n%s\n", mes); }
void GetOptions(char**& argv, int& i) { char* p, *ps; char c[LINEMAX]; while (argv[i] && *argv[i] == '-') { if (*(argv[i] + 1) == '-') { p = argv[i++] + 2; } else { p = argv[i++] + 1; } memset(c, 0, LINEMAX); //todo ps = STRSTR(p, "="); if (ps != NULL) { STRNCPY(c, LINEMAX, p, (int)(ps - p)); } else { STRCPY(c, LINEMAX, p); } if (!strcmp(c, "lstlab")) { AddLabelListing = 1; } else if (!strcmp(c, "help")) { // nothing } else if (!strcmp(c, "sym")) { if ((ps)&&(ps+1)) { STRCPY(SymbolListFName, LINEMAX, ps+1); } else { _COUT "No parameters found in " _CMDL argv[i-1] _ENDL; } } else if (!strcmp(c, "lst")) { if ((ps)&&(ps+1)) { STRCPY(ListingFName, LINEMAX, ps+1); } else { _COUT "No parameters found in " _CMDL argv[i-1] _ENDL; } } else if (!strcmp(c, "exp")) { if ((ps)&&(ps+1)) { STRCPY(ExportFName, LINEMAX, ps+1); } else { _COUT "No parameters found in " _CMDL argv[i-1] _ENDL; } /*} else if (!strcmp(c, "zxlab")) { if (ps+1) { STRCPY(UnrealLabelListFName, LINEMAX, ps+1); } else { _COUT "No parameters found in " _CMDL argv[i] _ENDL; }*/ } else if (!strcmp(c, "raw")) { if ((ps)&&(ps+1)) { STRCPY(RAWFName, LINEMAX, ps+1); } else { _COUT "No parameters found in " _CMDL argv[i-1] _ENDL; } } else if (!strcmp(c, "fullpath")) { IsShowFullPath = 1; } else if (!strcmp(c, "reversepop")) { IsReversePOP = 1; } else if (!strcmp(c, "nologo")) { HideLogo = 1; } else if (!strcmp(c, "dos866")) { ConvertEncoding = ENCDOS; } else if (!strcmp(c, "dirbol")) { IsPseudoOpBOF = 1; } else if (!strcmp(c, "inc")) { if ((ps)&&(ps+1)) { IncludeDirsList = new CStringsList(ps+1, IncludeDirsList); } else { _COUT "No parameters found in " _CMDL argv[i-1] _ENDL; } } else if (*p == 'i' || *p == 'I') { IncludeDirsList = new CStringsList(p+1, IncludeDirsList); } else { _COUT "Unrecognized option: " _CMDL c _ENDL; } } }
bool CContactInfo::SetMultiValue(AECHAR **pwsValue, char *pszXml, char *pszMultiTag, char *pszSingleTag) { FREEIF(*pwsValue); char *pszData=NULL; if ( !SetValue(&pszData, pszXml, pszMultiTag)) return false; //<emls><eml>[email protected]</eml><eml>[email protected]</eml></emls> if ( NULL!=pszData ) { //create a temporary buffer char *pszTmp = (char*)MALLOC(STRLEN(pszData));//need to change this 100 add. we r adding null characters at the end of each if ( NULL==pszTmp ) return false; char pszT[20]; SPRINTF(pszT, "<%s>", pszSingleTag); AECHAR pwzNewTag[]=NEW_FIELD; char pszNewtag[10]; SPRINTF(pszNewtag, "%S", pwzNewTag); char *pszFound=NULL; char *pszNext = pszData; bool bCount=false; int nBufLen=0; while ( NULL != (pszFound=STRSTR(pszNext, pszT))) { if ( bCount ) { //add null charachter at the end //STRCAT(pszTmp, "\0"); //add new tag STRCAT(pszTmp, pszNewtag); } bCount = true; //find the end position SPRINTF(pszT, "</%s>", pszSingleTag); char *pszEndTag=NULL; pszEndTag=STRSTR(pszFound, pszT); if ( NULL==pszEndTag ) return false; int nLen=0; SPRINTF(pszT, "<%s>", pszSingleTag); int nTagLen = STRLEN(pszT); nLen = STRLEN(pszFound)-STRLEN(pszEndTag)-nTagLen; // len of <id>3 nBufLen = STRLEN(pszTmp); STRLCAT(pszTmp+nBufLen, pszFound+nTagLen, nLen+1); nBufLen = STRLEN(pszTmp); pszNext = pszFound+1; } DBGPRINTF(pszTmp); nBufLen = STRLEN(pszTmp); //convert and copy to return buffer *pwsValue = (AECHAR*)MALLOC((nBufLen+1)*sizeof(AECHAR)); if ( NULL==(*pwsValue) ) { FREEIF(pszData); FREEIF(pszTmp); return false; } STRTOWSTR(pszTmp, *pwsValue, (nBufLen+1)*sizeof(AECHAR)); FREEIF(pszData); FREEIF(pszTmp); } return true; }
void CContactInfo::FillMultiField(AEEAddrField *pField, int &nPos, AECHAR *pwzName, AEEAddrFieldID type) { // pwzName = [email protected]<NEW>[email protected] if (NULL==pwzName ) return; AECHAR pwzNewTag[]=NEW_FIELD; char pszNewtag[10]; SPRINTF(pszNewtag, "%S", pwzNewTag); int nTagLen = STRLEN(pszNewtag); char *pszTmp=NULL; int nLen=WSTRLEN(pwzName); pszTmp = (char*)MALLOC(nLen+1); if ( NULL==pszTmp ) return; WSTRTOSTR(pwzName, pszTmp, nLen+1); char *pNext=pszTmp; char *pFound=NULL; char *pValue=NULL; char *pEnd=NULL; int nValueLen =0; int nBufferPos=0; pValue = pNext; DBGPRINTF("%s", pValue); while ( NULL!=(pFound=STRSTR(pNext, pszNewtag))) { pField[nPos].fID = type; pField[nPos].fType = AEEDB_FT_STRING; nBufferPos = STRLEN(pszTmp)-STRLEN(pValue); pField[nPos].pBuffer = pwzName+ nBufferPos; //value lenth nValueLen = STRLEN(pValue)-STRLEN(pFound); DBGPRINTF("%s", pValue); pField[nPos].wDataLen = (nValueLen+1)*sizeof(AECHAR); nPos++; pNext = pFound+1; pValue = pFound+ nTagLen; } DBGPRINTF("%s", pValue); pField[nPos].fID = type; pField[nPos].fType = AEEDB_FT_STRING; nBufferPos = STRLEN(pszTmp)-STRLEN(pValue); pField[nPos].pBuffer = pwzName+ nBufferPos; nValueLen=STRLEN(pValue); pField[nPos].wDataLen = (nValueLen+1)*sizeof(AECHAR); nPos++; FREEIF(pszTmp); AECHAR *pwzSart=pwzName; AECHAR *pwzEnd=NULL; AECHAR pwzNull = '\0'; while ( NULL!=(pwzEnd=WSTRCHR(pwzSart, '<'))) { *pwzEnd='\0'; pwzSart = pwzEnd+4; } }
int main(int argc, char *argv[]) { FILE *pf; char buff[BUFSIZE]; int length, c, i, j; char *delim, *delim2; pid_t pid; struct timespec ts; int upp; #ifdef HAVE_GETOPT_LONG int option_index = 0; static struct option l_opts[] = { {"help", 0, 0, 'X'}, {"version", 0, 0, 'V'}, {"filename", 1, 0, 'f'}, {"sip-uri", 1, 0, 's'}, {"traceroute-mode", 0, 0, 'T'}, {"usrloc-mode", 0, 0, 'U'}, {"invite-mode", 0, 0, 'I'}, {"message-mode", 0, 0, 'M'}, {"contact", 1, 0, 'C'}, {"appendix-begin", 1, 0, 'b'}, {"appendix-end", 1, 0, 'e'}, {"sleep", 1, 0, 'o'}, {"expires", 1, 0, 'x'}, {"remove-bindings", 0, 0, 'z'}, {"flood-mode", 0, 0, 'F'}, {"cseq-max", 1, 0, 'c'}, {"random-mode", 0, 0, 'R'}, {"trash-chars", 1, 0, 't'}, {"local-port", 1, 0, 'l'}, {"remote-port", 1, 0, 'r'}, {"outbound-proxy", 1, 0, 'p'}, {"hostname", 1, 0, 'H'}, {"max-fowards", 1, 0, 'm'}, {"numeric", 0, 0, 'n'}, {"no-via", 0, 0, 'i'}, {"password", 1, 0, 'a'}, {"ignore-redirects", 0, 0, 'd'}, {"verbose", 0, 0, 'v'}, {"extract-ip", 0, 0, 'w'}, {"replace-string", 0, 0, 'g'}, {"replace", 0, 0, 'G'}, {"nagios-code", 0, 0, 'N'}, {"nagios-warn", 1, 0, 'W'}, {"search", 1, 0, 'q'}, {"message-body", 1, 0, 'B'}, {"disposition", 1, 0, 'O'}, {"processes", 1, 0, 'P'}, {"auth-username", 1, 0, 'u'}, {"no-crlf", 0, 0, 'L'}, {"timing", 0, 0, 'A'}, {0, 0, 0, 0} }; #endif /* some initialisation to be shure */ file_b=uri_b=trace=lport=usrloc=flood=verbose=randtrash=trashchar = 0; warning_ext=rand_rem=nonce_count=replace_b=invite=message = 0; sleep_ms=empty_contact=nagios_warn=timing = 0; namebeg=nameend=maxforw= -1; numeric=via_ins=redirects=fix_crlf=processes = 1; username=password=replace_str=hostname=contact_uri=mes_body = NULL; con_dis=auth_username = NULL; re = NULL; address = 0; rport = 5060; expires_t = USRLOC_EXP_DEF; memset(buff, 0, BUFSIZE); memset(confirm, 0, BUFSIZE); memset(ack, 0, BUFSIZE); memset(fqdn, 0, FQDN_SIZE); memset(messusern, 0, FQDN_SIZE); if (argc==1) print_help(); /* lots of command line switches to handle*/ #ifdef HAVE_GETOPT_LONG while ((c=getopt_long(argc, argv, "a:AB:b:c:C:de:f:Fg:GhH:iIl:Lm:MnNo:O:p:P:q:r:Rs:t:Tu:UvVwW:x:z", l_opts, &option_index)) != EOF){ #else while ((c=getopt(argc,argv,"a:AB:b:c:C:de:f:Fg:GhH:iIl:Lm:MnNo:O:p:P:q:r:Rs:t:Tu:UvVwW:x:z")) != EOF){ #endif switch(c){ case 'a': password=malloc(strlen(optarg)); strncpy(password, optarg, strlen(optarg)); *(password+strlen(optarg)) = '\0'; break; case 'A': timing=1; break; case 'b': if ((namebeg=atoi(optarg))==-1) { printf("error: non-numerical appendix begin for the " "username\n"); exit_code(2); } break; case 'B': mes_body=malloc(strlen(optarg)); strncpy(mes_body, optarg, strlen(optarg)); *(mes_body+strlen(optarg)) = '\0'; break; case 'C': if (!strncmp(optarg, "empty", 5) || !strncmp(optarg, "none", 4)) { empty_contact = 1; } else if (((delim=STRSTR(optarg,"sip:"))!=NULL) || ((delim=STRSTR(optarg,"sips:"))!=NULL)) { if (strchr(optarg,'@')<delim) { printf("error: missing '@' in Contact uri\n"); exit_code(2); } else { contact_uri=malloc(strlen(optarg)+1); memset(contact_uri, 0, strlen(optarg)+1); strncpy(contact_uri, optarg, strlen(optarg)); } } else if ((strlen(optarg)==1) && (!strncmp(optarg, "*", 1))) { contact_uri=malloc(strlen(optarg)+1); memset(contact_uri, 0, strlen(optarg)+1); strncpy(contact_uri, optarg, strlen(optarg)); } else{ printf("error: REGISTER Contact uri doesn't not contain " "sip:, *, or is not empty\n"); exit_code(2); } break; case 'c': if ((namebeg=atoi(optarg))==-1) { printf("error: non-numerical CSeq maximum\n"); exit_code(2); } break; case 'd': redirects=0; break; case 'e': if ((nameend=atoi(optarg))==-1) { printf("error: non-numerical appendix end for the " "username\n"); exit_code(2); } break; case 'F': flood=1; break; case 'f': if (strncmp(optarg, "-", 1)) { /* file is opened in binary mode so that the cr-lf is preserved */ pf = fopen(optarg, "rb"); if (!pf){ printf("error: unable to open the file '%s'.\n", optarg); exit_code(2); } length = fread(buff, 1, sizeof(buff), pf); if (length >= sizeof(buff)){ printf("error:the file is too big. try files of less " "than %i bytes.\n", BUFSIZE); printf(" or recompile the program with bigger " "BUFSIZE defined.\n"); exit_code(2); } fclose(pf); } else { for(i = 0; i < BUFSIZE - 1; i++) { j = getchar(); if (j == EOF) break; else buff[i] = j; } length = i; } buff[length] = '\0'; file_b=1; break; case 'g': replace_str=optarg; break; case 'G': replace_b=1; break; case 'h': print_help(); break; case 'H': hostname=optarg; break; case 'i': via_ins=0; break; case 'I': invite=1; break; case 'l': lport=atoi(optarg); if (!lport) { printf("error: non-numerical local port number"); exit_code(2); } break; case 'L': fix_crlf=0; break; case 'm': maxforw=atoi(optarg); if (maxforw==-1) { printf("error: non-numerical number of max-forwards\n"); exit_code(2); } break; case 'M': message=1; break; case 'n': numeric = 0; break; case 'N': exit_mode=EM_NAGIOS; break; case 'o': sleep_ms = 0; if (strncmp(optarg, "rand", 4)==0) { sleep_ms = -2; } else { sleep_ms = atoi(optarg); if (!sleep_ms) { printf("error: non-numerical sleep value\n"); exit_code(2); } } break; case 'O': con_dis=malloc(strlen(optarg)); strncpy(con_dis, optarg, strlen(optarg)); *(con_dis+strlen(optarg)) = '\0'; break; case 'p': address = getaddress(optarg); break; case 'P': processes=atoi(optarg); if (!processes) { printf("error: non-numerical number of processes\n"); exit_code(2); } break; case 'q': if (re) { /* previously allocated -- free */ regfree(re); } else { /* never tried -- allocate */ re=malloc(sizeof(regex_t)); }; if (!re) { fprintf(stderr, "Error: can't allocate RE\n"); exit_code(2); }; if (regcomp(re, optarg, REG_EXTENDED|REG_ICASE|REG_NEWLINE )!=0) { fprintf(stderr, "Error: compiling RE: %s\n", optarg ); exit_code(2); }; break; case 'r': rport=atoi(optarg); if (!rport) { printf("error: non-numerical remote port number\n"); exit_code(2); } break; case 'R': randtrash=1; break; case 's': /* we try to extract as much informationas we can from the uri*/ if (!strncmp(optarg,"sip",3)){ if ((delim=strchr(optarg,':'))!=NULL){ delim++; if ((delim2=strchr(delim,'@'))!=NULL){ username=malloc(delim2-delim+1); strncpy(username, delim, delim2-delim); *(username+(delim2-delim)) = '\0'; delim2++; delim=delim2; } if ((delim2=strchr(delim,':'))!=NULL){ domainname=malloc(strlen(delim)+1); strncpy(domainname, delim, strlen(delim)); *(domainname+strlen(delim)) = '\0'; *delim2 = '\0'; delim2++; rport = atoi(delim2); if (!rport) { printf("error: non-numerical remote port " "number\n"); exit_code(2); } } else { domainname=malloc(strlen(delim)+1); strncpy(domainname, delim, strlen(delim)); *(domainname+strlen(delim)) = '\0'; } if (!address) address = getaddress(delim); if (!address){ printf("error:unable to determine the remote host " "address\n"); exit_code(2); } } else{ printf("error: SIPURI doesn't contain a : ?!\n"); exit_code(2); } } else{ printf("error: SIPURI doesn't not begin with sip\n"); exit_code(2); } uri_b=1; break; break; case 't': trashchar=atoi(optarg); if (!trashchar) { printf("error: non-numerical number of trashed " "character\n"); exit_code(2); } break; case 'T': trace=1; break; case 'U': usrloc=1; break; case 'u': auth_username=malloc(strlen(optarg)); strncpy(auth_username, optarg, strlen(optarg)); *(auth_username+strlen(optarg)) = '\0'; break; case 'v': verbose++; break; case 'V': printf("sipsak %s by Nils Ohlmeier\n Copyright (C) 2002-2004" " FhG Fokus\n Copyright (C) 2004-2005 Nils Ohlmeier\n", SIPSAK_VERSION); printf(" compiled with DEFAULT_RETRYS=%i, DEFAULT_TIMEOUT=%i, FQDN_SIZE=%i", DEFAULT_RETRYS, DEFAULT_TIMEOUT, FQDN_SIZE); #ifdef RAW_SUPPORT printf(", RAW_SUPPORT"); #endif #ifdef HAVE_GETOPT_LONG printf(", LONG_OPTS"); #endif printf("\n"); exit_code(0); break; case 'w': warning_ext=1; break; case 'W': nagios_warn = atoi(optarg); break; case 'x': expires_t=atoi(optarg); break; #ifdef HAVE_GETOPT_LONG case 'X': print_long_help(); break; #endif case 'z': rand_rem=1; break; default: printf("error: unknown parameter %c\n", c); exit_code(2); break; } } /* replace LF with CRLF if we read from a file */ if ((file_b) && (fix_crlf)) { insert_cr(buff); } /* lots of conditions to check */ if (trace) { if (usrloc || flood || randtrash) { printf("error: trace can't be combined with usrloc, random or " "flood\n"); exit_code(2); } if (!uri_b) { printf("error: for trace mode a SIPURI is realy needed\n"); exit_code(2); } if (file_b) { printf("warning: file will be ignored for tracing."); } if (!username) { printf("error: for trace mode without a file the SIPURI have to " "contain a username\n"); exit_code(2); } if (!via_ins){ printf("warning: Via-Line is needed for tracing. Ignoring -i\n"); via_ins=1; } if (!warning_ext) { printf("warning: IP extract from warning activated to be more " "informational\n"); warning_ext=1; } if (maxforw==-1) maxforw=255; } else if (usrloc || invite || message) { if (trace || flood || randtrash) { printf("error: usrloc can't be combined with trace, random or " "flood\n"); exit_code(2); } if (!username || !uri_b) { printf("error: for the USRLOC mode you have to give a SIPURI with " "a username\n at least\n"); exit_code(2); } if (namebeg>0 && nameend==-1) { printf("error: if a starting numbers is given also an ending " "number have to be specified\n"); exit_code(2); } if (invite && message) { printf("error: invite and message tests are XOR\n"); exit_code(2); } if (!usrloc && invite && !lport) { printf("WARNING: Do NOT use the usrloc invite mode without " "registering sipsak before.\n See man page for " "details.\n"); exit_code(2); } if (contact_uri!=NULL) { if (invite || message) { printf("error: Contact uri is not support for invites or " "messages\n"); exit_code(2); } if (nameend!=-1 || namebeg!=-1) { printf("warning: ignoring starting or ending number if Contact" " is given\n"); nameend=namebeg=0; } if (rand_rem) { printf("warning: ignoring -z option when Contact is given\n"); rand_rem=0; } } if (via_ins) { printf("warning: ignoring -i option when in usrloc mode\n"); via_ins=0; } if (nameend==-1) nameend=0; if (namebeg==-1) namebeg=0; } else if (flood) { if (trace || usrloc || randtrash) { printf("error: flood can't be combined with trace, random or " "usrloc\n"); exit_code(2); } if (!uri_b) { printf("error: we need at least a sip uri for flood\n"); exit_code(2); } if (redirects) { printf("warning: redirects are not expected in flood. " "disableing\n"); redirects=0; } } else if (randtrash) { if (trace || usrloc || flood) { printf("error: random can't be combined with trace, flood or " "usrloc\n"); exit_code(2); } if (!uri_b) { printf("error: need at least a sip uri for random\n"); exit_code(2); } if (redirects) { printf("warning: redirects are not expected in random. " "disableing\n"); redirects=0; } if (verbose) { printf("warning: random characters may destroy your terminal " "output\n"); } } else if (mes_body) { if (!message) { printf("warning: to send a message mode (-M) is required. activating\n"); message=1; } if (!uri_b) { printf("error: need at least a sip uri to send a meesage\n"); exit_code(2); } if (nameend==-1) nameend=0; if (namebeg==-1) namebeg=0; } else { if (!uri_b) { printf("error: a spi uri is needed at least\n"); exit_code(2); } } /* determine our hostname */ get_fqdn(); /* this is not a cryptographic random number generator, but hey this is only a test-tool => should be satisfying*/ srand(time(0)); if (processes > 1) { if (signal(SIGCHLD , sigchld_handler) == SIG_ERR ) { printf("error: Could not install SIGCHLD handler\n"); exit_code(2); } } for(i = 0; i < processes - 1; i++) { if ((pid = fork()) < 0) { printf("error: Cannot fork\n"); exit_code(2); } if (pid == 0){ /* child */ upp = (nameend - namebeg + 1) / processes; namebeg = namebeg + upp * i; nameend = namebeg + upp; shoot(buff); } else { if (lport) { lport++; } } /* Delay execution of children so that the * time of the first transmission gets spread over * the retransmission interval evenly */ ts.tv_sec = 0; ts.tv_nsec = (float)DEFAULT_TIMEOUT / (float)processes * (float)1000 * (float)1000; nanosleep(&ts, 0); } /* here we go...*/ if (processes > 1) { upp = (nameend - namebeg + 1) / processes; namebeg = namebeg + upp * i; nameend = namebeg + upp; } shoot(buff); /* normaly we won't come back here, but to satisfy the compiler */ return 0; }
/*======================================================================= Function: Loc_ReadGPSSettings() Description: Reads the GPS configuration settings from the configuration file. =======================================================================*/ static uint32 Loc_ReadGPSSettings(IFile * pIFile, AEEGPSConfig *gpsConfig) { char *pszBuf = NULL; char *pszTok = NULL; char *pszSvr = NULL; char *pszDelimiter = ";"; int32 nResult = 0; FileInfo fiInfo; if (pIFile == NULL || gpsConfig == NULL) return EFAILED; if ( SUCCESS != IFILE_GetInfo( pIFile, &fiInfo ) ) { return EFAILED; } if ( fiInfo.dwSize == 0 ) { return EFAILED; } // Allocate enough memory to read the full text into memory pszBuf = MALLOC( fiInfo.dwSize ); nResult = IFILE_Read( pIFile, pszBuf, fiInfo.dwSize ); if ( (uint32)nResult < fiInfo.dwSize ) { FREE( pszBuf ); return EFAILED; } // Check for an optimization mode setting in the file: pszTok = STRSTR( pszBuf, LOC_CONFIG_OPT_STRING ); if ( pszTok ) { pszTok = pszTok + STRLEN( LOC_CONFIG_OPT_STRING ); gpsConfig->optim = (AEEGPSOpt)STRTOUL( pszTok, &pszDelimiter, 10 ); } // Check for a QoS setting in the file: pszTok = STRSTR( pszBuf, LOC_CONFIG_QOS_STRING ); if ( pszTok ) { pszTok = pszTok + STRLEN( LOC_CONFIG_QOS_STRING ); gpsConfig->qos = (AEEGPSQos)STRTOUL( pszTok, &pszDelimiter, 10 ); } // Check for a server type setting in the file: pszTok = STRSTR( pszBuf, LOC_CONFIG_SVR_TYPE_STRING ); if ( pszTok ) { pszTok = pszTok + STRLEN( LOC_CONFIG_SVR_TYPE_STRING ); gpsConfig->server.svrType = STRTOUL( pszTok, &pszDelimiter, 10 ); // If the server type is IP, we need to find the ip address and the port number if ( AEEGPS_SERVER_IP == gpsConfig->server.svrType ) { pszTok = STRSTR( pszBuf, LOC_CONFIG_SVR_IP_STRING ); if ( pszTok ) { pszTok = pszTok + STRLEN( LOC_CONFIG_SVR_IP_STRING ); nResult = DistToSemi( pszTok ); pszSvr = MALLOC( nResult+1 ); STRNCPY( pszSvr, pszTok, nResult ); *(pszSvr+nResult) = 0; // Need to manually NULL-terminate the string if ( !INET_ATON( pszSvr, &gpsConfig->server.svr.ipsvr.addr ) ) { FREE( pszBuf ); FREE( pszSvr ); return EFAILED; } FREE( pszSvr ); } pszTok = STRSTR( pszBuf, LOC_CONFIG_SVR_PORT_STRING ); if ( pszTok ) { pszTok = pszTok + STRLEN( LOC_CONFIG_SVR_PORT_STRING ); gpsConfig->server.svr.ipsvr.port = AEE_htons((INPort)STRTOUL( pszTok, &pszDelimiter, 10 )); } } } FREE( pszBuf ); return SUCCESS; }