* [PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()
@ 2014-08-30 16:14 René Scharfe
2014-09-02 19:23 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2014-08-30 16:14 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
Use starts_with() instead of memcmp() to check if NUL-terminated
strings match prefixes. This gets rid of some magic string length
constants.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
imap-send.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/imap-send.c b/imap-send.c
index 524fbab..b079a0d 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -524,7 +524,7 @@ static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,
if (Verbose) {
if (imap->num_in_progress)
printf("(%d in progress) ", imap->num_in_progress);
- if (memcmp(cmd->cmd, "LOGIN", 5))
+ if (!starts_with(cmd->cmd, "LOGIN"))
printf(">>> %s", buf);
else
printf(">>> %d LOGIN <user> <pass>\n", cmd->tag);
@@ -802,7 +802,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
resp = DRV_OK;
else {
if (!strcmp("NO", arg)) {
- if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or UID COPY */
+ if (cmdp->cb.create && cmd &&
+ (cmdp->cb.trycreate ||
+ starts_with(cmd, "[TRYCREATE]"))) {
+ /* SELECT, APPEND or UID COPY */
p = strchr(cmdp->cmd, '"');
if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", (int)(strchr(p + 1, '"') - p + 1), p)) {
resp = RESP_BAD;
@@ -827,7 +830,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
} else /*if (!strcmp("BAD", arg))*/
resp = RESP_BAD;
fprintf(stderr, "IMAP command '%s' returned response (%s) - %s\n",
- memcmp(cmdp->cmd, "LOGIN", 5) ?
+ !starts_with(cmdp->cmd, "LOGIN") ?
cmdp->cmd : "LOGIN <user> <pass>",
arg, cmd ? cmd : "");
}
--
2.1.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()
2014-08-30 16:14 [PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with() René Scharfe
@ 2014-09-02 19:23 ` Junio C Hamano
2014-09-03 3:50 ` René Scharfe
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2014-09-02 19:23 UTC (permalink / raw)
To: René Scharfe; +Cc: Git Mailing List
René Scharfe <l.s.r@web.de> writes:
> Use starts_with() instead of memcmp() to check if NUL-terminated
> strings match prefixes. This gets rid of some magic string length
> constants.
>
> Signed-off-by: Rene Scharfe <l.s.r@web.de>
> ---
> imap-send.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/imap-send.c b/imap-send.c
> index 524fbab..b079a0d 100644
> --- a/imap-send.c
> +++ b/imap-send.c
> @@ -802,7 +802,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
> resp = DRV_OK;
> else {
> if (!strcmp("NO", arg)) {
> - if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or UID COPY */
> + if (cmdp->cb.create && cmd &&
> + (cmdp->cb.trycreate ||
> + starts_with(cmd, "[TRYCREATE]"))) {
> + /* SELECT, APPEND or UID COPY */
> p = strchr(cmdp->cmd, '"');
> if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", (int)(strchr(p + 1, '"') - p + 1), p)) {
> resp = RESP_BAD;
Do we want this hunk, given that it will disappear with the
tf/imap-send-create topic at e0d8e308 (imap-send: create target
mailbox if it is missing, 2014-08-01)?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()
2014-09-02 19:23 ` Junio C Hamano
@ 2014-09-03 3:50 ` René Scharfe
0 siblings, 0 replies; 3+ messages in thread
From: René Scharfe @ 2014-09-03 3:50 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
Am 02.09.2014 um 21:23 schrieb Junio C Hamano:
> René Scharfe <l.s.r@web.de> writes:
>
>> Use starts_with() instead of memcmp() to check if NUL-terminated
>> strings match prefixes. This gets rid of some magic string length
>> constants.
>>
>> Signed-off-by: Rene Scharfe <l.s.r@web.de>
>> ---
>> imap-send.c | 9 ++++++---
>> 1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/imap-send.c b/imap-send.c
>> index 524fbab..b079a0d 100644
>> --- a/imap-send.c
>> +++ b/imap-send.c
>> @@ -802,7 +802,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
>> resp = DRV_OK;
>> else {
>> if (!strcmp("NO", arg)) {
>> - if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or UID COPY */
>> + if (cmdp->cb.create && cmd &&
>> + (cmdp->cb.trycreate ||
>> + starts_with(cmd, "[TRYCREATE]"))) {
>> + /* SELECT, APPEND or UID COPY */
>> p = strchr(cmdp->cmd, '"');
>> if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", (int)(strchr(p + 1, '"') - p + 1), p)) {
>> resp = RESP_BAD;
>
> Do we want this hunk, given that it will disappear with the
> tf/imap-send-create topic at e0d8e308 (imap-send: create target
> mailbox if it is missing, 2014-08-01)?
In that case it's unnecessary; apparently I overlooked the conflicting
hunk while preparing the patch for sending.
René
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-09-03 3:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-30 16:14 [PATCH] imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with() René Scharfe
2014-09-02 19:23 ` Junio C Hamano
2014-09-03 3:50 ` René Scharfe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).