Lines Matching defs:data
90 static CURLcode smtp_regular_transfer(struct Curl_easy *data, bool *done);
91 static CURLcode smtp_do(struct Curl_easy *data, bool *done);
92 static CURLcode smtp_done(struct Curl_easy *data, CURLcode status,
94 static CURLcode smtp_connect(struct Curl_easy *data, bool *done);
95 static CURLcode smtp_disconnect(struct Curl_easy *data,
97 static CURLcode smtp_multi_statemach(struct Curl_easy *data, bool *done);
98 static int smtp_getsock(struct Curl_easy *data,
100 static CURLcode smtp_doing(struct Curl_easy *data, bool *dophase_done);
101 static CURLcode smtp_setup_connection(struct Curl_easy *data,
104 static CURLcode smtp_parse_url_path(struct Curl_easy *data);
105 static CURLcode smtp_parse_custom_request(struct Curl_easy *data);
108 static CURLcode smtp_perform_auth(struct Curl_easy *data, const char *mech,
110 static CURLcode smtp_continue_auth(struct Curl_easy *data, const char *mech,
112 static CURLcode smtp_cancel_auth(struct Curl_easy *data, const char *mech);
113 static CURLcode smtp_get_message(struct Curl_easy *data, struct bufref *out);
208 static bool smtp_endofresp(struct Curl_easy *data, struct connectdata *conn,
213 (void)data;
251 static CURLcode smtp_get_message(struct Curl_easy *data, struct bufref *out)
253 char *message = Curl_dyn_ptr(&data->conn->proto.smtpc.pp.recvbuf);
254 size_t len = data->conn->proto.smtpc.pp.nfinal;
285 static void smtp_state(struct Curl_easy *data, smtpstate newstate)
287 struct smtp_conn *smtpc = &data->conn->proto.smtpc;
308 infof(data, "SMTP %p state change from %s to %s",
322 static CURLcode smtp_perform_ehlo(struct Curl_easy *data)
325 struct connectdata *conn = data->conn;
335 result = Curl_pp_sendf(data, &smtpc->pp, "EHLO %s", smtpc->domain);
338 smtp_state(data, SMTP_EHLO);
349 static CURLcode smtp_perform_helo(struct Curl_easy *data,
359 result = Curl_pp_sendf(data, &smtpc->pp, "HELO %s", smtpc->domain);
362 smtp_state(data, SMTP_HELO);
373 static CURLcode smtp_perform_starttls(struct Curl_easy *data,
377 CURLcode result = Curl_pp_sendf(data, &conn->proto.smtpc.pp,
381 smtp_state(data, SMTP_STARTTLS);
392 static CURLcode smtp_perform_upgrade_tls(struct Curl_easy *data)
395 struct connectdata *conn = data->conn;
401 result = Curl_ssl_cfilter_add(data, conn, FIRSTSOCKET);
406 result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone);
410 smtp_state(data, SMTP_UPGRADETLS);
414 result = smtp_perform_ehlo(data);
428 static CURLcode smtp_perform_auth(struct Curl_easy *data,
433 struct smtp_conn *smtpc = &data->conn->proto.smtpc;
438 result = Curl_pp_sendf(data, &smtpc->pp, "AUTH %s %s", mech, ir);
442 result = Curl_pp_sendf(data, &smtpc->pp, "AUTH %s", mech);
452 * Sends SASL continuation data.
454 static CURLcode smtp_continue_auth(struct Curl_easy *data,
458 struct smtp_conn *smtpc = &data->conn->proto.smtpc;
462 return Curl_pp_sendf(data, &smtpc->pp,
472 static CURLcode smtp_cancel_auth(struct Curl_easy *data, const char *mech)
474 struct smtp_conn *smtpc = &data->conn->proto.smtpc;
478 return Curl_pp_sendf(data, &smtpc->pp, "*");
488 static CURLcode smtp_perform_authentication(struct Curl_easy *data)
491 struct connectdata *conn = data->conn;
495 /* Check we have enough data to authenticate with, and the
498 !Curl_sasl_can_authenticate(&smtpc->sasl, data)) {
499 smtp_state(data, SMTP_STOP);
504 result = Curl_sasl_start(&smtpc->sasl, data, FALSE, &progress);
508 smtp_state(data, SMTP_AUTH);
511 infof(data, "No known authentication mechanisms supported");
525 static CURLcode smtp_perform_command(struct Curl_easy *data)
528 struct connectdata *conn = data->conn;
529 struct SMTP *smtp = data->req.p.smtp;
532 /* We notify the server we are sending UTF-8 data if a) it supports the
544 result = smtp_parse_address(smtp->rcpt->data,
557 result = Curl_pp_sendf(data, &conn->proto.smtpc.pp, "VRFY %s%s%s%s",
573 result = Curl_pp_sendf(data, &conn->proto.smtpc.pp,
575 smtp->rcpt->data,
581 result = Curl_pp_sendf(data, &conn->proto.smtpc.pp, "%s",
586 smtp_state(data, SMTP_COMMAND);
597 static CURLcode smtp_perform_mail(struct Curl_easy *data)
603 struct connectdata *conn = data->conn;
605 /* We notify the server we are sending UTF-8 data if a) it supports the
612 if(data->set.str[STRING_MAIL_FROM]) {
618 result = smtp_parse_address(data->set.str[STRING_MAIL_FROM],
649 if(data->set.str[STRING_MAIL_AUTH] && conn->proto.smtpc.sasl.authused) {
650 if(data->set.str[STRING_MAIL_AUTH][0] != '\0') {
656 result = smtp_parse_address(data->set.str[STRING_MAIL_AUTH],
693 /* Prepare the mime data if some. */
694 if(data->set.mimepost.kind != MIMEKIND_NONE) {
695 /* Use the whole structure as data. */
696 data->set.mimepost.flags &= ~MIME_BODY_ONLY;
699 curl_mime_headers(&data->set.mimepost, data->set.headers, 0);
700 result = Curl_mime_prepare_headers(data, &data->set.mimepost, NULL,
704 if(!Curl_checkheaders(data, STRCONST("Mime-Version")))
705 result = Curl_mime_add_header(&data->set.mimepost.curlheaders,
710 result = Curl_mime_rewind(&data->set.mimepost);
719 data->state.infilesize = Curl_mime_size(&data->set.mimepost);
722 data->state.fread_func = (curl_read_callback) Curl_mime_read;
723 data->state.in = (void *) &data->set.mimepost;
727 if(conn->proto.smtpc.size_supported && data->state.infilesize > 0) {
728 size = aprintf("%" CURL_FORMAT_CURL_OFF_T, data->state.infilesize);
743 struct SMTP *smtp = data->req.p.smtp;
748 if(!Curl_is_ASCII_name(rcpt->data))
756 result = Curl_pp_sendf(data, &conn->proto.smtpc.pp,
771 smtp_state(data, SMTP_MAIL);
783 static CURLcode smtp_perform_rcpt_to(struct Curl_easy *data)
786 struct connectdata *conn = data->conn;
787 struct SMTP *smtp = data->req.p.smtp;
793 result = smtp_parse_address(smtp->rcpt->data,
800 result = Curl_pp_sendf(data, &conn->proto.smtpc.pp, "RCPT TO:<%s@%s>",
805 result = Curl_pp_sendf(data, &conn->proto.smtpc.pp, "RCPT TO:<%s>",
812 smtp_state(data, SMTP_RCPT);
823 static CURLcode smtp_perform_quit(struct Curl_easy *data,
827 CURLcode result = Curl_pp_sendf(data, &conn->proto.smtpc.pp, "%s", "QUIT");
830 smtp_state(data, SMTP_QUIT);
836 static CURLcode smtp_state_servergreet_resp(struct Curl_easy *data,
844 failf(data, "Got unexpected smtp-server response: %d", smtpcode);
848 result = smtp_perform_ehlo(data);
854 static CURLcode smtp_state_starttls_resp(struct Curl_easy *data,
862 if(data->conn->proto.smtpc.pp.overflow)
866 if(data->set.use_ssl != CURLUSESSL_TRY) {
867 failf(data, "STARTTLS denied, code %d", smtpcode);
871 result = smtp_perform_authentication(data);
874 result = smtp_perform_upgrade_tls(data);
880 static CURLcode smtp_state_ehlo_resp(struct Curl_easy *data,
892 if(data->set.use_ssl <= CURLUSESSL_TRY
894 result = smtp_perform_helo(data, conn);
896 failf(data, "Remote access denied: %d", smtpcode);
924 /* Loop through the data line */
958 if(data->set.use_ssl && !Curl_conn_is_ssl(conn, FIRSTSOCKET)) {
962 result = smtp_perform_starttls(data, conn);
963 else if(data->set.use_ssl == CURLUSESSL_TRY)
965 result = smtp_perform_authentication(data);
967 failf(data, "STARTTLS not supported.");
972 result = smtp_perform_authentication(data);
976 failf(data, "Unexpectedly short EHLO response");
984 static CURLcode smtp_state_helo_resp(struct Curl_easy *data, int smtpcode,
991 failf(data, "Remote access denied: %d", smtpcode);
996 smtp_state(data, SMTP_STOP);
1002 static CURLcode smtp_state_auth_resp(struct Curl_easy *data,
1007 struct connectdata *conn = data->conn;
1013 result = Curl_sasl_continue(&smtpc->sasl, data, smtpcode, &progress);
1017 smtp_state(data, SMTP_STOP); /* Authenticated */
1020 failf(data, "Authentication cancelled");
1031 static CURLcode smtp_state_command_resp(struct Curl_easy *data, int smtpcode,
1035 struct SMTP *smtp = data->req.p.smtp;
1036 char *line = Curl_dyn_ptr(&data->conn->proto.smtpc.pp.recvbuf);
1037 size_t len = data->conn->proto.smtpc.pp.nfinal;
1043 failf(data, "Command failed: %d", smtpcode);
1047 if(!data->req.no_body)
1048 result = Curl_client_write(data, CLIENTWRITE_BODY, line, len);
1056 result = smtp_perform_command(data);
1060 smtp_state(data, SMTP_STOP);
1064 smtp_state(data, SMTP_STOP);
1072 static CURLcode smtp_state_mail_resp(struct Curl_easy *data, int smtpcode,
1079 failf(data, "MAIL failed: %d", smtpcode);
1084 result = smtp_perform_rcpt_to(data);
1090 static CURLcode smtp_state_rcpt_resp(struct Curl_easy *data,
1095 struct SMTP *smtp = data->req.p.smtp;
1106 (is_smtp_err && !data->set.mail_rcpt_allowfails) ? TRUE : FALSE;
1114 failf(data, "RCPT failed: %d", smtpcode);
1128 result = smtp_perform_rcpt_to(data);
1133 failf(data, "RCPT failed: %d (last error)", smtp->rcpt_last_error);
1138 result = Curl_pp_sendf(data, &conn->proto.smtpc.pp, "%s", "DATA");
1141 smtp_state(data, SMTP_DATA);
1150 static CURLcode smtp_state_data_resp(struct Curl_easy *data, int smtpcode,
1157 failf(data, "DATA failed: %d", smtpcode);
1162 Curl_pgrsSetUploadSize(data, data->state.infilesize);
1165 Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
1168 smtp_state(data, SMTP_STOP);
1176 static CURLcode smtp_state_postdata_resp(struct Curl_easy *data,
1188 smtp_state(data, SMTP_STOP);
1193 static CURLcode smtp_statemachine(struct Curl_easy *data,
1205 return smtp_perform_upgrade_tls(data);
1207 /* Flush any data that needs to be sent */
1209 return Curl_pp_flushsend(data, pp);
1213 result = Curl_pp_readresp(data, sock, pp, &smtpcode, &nread);
1219 data->info.httpcode = smtpcode;
1227 result = smtp_state_servergreet_resp(data, smtpcode, smtpc->state);
1231 result = smtp_state_ehlo_resp(data, conn, smtpcode, smtpc->state);
1235 result = smtp_state_helo_resp(data, smtpcode, smtpc->state);
1239 result = smtp_state_starttls_resp(data, smtpcode, smtpc->state);
1243 result = smtp_state_auth_resp(data, smtpcode, smtpc->state);
1247 result = smtp_state_command_resp(data, smtpcode, smtpc->state);
1251 result = smtp_state_mail_resp(data, smtpcode, smtpc->state);
1255 result = smtp_state_rcpt_resp(data, conn, smtpcode, smtpc->state);
1259 result = smtp_state_data_resp(data, smtpcode, smtpc->state);
1263 result = smtp_state_postdata_resp(data, smtpcode, smtpc->state);
1269 smtp_state(data, SMTP_STOP);
1278 static CURLcode smtp_multi_statemach(struct Curl_easy *data, bool *done)
1281 struct connectdata *conn = data->conn;
1286 result = Curl_conn_connect(data, FIRSTSOCKET, FALSE, &ssldone);
1292 result = Curl_pp_statemach(data, &smtpc->pp, FALSE, FALSE);
1298 static CURLcode smtp_block_statemach(struct Curl_easy *data,
1306 result = Curl_pp_statemach(data, &smtpc->pp, TRUE, disconnecting);
1313 static CURLcode smtp_init(struct Curl_easy *data)
1318 smtp = data->req.p.smtp = calloc(1, sizeof(struct SMTP));
1326 static int smtp_getsock(struct Curl_easy *data,
1329 return Curl_pp_getsock(data, &conn->proto.smtpc.pp, socks);
1342 static CURLcode smtp_connect(struct Curl_easy *data, bool *done)
1345 struct connectdata *conn = data->conn;
1357 Curl_sasl_init(&smtpc->sasl, data, &saslsmtp);
1368 result = smtp_parse_url_path(data);
1373 smtp_state(data, SMTP_SERVERGREET);
1375 result = smtp_multi_statemach(data, done);
1389 static CURLcode smtp_done(struct Curl_easy *data, CURLcode status,
1393 struct connectdata *conn = data->conn;
1394 struct SMTP *smtp = data->req.p.smtp;
1412 else if(!data->set.connect_only && data->set.mail_rcpt &&
1413 (data->state.upload || data->set.mimepost.kind)) {
1416 is "no mail data". RFC-5321, sect. 4.1.1.4.
1422 if(smtp->trailing_crlf || !data->state.infilesize) {
1434 /* Send the end of block data */
1435 result = Curl_write(data, conn->writesockfd, eob, len, &bytes_written);
1455 smtp_state(data, SMTP_POSTDATA);
1458 result = smtp_block_statemach(data, conn, FALSE);
1472 * or get some data according to the options previously setup.
1474 static CURLcode smtp_perform(struct Curl_easy *data, bool *connected,
1479 struct SMTP *smtp = data->req.p.smtp;
1481 DEBUGF(infof(data, "DO phase starts"));
1483 if(data->req.no_body) {
1491 smtp->rcpt = data->set.mail_rcpt;
1499 /* Initial data character is the first character in line: it is implicitly
1505 if((data->state.upload || data->set.mimepost.kind) && data->set.mail_rcpt)
1507 result = smtp_perform_mail(data);
1510 result = smtp_perform_command(data);
1516 result = smtp_multi_statemach(data, dophase_done);
1518 *connected = Curl_conn_is_connected(data->conn, FIRSTSOCKET);
1521 DEBUGF(infof(data, "DO phase is complete"));
1535 static CURLcode smtp_do(struct Curl_easy *data, bool *done)
1538 DEBUGASSERT(data);
1539 DEBUGASSERT(data->conn);
1543 result = smtp_parse_custom_request(data);
1547 result = smtp_regular_transfer(data, done);
1559 static CURLcode smtp_disconnect(struct Curl_easy *data,
1564 (void)data;
1571 if(!smtp_perform_quit(data, conn))
1572 (void)smtp_block_statemach(data, conn, TRUE); /* ignore errors on QUIT */
1588 static CURLcode smtp_dophase_done(struct Curl_easy *data, bool connected)
1590 struct SMTP *smtp = data->req.p.smtp;
1595 /* no data to transfer */
1596 Curl_setup_transfer(data, -1, -1, FALSE, -1);
1602 static CURLcode smtp_doing(struct Curl_easy *data, bool *dophase_done)
1604 CURLcode result = smtp_multi_statemach(data, dophase_done);
1607 DEBUGF(infof(data, "DO phase failed"));
1609 result = smtp_dophase_done(data, FALSE /* not connected */);
1611 DEBUGF(infof(data, "DO phase is complete"));
1626 static CURLcode smtp_regular_transfer(struct Curl_easy *data,
1633 data->req.size = -1;
1635 /* Set the progress data */
1636 Curl_pgrsSetUploadCounter(data, 0);
1637 Curl_pgrsSetDownloadCounter(data, 0);
1638 Curl_pgrsSetUploadSize(data, -1);
1639 Curl_pgrsSetDownloadSize(data, -1);
1642 result = smtp_perform(data, &connected, dophase_done);
1646 result = smtp_dophase_done(data, connected);
1651 static CURLcode smtp_setup_connection(struct Curl_easy *data,
1660 result = smtp_init(data);
1710 static CURLcode smtp_parse_url_path(struct Curl_easy *data)
1713 struct connectdata *conn = data->conn;
1715 const char *path = &data->state.up.path[1]; /* skip leading path */
1736 static CURLcode smtp_parse_custom_request(struct Curl_easy *data)
1739 struct SMTP *smtp = data->req.p.smtp;
1740 const char *custom = data->set.str[STRING_CUSTOMREQUEST];
1776 * the data to the server as a U-label (as per RFC-6531 sect. 3.2).
1821 CURLcode Curl_smtp_escape_eob(struct Curl_easy *data,
1829 data by the server
1833 struct SMTP *smtp = data->req.p.smtp;
1834 char *scratch = data->state.scratch;
1840 if(!scratch || data->set.crlf) {
1843 scratch = newscratch = malloc(2 * data->set.upload_buffer_size);
1845 failf(data, "Failed to alloc scratch buffer");
1850 DEBUGASSERT((size_t)data->set.upload_buffer_size >= (size_t)nread);
1858 memcpy(scratch, data->req.upload_fromhere, offset);
1860 if(SMTP_EOB[smtp->eob] == data->req.upload_fromhere[i]) {
1875 if(SMTP_EOB[0] == data->req.upload_fromhere[i])
1882 /* Reset the trailing CRLF flag as there was more data */
1888 /* Copy the replacement data to the target buffer */
1896 scratch[si++] = data->req.upload_fromhere[i];
1908 data->req.upload_fromhere = scratch;
1911 data->state.scratch = scratch;
1917 data->req.upload_present = si;