/* Search for a module "filename" in the modulePath. Return the result in "result" */ PUBLIC char *mprSearchForModule(cchar *filename) { #if ME_COMPILER_HAS_DYN_LOAD char *path, *f, *searchPath, *dir, *tok; filename = mprNormalizePath(filename); /* Search for the path directly */ if ((path = probe(filename)) != 0) { return path; } /* Search in the searchPath */ searchPath = sclone(mprGetModuleSearchPath()); tok = 0; dir = stok(searchPath, MPR_SEARCH_SEP, &tok); while (dir && *dir) { f = mprJoinPath(dir, filename); if ((path = probe(f)) != 0) { return path; } dir = stok(0, MPR_SEARCH_SEP, &tok); } #endif /* ME_COMPILER_HAS_DYN_LOAD */ return 0; }
PUBLIC int httpParsePlatform(cchar *platform, cchar **osp, cchar **archp, cchar **profilep) { char *arch, *os, *profile, *rest; if (osp) { *osp = 0; } if (archp) { *archp = 0; } if (profilep) { *profilep = 0; } if (platform == 0 || *platform == '\0') { return MPR_ERR_BAD_ARGS; } os = stok(sclone(platform), "-", &rest); arch = sclone(stok(NULL, "-", &rest)); profile = sclone(rest); if (os == 0 || arch == 0 || profile == 0 || *os == '\0' || *arch == '\0' || *profile == '\0') { return MPR_ERR_BAD_ARGS; } if (osp) { *osp = os; } if (archp) { *archp = arch; } if (profilep) { *profilep = profile; } return 0; }
/* Search for a module "filename" in the modulePath. Return the result in "result" */ char *mprSearchForModule(cchar *filename) { #if BIT_HAS_DYN_LOAD char *path, *f, *searchPath, *dir, *tok; filename = mprNormalizePath(filename); /* Search for the path directly */ if ((path = probe(filename)) != 0) { mprLog(6, "Found native module %s at %s", filename, path); return path; } /* Search in the searchPath */ searchPath = sclone(mprGetModuleSearchPath()); tok = 0; dir = stok(searchPath, MPR_SEARCH_SEP, &tok); while (dir && *dir) { f = mprJoinPath(dir, filename); if ((path = probe(f)) != 0) { mprLog(6, "Found native module %s at %s", filename, path); return path; } dir = stok(0, MPR_SEARCH_SEP, &tok); } #endif /* BIT_HAS_DYN_LOAD */ return 0; }
static void computeUserAbilities(WebsUser *user) { char *ability, *roles, *tok; assure(user); if ((user->abilities = hashCreate(-1)) == 0) { return; } roles = sclone(user->roles); for (ability = stok(roles, " \t,", &tok); ability; ability = stok(NULL, " \t,", &tok)) { computeAbilities(user->abilities, ability, 0); } #if BIT_DEBUG { WebsKey *key; trace(5, "User \"%s\" has abilities: ", user->name); for (key = hashFirst(user->abilities); key; key = hashNext(user->abilities, key)) { trace(5, "%s ", key->name.value.string); ability = key->name.value.string; } trace(5, "\n"); } #endif wfree(roles); }
int main() { setlocale(LC_ALL, "Russian"); char StringEntered[] = "192.168.10.2:home/OpenMPI/MPicc.exe"; char *Links[10]; // Массив указателей на подстроки из String; char *IPLinks[4]; // Массив указателей на подстроки IP-адреса; char DelimeterPath = ':'; // Разделитель для пути; char DelimeterIP = '.'; // Разделитель для IP; int QuantityOfSubStrings; int QuantityOfIPSubStrings; int SCPCorrect; int IPCorrect; int index; QuantityOfSubStrings = stok(StringEntered, DelimeterPath, Links); QuantityOfSubStrings = stok(Links[0], DelimeterIP, IPLinks); IPCorrect = IPChecking(IPLinks); printf("Количество подстрок: %d", QuantityOfSubStrings); printf("Количество подстрок IP: %d", QuantityOfIPSubStrings); SCPCorrect = SCPChecking(IPLinks[0]); if(SCPCorrect == 1) printf("Протокол SCP некорректен"); if(IPCorrect == -1) printf("IP неверен\n"); return 0; }
/* Can supply a roles or abilities in the "abilities" parameter */ PUBLIC void httpSetAuthRequiredAbilities(HttpAuth *auth, cchar *abilities) { char *ability, *tok; GRADUATE_HASH(auth, abilities); for (ability = stok(sclone(abilities), " \t,", &tok); abilities; abilities = stok(NULL, " \t,", &tok)) { httpComputeRoleAbilities(auth, auth->abilities, ability); } }
static void addFormVars(cchar *buf) { char *pair, *tok; pair = stok(sclone(buf), "&", &tok); while (pair != 0) { mprAddItem(app->formData, sclone(pair)); pair = stok(0, "&", &tok); } }
static void parseQuery(HttpConn *conn) { HttpRx *rx; HttpDir *dir; char *value, *query, *next, *tok, *field; rx = conn->rx; dir = conn->reqData; query = sclone(rx->parsedUri->query); if (query == 0) { return; } tok = stok(query, ";&", &next); while (tok) { if ((value = strchr(tok, '=')) != 0) { *value++ = '\0'; if (*tok == 'C') { /* Sort column */ field = 0; if (*value == 'N') { field = "Name"; } else if (*value == 'M') { field = "Date"; } else if (*value == 'S') { field = "Size"; } if (field) { dir->sortField = sclone(field); } } else if (*tok == 'O') { /* Sort order */ if (*value == 'A') { dir->sortOrder = 1; } else if (*value == 'D') { dir->sortOrder = -1; } } else if (*tok == 'F') { /* Format */ if (*value == '0') { dir->fancyIndexing = 0; } else if (*value == '1') { dir->fancyIndexing = 1; } else if (*value == '2') { dir->fancyIndexing = 2; } } else if (*tok == 'P') { /* Pattern */ dir->pattern = sclone(value); } } tok = stok(next, ";&", &next); } }
static int parseDigestNonce(char *nonce, cchar **secret, cchar **realm, MprTime *when) { char *tok, *decoded, *whenStr; if ((decoded = mprDecode64(nonce)) == 0) { return MPR_ERR_CANT_READ; } *secret = stok(decoded, ":", &tok); *realm = stok(NULL, ":", &tok); whenStr = stok(NULL, ":", &tok); *when = (MprTime) stoiradix(whenStr, 16, NULL); return 0; }
/* Can also achieve this via abilities */ PUBLIC void httpSetAuthPermittedUsers(HttpAuth *auth, cchar *users) { char *user, *tok; GRADUATE_HASH(auth, permittedUsers); for (user = stok(sclone(users), " \t,", &tok); users; users = stok(NULL, " \t,", &tok)) { if (smatch(user, "*")) { auth->permittedUsers = 0; break; } else { mprAddKey(auth->permittedUsers, user, user); } } }
/* Options Indexes */ static int optionsDirective(MaState *state, cchar *key, cchar *value) { Dir *dir; char *option, *tok; dir = getDirObj(state); option = stok(sclone(value), " \t", &tok); while (option) { if (scaselessmatch(option, "Indexes")) { dir->enabled = 1; } option = stok(tok, " \t", &tok); } return 0; }
/* function get info(): Object */ static EjsObj *http_info(Ejs *ejs, EjsHttp *hp, int argc, EjsObj **argv) { EjsObj *obj; char *key, *next, *value; if (hp->conn && hp->conn->sock) { obj = ejsCreateEmptyPot(ejs); for (key = stok(mprGetSocketState(hp->conn->sock), ",", &next); key; key = stok(NULL, ",", &next)) { stok(key, "=", &value); ejsSetPropertyByName(ejs, obj, EN(key), ejsCreateStringFromAsc(ejs, value)); } return obj; } return ESV(null); }
/* Map iana names to OpenSSL names so users can provide IANA names as well as OpenSSL cipher names */ static char *mapCipherNames(char *ciphers) { WebsBuf buf; CipherMap *cp; char *cipher, *next, *str; if (!ciphers || *ciphers == 0) { return 0; } bufCreate(&buf, 0, 0); ciphers = sclone(ciphers); for (next = ciphers; (cipher = stok(next, ":, \t", &next)) != 0; ) { for (cp = cipherMap; cp->name; cp++) { if (smatch(cp->name, cipher)) { bufPut(&buf, "%s:", cp->ossName); break; } } if (cp->name == 0) { bufPut(&buf, "%s:", cipher); } } wfree(ciphers); str = sclone(bufStart(&buf)); bufFree(&buf); return str; }
void ViewDescriptor::LoadFromExtension() { configElement->GetAttribute(WorkbenchRegistryConstants::ATT_ID, id); // Sanity check. std::string name; if ((configElement->GetAttribute(WorkbenchRegistryConstants::ATT_NAME, name) == false) || (RegistryReader::GetClassValue(configElement, WorkbenchRegistryConstants::ATT_CLASS) == "")) { throw CoreException( "Invalid extension (missing label or class name)", id); } std::string category; if (configElement->GetAttribute(WorkbenchRegistryConstants::TAG_CATEGORY, category)) { Poco::StringTokenizer stok(category, "/", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); // Parse the path tokens and store them for (Poco::StringTokenizer::Iterator iter = stok.begin(); iter != stok.end(); ++iter) { categoryPath.push_back(*iter); } } }
/* Write upload data. This routine blocks. If you need non-blocking ... cut and paste. */ ssize httpWriteUploadData(HttpConn *conn, MprList *fileData, MprList *formData) { char *path, *pair, *key, *value, *name; ssize rc; int next; rc = 0; if (formData) { for (rc = next = 0; rc >= 0 && (pair = mprGetNextItem(formData, &next)) != 0; ) { key = stok(sclone(pair), "=", &value); rc += httpWrite(conn->writeq, "%s\r\nContent-Disposition: form-data; name=\"%s\";\r\n", conn->boundary, key); rc += httpWrite(conn->writeq, "Content-Type: application/x-www-form-urlencoded\r\n\r\n%s\r\n", value); } } if (fileData) { for (rc = next = 0; rc >= 0 && (path = mprGetNextItem(fileData, &next)) != 0; ) { name = mprGetPathBase(path); rc += httpWrite(conn->writeq, "%s\r\nContent-Disposition: form-data; name=\"file%d\"; filename=\"%s\"\r\n", conn->boundary, next - 1, name); rc += httpWrite(conn->writeq, "Content-Type: %s\r\n\r\n", mprLookupMime(MPR->mimeTypes, path)); rc += blockingFileCopy(conn, path); rc += httpWrite(conn->writeq, "\r\n"); } } rc += httpWrite(conn->writeq, "%s--\r\n--", conn->boundary); httpFinalize(conn); return rc; }
int isdomain(char *str) { char d_ru[] = "ru"; char d_com[] = "com"; char d_org[] = "org"; char *EL[MAXSIZE]; int i; if (6 > slen(str)) return 0; int Z = stok(str, '.', EL); if (!((scmp(EL[Z - 1], d_ru) == 0) || (scmp(EL[Z - 1], d_com) == 0) || (scmp(EL[Z - 1], d_org) == 0))) { suntok(str, '.', EL, Z); return 0; } suntok(str, '.', EL, Z); if (3 != Z) return 0; for (i = 0; str[i] != '\0'; i++) { if (!((str[i] >= 'A')&&(str[i] <= 'Z') || ( (str[i] >= 'a')&&(str[i] <= 'z')) || str[i] == '.' )) return 0; } return 1; }
/* Test if the version is acceptable based on the supplied critera. The acceptable formats for criteria are: VER Allows prereleases 1.2.[*xX] Wild card version portion. (allows prereleases). ~VER Compatible with VER at the least significant level. ~1.2.3 == (>=1.2.3 <1.3.0) Compatible at the patch level ~1.2 == 1.2.x Compatible at the minor level ~1 == 1.x Compatible at the major level ^VER Compatible with VER at the most significant level. ^0.2.3 == 0.2.3 <= VER < 0.3.0 ^1.2.3 == 1.2.3 <= VER < 2.0.0 [>, >=, <, <=, ==, !=]VER Create range relative to given version EXPR1 - EXPR2 <=EXPR1 <=EXPR2 EXPR1 || EXPR2 ... EXPR1 OR EXPR2 EXPR1 && EXPR2 ... EXPR1 AND EXPR2 EXPR1 EXPR2 ... EXPR1 AND EXPR2 Pre-release versions will only match if the criteria contains a "-.*" prerelease suffix */ PUBLIC bool mprIsVersionObjAcceptable(MprVersion *vp, cchar *criteria) { char *expr, *exprTok, *range, *rangeTok, *low, *high; bool allMatched; if (!vp->ok) { return 0; } if (!criteria || *criteria == '\0') { return 1; } criteria = cleanVersion(criteria); for (range = (char*) criteria; stok(range, "||", &rangeTok) != 0; range = rangeTok) { range = strim(range, " \t", 0); allMatched = 1; for (expr = (char*) range; sptok(expr, "&&", &exprTok) != 0; expr = exprTok) { if (scontains(expr, " - ")) { low = sptok(expr, " - ", &high); return inRange(vp, sjoin(">=", low, NULL)) && inRange(vp, sjoin("<=", high, NULL)); } if (!inRange(vp, expr)) { allMatched = 0; break; } } if (allMatched) { return 1; } } return 0; }
int main() { int i; char ch[260]; // vremenniy massiv dlya dannih char delim; // razdelitel' printf("Vvedite razdlitel':\n"); scanf("%c", &delim); // razdelitel' printf("Vvedite imya polzovatelya:\n"); scanf("%s", &ch); char *username = (int *)malloc(size_s(ch)*sizeof(int)); // imya polzovatelya for (i=0; i<size_s(ch); i++) username[i]=ch[i]; printf("Vvedite imya domashney direktorii:\n"); scanf("%s", &ch); char *dir = (int *)malloc(size_s(ch)*sizeof(int)); // imya domashnego kataloga for (i=0; i<size_s(ch); i++) dir[i]=ch[i]; printf("Vvedite puti cherez razdeliteli:\n"); scanf("%s", &ch); char *paths = (int *)malloc(size_s(ch)*sizeof(int)); // vhodnaya stroka s putyami for (i=0; i<size_s(ch); i++) paths[i]=ch[i]; //printf("Vvedeno:\n%c\n%s\n%s\n%s\n", delim, username, dir, paths); stok(paths, delim); // zanosim puti v noviy massiv //sspn(paths); return 0; }
int Researcher(char *Str) { int isipv4(char *str) { char *EL[MAXSIZE]; int i, j; if ((7 > slen(str)) || (15 < slen(str))) return 0; int Z = stok(str, '.', EL); if (Z != 4) { suntok(str, '.', EL, Z); return 0; } for (i = 0; i < Z; ++i) { for (j = 0; EL[i][j] != '\0'; ++j) { if (myisdigit(EL[i][j])) continue; else { suntok(str, '.', EL, Z); return 0; } } if (255 < myatoi(EL[i])) { suntok(str, '.', EL, Z); return 0; } } suntok(str, '.', EL, Z); return 1; }
/* Parses out a start/end date spec from a posix time zone string. * Date specs come in three possible formats, this function handles * the 'M' spec. Ex "M2.2.4" => 2nd month, 2nd week, 4th day . */ void M_func(const string_type& s, const string_type& e){ typedef gregorian::nth_kday_of_month nkday; unsigned short sm=0,sw=0,sd=0,em=0,ew=0,ed=0; // start/end month,week,day #ifdef __HP_aCC // Work around bug in aC++ compiler: see QXCR1000880488 in the // HP bug tracking system const char_type sep_chars[3] = {'M','.',0}; #else const char_type sep_chars[3] = {'M','.'}; #endif char_separator_type sep(sep_chars); tokenizer_type stok(s, sep), etok(e, sep); tokenizer_iterator_type it = stok.begin(); sm = lexical_cast<unsigned short>(*it++); sw = lexical_cast<unsigned short>(*it++); sd = lexical_cast<unsigned short>(*it); it = etok.begin(); em = lexical_cast<unsigned short>(*it++); ew = lexical_cast<unsigned short>(*it++); ed = lexical_cast<unsigned short>(*it); dst_calc_rules_ = shared_ptr<dst_calc_rule>( new nth_kday_dst_rule( nth_last_dst_rule::start_rule( static_cast<nkday::week_num>(sw),sd,sm), nth_last_dst_rule::start_rule( static_cast<nkday::week_num>(ew),ed,em) ) ); }
/* Convert queue data in key / value pairs MOB - should be able to remove this and use standard form parsing */ static int getParams(char ***keys, char *buf, int len) { char** keyList; char *eq, *cp, *pp, *tok; int i, keyCount; *keys = 0; /* Change all plus signs back to spaces */ keyCount = (len > 0) ? 1 : 0; for (cp = buf; cp < &buf[len]; cp++) { if (*cp == '+') { *cp = ' '; } else if (*cp == '&' && (cp > buf && cp < &buf[len - 1])) { keyCount++; } } if (keyCount == 0) { return 0; } /* Crack the input into name/value pairs */ keyList = mprAlloc((keyCount * 2) * sizeof(char**)); i = 0; tok = 0; for (pp = stok(buf, "&", &tok); pp; pp = stok(0, "&", &tok)) { if ((eq = strchr(pp, '=')) != 0) { *eq++ = '\0'; pp = mprUriDecode(pp); eq = mprUriDecode(eq); } else { pp = mprUriDecode(pp); eq = 0; } if (i < (keyCount * 2)) { keyList[i++] = pp; keyList[i++] = eq; } } *keys = keyList; return keyCount; }
static int parseDigestNonce(char *nonce, char **secret, char **realm, WebsTime *when) { char *tok, *decoded, *whenStr; assure(nonce && *nonce); assure(secret); assure(realm); assure(when); if ((decoded = websDecode64(nonce)) == 0) { return -1; } *secret = stok(decoded, ":", &tok); *realm = stok(NULL, ":", &tok); whenStr = stok(NULL, ":", &tok); *when = hextoi(whenStr); return 0; }
void process(char *str) { char *ptr[20]; int count; int i; count = stok(str, '/', ptr); suntok(str, '\\', ptr, count); }
/* IndexOptions FancyIndexing|FoldersFirst ... (set of options) */ static int indexOptionsDirective(MaState *state, cchar *key, cchar *value) { Dir *dir; char *option, *tok; dir = getDirObj(state); option = stok(sclone(value), " \t", &tok); while (option) { if (scaselessmatch(option, "FancyIndexing")) { dir->fancyIndexing = 1; } else if (scaselessmatch(option, "HTMLTable")) { dir->fancyIndexing = 2; } else if (scaselessmatch(option, "FoldersFirst")) { dir->foldersFirst = 1; } option = stok(tok, " \t", &tok); } return 0; }
void process(char *path, char *delim) { int count, i; char *subpath[10]; count = stok(path, delim[0], subpath); for (i = 0; i < count; i++) processing(subpath[i]); suntok(path, delim[0], subpath, count); change(path); }
/* Parse cached content of the form: headers \n\n data Set headers in the current requeset and return a reference to the data portion */ static cchar *setHeadersFromCache(HttpConn *conn, cchar *content) { cchar *data; char *header, *headers, *key, *value, *tok; if ((data = strstr(content, "\n\n")) == 0) { data = content; } else { headers = snclone(content, data - content); data += 2; for (header = stok(headers, "\n", &tok); header; header = stok(NULL, "\n", &tok)) { key = stok(header, ": ", &value); if (smatch(key, "X-Status")) { conn->tx->status = (int) stoi(value); } else { httpAddHeader(conn, key, value); } } } return data; }
PUBLIC HttpRole *httpAddRole(HttpAuth *auth, cchar *name, cchar *abilities) { HttpRole *role; char *ability, *tok; GRADUATE_HASH(auth, roles); if ((role = mprLookupKey(auth->roles, name)) == 0) { if ((role = mprAllocObj(HttpRole, manageRole)) == 0) { return 0; } role->name = sclone(name); } role->abilities = mprCreateHash(0, 0); for (ability = stok(sclone(abilities), " \t", &tok); ability; ability = stok(NULL, " \t", &tok)) { mprAddKey(role->abilities, ability, role); } if (mprAddKey(auth->roles, name, role) == 0) { return 0; } return role; }
void check(char *str, char *ptr[], int size) { int t, i, d; if (scspn(str, size) > 0) { printf("Is SCP: no\n"); return; } for(i = 0; (str[i] != '\0'); i++) if(str[i] == ':') d++; if (d == 1) printf("Is SCP: yes\n"); else { printf("Is SCP: no\n"); return; } int j = stok(str, ':', ptr, size); for(i = 0; (str[i] != '\0'); i++) if(str[i] == '.') t++; if (t == 3) { for(i = 0; i < str[i] != '\0'; i++) if((str[i] >= '0' && str[i] <= '9') || (str[i] == '.')) t = 3; else { t = 4; break; } } char *ptr2[228]; int k = stok(str, '.', ptr2, size); isIp(ptr2, size, t); suntok(str, '.', ptr2, k); suntok(str, ':', ptr, j); process(str, size); output(str); }
CTEST(equation_suite, stok_single) { //Given char string[]= "haallo"; char *ptr[1]; stok(string, ptr); char *tmp1 = ptr[0]; //When const int real = tmp1[0]; //Then const int expct = 'h'; ASSERT_EQUAL(real, expct); }
void process(char *pat, char *dir, char del) { char *RAW[MAXSIZE]; char *TOK[MAXSIZE]; char *a; int Z = 0, R = 0, i, j, k, dLEN, pLEN; pLEN = slen(pat); Z = stok(pat, del, RAW); dLEN = slen(dir); if (Z > 10) { printf("%sПо заданию программа не может обработать больше 10 путей%s\n", clBoldRed, clNormal); myexit(); } for (i = 0; i < Z; i++) { R = stok(RAW[i], '/', TOK); for (j = 0; j < R; j++) { if ((j == 0) && (slen(TOK[j]) > 1) && (TOK[j][0] == '~')) { for (a = pat + pLEN; a > TOK[j]; --a) *(a + dLEN) = *a; scpy(TOK[j], dir); *(TOK[j]+dLEN) = '/'; for (k = i + 1; k < Z; k++) RAW[k] += dLEN; for (k = j - 1; k < R; k++) TOK[k] += dLEN; } } suntok(RAW[i], '/', TOK, R); } suntok(pat, del, RAW, Z); return; }