本文整理汇总了C++中prot_printf函数的典型用法代码示例。如果您正苦于以下问题:C++ prot_printf函数的具体用法?C++ prot_printf怎么用?C++ prot_printf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了prot_printf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: capabilities
int capabilities(struct protstream *conn, sasl_conn_t *saslconn,
int starttls_done, int authenticated, sasl_ssf_t sasl_ssf)
{
const char *sasllist;
int mechcount;
/* implementation */
prot_printf(conn,
"\"IMPLEMENTATION\" \"Cyrus timsieved%s %s\"\r\n",
config_mupdate_server ? " (Murder)" : "", cyrus_version());
/* SASL */
if ((!authenticated || sasl_ssf) &&
sasl_listmech(saslconn, NULL,
"\"SASL\" \"", " ", "\"\r\n",
&sasllist,
NULL, &mechcount) == SASL_OK/* && mechcount > 0*/)
{
prot_printf(conn,"%s",sasllist);
}
/* Sieve capabilities */
prot_printf(conn,"\"SIEVE\" \"%s\"\r\n",sieve_listextensions(interp));
if (tls_enabled() && !starttls_done && !authenticated) {
prot_printf(conn, "\"STARTTLS\"\r\n");
}
prot_printf(conn,"OK\r\n");
return TIMSIEVE_OK;
}
示例2: annotate_fetch_proxy
/* Proxy GETANNOTATION commands to backend */
int annotate_fetch_proxy(const char *server, const char *mbox_pat,
const strarray_t *entry_pat,
const strarray_t *attribute_pat)
{
struct backend *be;
int i;
char mytag[128];
assert(server && mbox_pat && entry_pat && attribute_pat);
be = proxy_findserver(server, &imap_protocol,
proxy_userid, &backend_cached,
&backend_current, &backend_inbox, imapd_in);
if (!be) return IMAP_SERVER_UNAVAILABLE;
/* Send command to remote */
proxy_gentag(mytag, sizeof(mytag));
prot_printf(be->out, "%s GETANNOTATION \"%s\" (", mytag, mbox_pat);
for (i = 0 ; i < entry_pat->count ; i++) {
prot_printf(be->out, "%s\"%s\"", i ? " " : "", entry_pat->data[i]);
}
prot_printf(be->out, ") (");
for (i = 0 ; i < attribute_pat->count ; i++) {
prot_printf(be->out, "%s\"%s\"", i ? " " : "", attribute_pat->data[i]);
}
prot_printf(be->out, ")\r\n");
prot_flush(be->out);
/* Pipe the results. Note that backend-current may also pipe us other
messages. */
pipe_until_tag(be, mytag, 0);
return 0;
}
示例3: ping
static int ping(struct backend *s, const char *userid)
{
unsigned code = 0;
const char *errstr;
hdrcache_t resp_hdrs = NULL;
struct body_t resp_body;
/* Send Authorization request to server */
prot_puts(s->out, "OPTIONS * HTTP/1.1\r\n");
prot_printf(s->out, "Host: %s\r\n", s->hostname);
prot_printf(s->out, "User-Agent: %s\r\n", buf_cstring(&serverinfo));
prot_printf(s->out, "Authorize-As: %s\r\n", userid ? userid : "anonymous");
prot_puts(s->out, "\r\n");
prot_flush(s->out);
/* Read response(s) from backend until final response or error */
do {
resp_body.flags = BODY_DISCARD;
if (http_read_response(s, METH_OPTIONS, &code, NULL,
&resp_hdrs, &resp_body, &errstr)) {
break;
}
} while (code < 200);
if (resp_hdrs) spool_free_hdrcache(resp_hdrs);
return (code != 200);
}
示例4: installdata
int installdata(int version,struct protstream *pout, struct protstream *pin,
char *scriptname, char *data, int len,
char **refer_to, char **errstrp)
{
int res;
int ret;
char *errstr=NULL;
lexstate_t state;
prot_printf(pout, "PUTSCRIPT \"%s\" ",scriptname);
prot_printf(pout, "{%d+}\r\n",len);
prot_write(pout, data, len);
prot_printf(pout,"\r\n");
prot_flush(pout);
/* now let's see what the server said */
res=yylex(&state,pin);
ret = handle_response(res,version,pin,refer_to,&errstr);
/* if command failed */
if(ret == -2 && *refer_to) {
return -2;
} else if (ret!=0) {
*errstrp = strconcat("Putting script: ",
errstr,
(char *)NULL);
return -1;
}
return 0;
}
示例5: do_restart
static int do_restart()
{
static int restartcnt = 0;
if (sync_out->userdata) {
/* IMAP flavor (w/ tag) */
prot_printf(sync_out, "R%d SYNC", restartcnt++);
}
prot_printf(sync_out, "RESTART\r\n");
prot_flush(sync_out);
return sync_parse_response("RESTART", sync_in, NULL);
}
示例6: do_restart
static int do_restart()
{
static int restartcnt = 0;
if (sync_out->userdata) {
/* IMAP flavor (w/ tag) */
struct buf *tag = (struct buf *) sync_out->userdata;
buf_reset(tag);
buf_printf(tag, "R%d", restartcnt++);
prot_printf(sync_out, "%s SYNC", buf_cstring(tag));
}
prot_printf(sync_out, "RESTART\r\n");
prot_flush(sync_out);
return sync_parse_response("RESTART", sync_in, NULL);
}
示例7: setscriptactive
int setscriptactive(int version, struct protstream *pout,
struct protstream *pin,char *name,
char **refer_to, char **errstrp)
{
lexstate_t state;
int res;
int ret;
char *errstr=NULL;
/* tell server we want "name" to be the active script */
prot_printf(pout, "SETACTIVE \"%s\"\r\n",name);
prot_flush(pout);
/* now let's see what the server said */
res=yylex(&state, pin);
ret = handle_response(res, version, pin, refer_to, &errstr);
/* if command failed */
if(ret == -2 && *refer_to) {
return -2;
} else if (ret != 0) {
*errstrp = strconcat("Setting script active: ",
errstr,
(char *)NULL);
return -1;
}
return 0;
}
示例8: backend_ping
EXPORTED int backend_ping(struct backend *s, const char *userid)
{
char buf[1024];
struct simple_cmd_t *ping_cmd;
if (!s) return 0;
if (s->sock == -1) return -1; /* Disconnected Socket */
if (s->prot->type == TYPE_SPEC) return s->prot->u.spec.ping(s, userid);
ping_cmd = &s->prot->u.std.ping_cmd;
if (!ping_cmd->cmd) return 0;
prot_printf(s->out, "%s\r\n", ping_cmd->cmd);
prot_flush(s->out);
for (;;) {
if (!prot_fgets(buf, sizeof(buf), s->in)) {
/* connection closed? */
return -1;
} else if (ping_cmd->unsol &&
!strncmp(ping_cmd->unsol, buf,
strlen(ping_cmd->unsol))) {
/* unsolicited response */
continue;
} else {
/* success/fail response */
return strncmp(ping_cmd->ok, buf, strlen(ping_cmd->ok));
}
}
}
示例9: deleteascript
int deleteascript(int version, struct protstream *pout,
struct protstream *pin, const char *name,
char **refer_to, char **errstrp)
{
lexstate_t state;
int res;
int ret;
char *errstr = NULL;
prot_printf(pout,"DELETESCRIPT \"%s\"\r\n",name);
prot_flush(pout);
res=yylex(&state, pin);
ret = handle_response(res,version,pin,refer_to,&errstr);
if(ret == -2 && *refer_to) {
return -2;
} else if (ret!=0) {
*errstrp = strconcat("Deleting script: ",
errstr,
(char *)NULL);
return -1;
}
return 0;
}
示例10: backend_ping
int backend_ping(struct backend *s)
{
char buf[1024];
if (!s || !s->prot->ping_cmd.cmd) return 0;
if (s->sock == -1) return -1; /* Disconnected Socket */
prot_printf(s->out, "%s\r\n", s->prot->ping_cmd.cmd);
prot_flush(s->out);
for (;;) {
if (!prot_fgets(buf, sizeof(buf), s->in)) {
/* connection closed? */
return -1;
} else if (s->prot->ping_cmd.unsol &&
!strncmp(s->prot->ping_cmd.unsol, buf,
strlen(s->prot->ping_cmd.unsol))) {
/* unsolicited response */
continue;
} else {
/* success/fail response */
return strncmp(s->prot->ping_cmd.ok, buf,
strlen(s->prot->ping_cmd.ok));
}
}
}
示例11: detect_mitm
int detect_mitm(isieve_t *obj, char *mechlist)
{
char *new_mechlist;
int ch, r = 0;
/* wait and probe for possible automatic capability response */
usleep(250000);
prot_NONBLOCK(obj->pin);
if ((ch = prot_getc(obj->pin)) != EOF) {
/* automatic capability response */
prot_ungetc(ch, obj->pin);
} else {
/* manually ask for capabilities */
prot_printf(obj->pout, "CAPABILITY\r\n");
prot_flush(obj->pout);
}
prot_BLOCK(obj->pin);
if ((new_mechlist = read_capability(obj))) {
/* if the server still advertises SASL mechs, compare lists */
r = strcmp(new_mechlist, mechlist);
free(new_mechlist);
}
return r;
}
示例12: backend_disconnect
void backend_disconnect(struct backend *s)
{
char buf[1024];
if (!s || s->sock == -1) return;
if (!prot_error(s->in)) {
if (s->prot->logout_cmd.cmd) {
prot_printf(s->out, "%s\r\n", s->prot->logout_cmd.cmd);
prot_flush(s->out);
for (;;) {
if (!prot_fgets(buf, sizeof(buf), s->in)) {
/* connection closed? */
break;
} else if (s->prot->logout_cmd.unsol &&
!strncmp(s->prot->logout_cmd.unsol, buf,
strlen(s->prot->logout_cmd.unsol))) {
/* unsolicited response */
continue;
} else {
/* success/fail response -- don't care either way */
break;
}
}
}
}
/* Flush the incoming buffer */
prot_NONBLOCK(s->in);
prot_fill(s->in);
#ifdef HAVE_SSL
/* Free tlsconn */
if (s->tlsconn) {
tls_reset_servertls(&s->tlsconn);
s->tlsconn = NULL;
}
#endif /* HAVE_SSL */
/* close/free socket & prot layer */
cyrus_close_sock(s->sock);
s->sock = -1;
prot_free(s->in);
prot_free(s->out);
s->in = s->out = NULL;
/* Free saslconn */
if(s->saslconn) {
sasl_dispose(&(s->saslconn));
s->saslconn = NULL;
}
/* free last_result buffer */
buf_free(&s->last_result);
forget_capabilities(s);
}
示例13: setactive
int setactive(struct protstream *conn, mystring_t *name)
{
int result;
char filename[1024];
/* if string name is empty, disable active script */
if (!strlen(string_DATAPTR(name))) {
if (deleteactive(conn) != TIMSIEVE_OK)
return TIMSIEVE_FAIL;
prot_printf(conn,"OK\r\n");
return TIMSIEVE_OK;
}
result = scriptname_valid(name);
if (result!=TIMSIEVE_OK)
{
prot_printf(conn,"NO \"Invalid script name\"\r\n");
return result;
}
if (exists(string_DATAPTR(name))==FALSE)
{
prot_printf(conn,"NO \"Script does not exist\"\r\n");
return TIMSIEVE_NOEXIST;
}
/* if script already is the active one just say ok */
if (isactive(string_DATAPTR(name))==TRUE) {
prot_printf(conn,"OK\r\n");
return TIMSIEVE_OK;
}
/* get the name of the active sieve script */
snprintf(filename, sizeof(filename), "%s.bc", string_DATAPTR(name));
/* ok we want to do this atomically so let's
- make <activesieve>.NEW as a hard link
- rename it to <activesieve>
*/
result = symlink(filename, "defaultbc.NEW");
if (result) {
syslog(LOG_ERR, "symlink(%s, defaultbc.NEW): %m", filename);
prot_printf(conn, "NO \"Can't make link\"\r\n");
return TIMSIEVE_FAIL;
}
result = rename("defaultbc.NEW", "defaultbc");
if (result) {
unlink("defaultbc.NEW");
syslog(LOG_ERR, "rename(defaultbc.NEW, defaultbc): %m");
prot_printf(conn,"NO \"Error renaming\"\r\n");
return TIMSIEVE_FAIL;
}
sync_log_sieve(sieved_userid);
prot_printf(conn,"OK\r\n");
return TIMSIEVE_OK;
}
示例14: deleteactive
static int deleteactive(struct protstream *conn)
{
if (unlink("defaultbc") != 0) {
prot_printf(conn,"NO \"Unable to unlink active script\"\r\n");
return TIMSIEVE_FAIL;
}
sync_log_sieve(sieved_userid);
return TIMSIEVE_OK;
}
示例15: ask_capability
/*
* Get capabilities from the server, and parse them according to
* details in the protocol_t, so that the CAPA() macro and perhaps
* the backend_get_cap_params() function will notice them. Any
* capabilities previously parsed are forgotten.
*
* The server might give us capabilities for free just because we
* connected (or did a STARTTLS or logged in); in this case, call
* with a non-zero value for @automatic. Otherwise, we send a
* protocol-specific command to the server to tickle it into
* disgorging some capabilities.
*
* Returns: 1 if any capabilities were found, 0 otherwise.
*/
static int ask_capability(struct backend *s, int dobanner, int automatic)
{
struct protstream *pout = s->out, *pin = s->in;
const struct protocol_t *prot = s->prot;
int matches = 0;
char str[4096];
const char *resp;
resp = (automatic == AUTO_CAPA_BANNER) ?
prot->banner.resp : prot->capa_cmd.resp;
if (!automatic) {
/* no capability command */
if (!prot->capa_cmd.cmd) return -1;
/* request capabilities of server */
prot_printf(pout, "%s", prot->capa_cmd.cmd);
if (prot->capa_cmd.arg) prot_printf(pout, " %s", prot->capa_cmd.arg);
prot_printf(pout, "\r\n");
prot_flush(pout);
}
forget_capabilities(s);
do {
if (prot_fgets(str, sizeof(str), pin) == NULL) break;
matches |= parse_capability(s, str);
if (!resp) {
/* multiline response with no distinct end (IMAP banner) */
prot_NONBLOCK(pin);
}
if (dobanner) strncpy(s->banner, str, sizeof(s->banner));
/* look for the end of the capabilities */
} while (!resp || strncasecmp(str, resp, strlen(resp)));
prot_BLOCK(pin);
post_parse_capability(s);
return matches;
}