本文整理汇总了C++中smatch函数的典型用法代码示例。如果您正苦于以下问题:C++ smatch函数的具体用法?C++ smatch怎么用?C++ smatch使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了smatch函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: matchRow
static bool matchRow(MdbCol *col, cchar *existing, int op, cchar *value)
{
if (value == 0 || *value == '\0') {
return 0;
}
// MOB - must ensure database NEVER has a null
switch (op) {
case OP_EQ:
if (smatch(existing, value)) {
return 1;
}
break;
case OP_NEQ:
if (!smatch(existing, value)) {
return 1;
}
break;
#if MOB && TODO
case OP_LT:
case OP_GT:
case OP_LTE:
case OP_GTE:
#endif
default:
mprAssert(0);
}
return 0;
}
示例2: sclone
PUBLIC HttpUri *httpCloneUri(HttpUri *base, int flags)
{
HttpUri *up;
char *path, *cp, *tok;
if ((up = mprAllocObj(HttpUri, manageUri)) == 0) {
up->valid = 0;
return 0;
}
if (!base || !base->valid) {
up->valid = 0;
return up;
}
if (base->scheme) {
up->scheme = sclone(base->scheme);
} else if (flags & HTTP_COMPLETE_URI) {
up->scheme = sclone("http");
}
up->secure = (smatch(up->scheme, "https") || smatch(up->scheme, "wss"));
up->webSockets = (smatch(up->scheme, "ws") || smatch(up->scheme, "wss"));
if (base->host) {
up->host = sclone(base->host);
} else if (flags & HTTP_COMPLETE_URI) {
up->host = sclone("localhost");
}
if (base->port) {
up->port = base->port;
} else if (flags & HTTP_COMPLETE_URI) {
up->port = up->secure ? 443 : 80;
}
path = base->path;
if (path) {
while (path[0] == '/' && path[1] == '/') {
path++;
}
up->path = sclone(path);
}
if (flags & (HTTP_COMPLETE_URI | HTTP_COMPLETE_URI_PATH)) {
if (up->path == 0 || *up->path == '\0') {
up->path = sclone("/");
}
}
if (base->reference) {
up->reference = sclone(base->reference);
}
if (base->query) {
up->query = sclone(base->query);
}
if (up->path && (tok = srchr(up->path, '.')) != 0) {
if ((cp = srchr(up->path, '/')) != 0) {
if (cp <= tok) {
up->ext = sclone(&tok[1]);
}
} else {
up->ext = sclone(&tok[1]);
}
}
up->valid = 1;
return up;
}
示例3: websVerifyPassword
PUBLIC bool websVerifyPassword(Webs *wp)
{
char passbuf[BIT_LIMIT_PASSWORD * 3 + 3];
bool success;
assure(wp);
if (!wp->encoded) {
fmt(passbuf, sizeof(passbuf), "%s:%s:%s", wp->username, BIT_REALM, wp->password);
wfree(wp->password);
wp->password = websMD5(passbuf);
wp->encoded = 1;
}
if (!wp->user && (wp->user = websLookupUser(wp->username)) == 0) {
trace(5, "verifyUser: Unknown user \"%s\"", wp->username);
return 0;
}
/*
Verify the password
*/
if (wp->digest) {
success = smatch(wp->password, wp->digest);
} else {
success = smatch(wp->password, wp->user->password);
}
if (success) {
trace(5, "User \"%s\" authenticated", wp->username);
} else {
trace(5, "Password for user \"%s\" failed to authenticate", wp->username);
}
return success;
}
示例4: websSetRouteAuth
PUBLIC int websSetRouteAuth(WebsRoute *route, char *auth)
{
WebsParseAuth parseAuth;
WebsAskLogin askLogin;
assure(route);
assure(auth && *auth);
askLogin = 0;
parseAuth = 0;
if (smatch(auth, "basic")) {
askLogin = basicLogin;
parseAuth = parseBasicDetails;
#if BIT_DIGEST
} else if (smatch(auth, "digest")) {
askLogin = digestLogin;
parseAuth = parseDigestDetails;
#endif
} else {
auth = 0;
}
route->authType = sclone(auth);
route->askLogin = askLogin;
route->parseAuth = parseAuth;
return 0;
}
示例5: espScript
PUBLIC void espScript(HttpConn *conn, cchar *uri, cchar *optionString)
{
MprHash *options;
cchar *indent, *newline, *path;
EspScript *sp;
EspRoute *eroute;
bool minified;
eroute = conn->rx->route->eroute;
options = httpGetOptions(optionString);
if (uri) {
espRender(conn, "<script src='%s' type='text/javascript'></script>", httpUri(conn, uri));
} else {
minified = smatch(httpGetOption(options, "minified", 0), "true");
indent = "";
for (sp = defaultScripts; sp->name; sp++) {
if (sp->option && !smatch(httpGetOption(options, sp->option, "false"), "true")) {
continue;
}
if (sp->flags & SCRIPT_IE) {
espRender(conn, "%s<!-- [if lt IE 9]>\n", indent);
}
path = sjoin("~/", mprGetPathBase(eroute->clientDir), sp->name, minified ? ".min.js" : ".js", NULL);
uri = httpUri(conn, path);
newline = sp[1].name ? "\r\n" : "";
espRender(conn, "%s<script src='%s' type='text/javascript'></script>%s", indent, uri, newline);
if (sp->flags & SCRIPT_IE) {
espRender(conn, "%s<![endif]-->\n", indent);
}
indent = " ";
}
}
}
示例6: tabs
/*
tabs(makeGrid("[{ name: 'Status', uri: 'pane-1' }, { name: 'Edit', uri: 'pane-2' }]"))
Options:
click
toggle
remote
*/
PUBLIC void espTabs(HttpConn *conn, EdiGrid *grid, cchar *optionString)
{
MprHash *options;
EdiRec *rec;
cchar *attr, *uri, *name, *klass;
int r, toggle;
options = httpGetOptions(optionString);
httpInsertOption(options, "class", ESTYLE("tabs"));
attr = httpGetOption(options, "toggle", EDATA("click"));
if ((toggle = smatch(attr, "true")) != 0) {
attr = EDATA("toggle");
}
espRender(conn, "<div%s>\r\n <ul>\r\n", map(conn, options));
for (r = 0; r < grid->nrecords; r++) {
rec = grid->records[r];
name = ediGetFieldValue(rec, "name");
uri = ediGetFieldValue(rec, "uri");
uri = toggle ? uri : httpUri(conn, uri);
if ((r == 0 && toggle) || smatch(uri, conn->rx->pathInfo)) {
klass = smatch(uri, conn->rx->pathInfo) ? " class='esp-selected'" : "";
} else {
klass = "";
}
espRender(conn, " <li %s='%s'%s>%s</li>\r\n", attr, uri, klass, name);
}
espRender(conn, " </ul>\r\n </div>\r\n");
}
示例7: httpGetCredentials
/*
Get the username and password credentials. If using an in-protocol auth scheme like basic|digest, the
rx->authDetails will contain the credentials and the parseAuth callback will be invoked to parse.
Otherwise, it is expected that "username" and "password" fields are present in the request parameters.
This is called by authCondition which thereafter calls httpLogin
*/
PUBLIC bool httpGetCredentials(HttpConn *conn, cchar **username, cchar **password)
{
HttpAuth *auth;
assert(username);
assert(password);
*username = *password = NULL;
auth = conn->rx->route->auth;
if (!auth || !auth->type) {
return 0;
}
if (auth->type) {
if (conn->authType && !smatch(conn->authType, auth->type->name)) {
if (!(smatch(auth->type->name, "form") && conn->rx->flags & HTTP_POST)) {
/* If a posted form authentication, ignore any basic|digest details in request */
return 0;
}
}
if (auth->type->parseAuth && (auth->type->parseAuth)(conn, username, password) < 0) {
return 0;
}
} else {
*username = httpGetParam(conn, "username", 0);
*password = httpGetParam(conn, "password", 0);
}
return 1;
}
示例8: websVerifyPasswordFromFile
PUBLIC bool websVerifyPasswordFromFile(Webs *wp)
{
char passbuf[ME_GOAHEAD_LIMIT_PASSWORD * 3 + 3];
bool success;
assert(wp);
if (!wp->user && (wp->user = websLookupUser(wp->username)) == 0) {
trace(5, "verifyUser: Unknown user \"%s\"", wp->username);
return 0;
}
/*
Verify the password. If using Digest auth, we compare the digest of the password.
Otherwise we encode the plain-text password and compare that
*/
if (!wp->encoded) {
fmt(passbuf, sizeof(passbuf), "%s:%s:%s", wp->username, ME_GOAHEAD_REALM, wp->password);
wfree(wp->password);
wp->password = websMD5(passbuf);
wp->encoded = 1;
}
if (wp->digest) {
success = smatch(wp->password, wp->digest);
} else {
success = smatch(wp->password, wp->user->password);
}
if (success) {
trace(5, "User \"%s\" authenticated", wp->username);
} else {
trace(5, "Password for user \"%s\" failed to authenticate", wp->username);
}
return success;
}
示例9: getPort
static int getPort(HttpUri *uri)
{
if (uri->port) {
return uri->port;
}
return (uri->scheme && (smatch(uri->scheme, "https") || smatch(uri->scheme, "wss"))) ? 443 : 80;
}
示例10: websOpenAuth
PUBLIC int websOpenAuth(int minimal)
{
char sbuf[64];
assert(minimal == 0 || minimal == 1);
if ((users = hashCreate(-1)) < 0) {
return -1;
}
if ((roles = hashCreate(-1)) < 0) {
return -1;
}
if (!minimal) {
fmt(sbuf, sizeof(sbuf), "%x:%x", rand(), OSTimeGet());
secret = websMD5(sbuf);
#if ME_GOAHEAD_JAVASCRIPT && FUTURE
websJsDefine("can", jsCan);
#endif
websDefineAction("login", loginServiceProc);
websDefineAction("logout", logoutServiceProc);
}
if (smatch(ME_GOAHEAD_AUTH_STORE, "file")) {
verifyPassword = websVerifyPasswordFromFile;
#if ME_COMPILER_HAS_PAM
} else if (smatch(ME_GOAHEAD_AUTH_STORE, "pam")) {
verifyPassword = websVerifyPasswordFromPam;
#endif
}
return 0;
}
示例11: setClientHeaders
/*
Define headers and create an empty header packet that will be filled later by the pipeline.
*/
static int setClientHeaders(HttpConn *conn)
{
HttpAuthType *authType;
mprAssert(conn);
if (smatch(conn->protocol, "HTTP/1.0")) {
conn->http10 = 1;
}
if (conn->authType && (authType = httpLookupAuthType(conn->authType)) != 0) {
(authType->setAuth)(conn);
conn->setCredentials = 1;
}
if (conn->port != 80) {
httpAddHeader(conn, "Host", "%s:%d", conn->ip, conn->port);
} else {
httpAddHeaderString(conn, "Host", conn->ip);
}
#if UNUSED
if (conn->http10 && !smatch(conn->tx->method, "GET")) {
conn->keepAliveCount = 0;
}
#endif
if (conn->keepAliveCount > 0) {
httpSetHeaderString(conn, "Connection", "Keep-Alive");
} else {
httpSetHeaderString(conn, "Connection", "close");
}
return 0;
}
示例12: sfmt
static char *getModuleEntry(EspRoute *eroute, cchar *kind, cchar *source, cchar *cacheName)
{
char *cp, *entry;
if (smatch(kind, "view")) {
entry = sfmt("esp_%s", cacheName);
} else if (smatch(kind, "app")) {
if (eroute->combine) {
entry = sfmt("esp_%s_%s_combine", kind, eroute->appName);
} else {
entry = sfmt("esp_%s_%s", kind, eroute->appName);
}
} else {
/* Controller */
if (eroute->appName) {
entry = sfmt("esp_%s_%s_%s", kind, eroute->appName, mprTrimPathExt(mprGetPathBase(source)));
} else {
entry = sfmt("esp_%s_%s", kind, mprTrimPathExt(mprGetPathBase(source)));
}
}
for (cp = entry; *cp; cp++) {
if (!isalnum((uchar) *cp) && *cp != '_') {
*cp = '_';
}
}
return entry;
}
示例13: checkPeerCertName
/*
Check the certificate peer name validates and matches the desired name
*/
static int checkPeerCertName(MprSocket *sp)
{
MprSsl *ssl;
OpenSocket *osp;
X509 *cert;
X509_NAME *xSubject;
char subject[512], issuer[512], peerName[512], *target, *certName, *tp;
ssl = sp->ssl;
osp = (OpenSocket*) sp->sslSocket;
if ((cert = SSL_get_peer_certificate(osp->handle)) == 0) {
peerName[0] = '\0';
} else {
xSubject = X509_get_subject_name(cert);
X509_NAME_oneline(xSubject, subject, sizeof(subject) -1);
X509_NAME_oneline(X509_get_issuer_name(cert), issuer, sizeof(issuer) -1);
X509_NAME_get_text_by_NID(xSubject, NID_commonName, peerName, sizeof(peerName) - 1);
sp->peerName = sclone(peerName);
sp->peerCert = sclone(subject);
sp->peerCertIssuer = sclone(issuer);
X509_free(cert);
}
if (ssl->verifyPeer && osp->requiredPeerName) {
target = osp->requiredPeerName;
certName = peerName;
if (target == 0 || *target == '\0' || strchr(target, '.') == 0) {
sp->errorMsg = sfmt("Bad peer name");
return MPR_ERR_BAD_VALUE;
}
if (!smatch(certName, "localhost")) {
if (strchr(certName, '.') == 0) {
sp->errorMsg = sfmt("Peer certificate must have a domain: \"%s\"", certName);
return MPR_ERR_BAD_VALUE;
}
if (*certName == '*' && certName[1] == '.') {
/* Wildcard cert */
certName = &certName[2];
if (strchr(certName, '.') == 0) {
/* Peer must be of the form *.domain.tld. i.e. *.com is not valid */
sp->errorMsg = sfmt("Peer CN is not valid %s", peerName);
return MPR_ERR_BAD_VALUE;
}
if ((tp = strchr(target, '.')) != 0 && strchr(&tp[1], '.')) {
/* Strip host name if target has a host name */
target = &tp[1];
}
}
}
if (!smatch(target, certName)) {
sp->errorMsg = sfmt("Certificate common name mismatch CN \"%s\" vs required \"%s\"", peerName,
osp->requiredPeerName);
return MPR_ERR_BAD_VALUE;
}
}
return 0;
}
示例14: httpCloneUri
PUBLIC HttpUri *httpResolveUri(HttpConn *conn, HttpUri *base, HttpUri *other)
{
HttpHost *host;
HttpEndpoint *endpoint;
HttpUri *current;
if (!base || !base->valid) {
return other;
}
if (!other || !other->valid) {
return base;
}
current = httpCloneUri(base, 0);
/*
Must not inherit the query or reference
*/
current->query = 0;
current->reference = 0;
if (other->scheme && !smatch(current->scheme, other->scheme)) {
current->scheme = sclone(other->scheme);
/*
If the scheme is changed (test above), then accept an explict port.
If no port, then must not use the current port as the scheme has changed.
*/
if (other->port) {
current->port = other->port;
} else {
host = conn ? conn->host : httpGetDefaultHost();
endpoint = smatch(current->scheme, "https") ? host->secureEndpoint : host->defaultEndpoint;
if (endpoint) {
current->port = endpoint->port;
} else {
current->port = 0;
}
}
}
if (other->host) {
current->host = sclone(other->host);
}
if (other->port) {
current->port = other->port;
}
if (other->path) {
trimPathToDirname(current);
httpJoinUriPath(current, current, other);
current->path = httpNormalizeUriPath(current->path);
}
if (other->reference) {
current->reference = sclone(other->reference);
}
if (other->query) {
current->query = sclone(other->query);
}
current->ext = mprGetPathExt(current->path);
return current;
}
示例15: logoutServiceProc
static void logoutServiceProc(Webs *wp)
{
assure(wp);
websRemoveSessionVar(wp, WEBS_SESSION_USERNAME);
if (smatch(wp->authType, "basic") || smatch(wp->authType, "digest")) {
websError(wp, HTTP_CODE_UNAUTHORIZED, "Logged out.");
return;
}
websRedirectByStatus(wp, HTTP_CODE_OK);
}