master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24/* <DESC>
25 * Send SMTP email with the multi interface
26 * </DESC>
27 */
28#include <string.h>
30#include <curl/curl.h>
32/* This is an example showing how to send mail using libcurl's SMTP
33 * capabilities. It builds on the smtp-mail.c example to demonstrate how to use
34 * libcurl's multi interface.
35 */
37#define FROM_MAIL "<sender@example.com>"
38#define TO_MAIL "<recipient@example.com>"
39#define CC_MAIL "<info@example.com>"
41static const char payload_text[] =
42 "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n"
43 "To: " TO_MAIL "\r\n"
44 "From: " FROM_MAIL "\r\n"
45 "Cc: " CC_MAIL "\r\n"
46 "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
47 "rfcpedant.example.org>\r\n"
48 "Subject: SMTP example message\r\n"
49 "\r\n" /* empty line to divide headers from body, see RFC 5322 */
50 "The body of the message starts here.\r\n"
51 "\r\n"
52 "It could be a lot of lines, could be MIME encoded, whatever.\r\n"
53 "Check RFC 5322.\r\n";
55struct upload_status {
56 size_t bytes_read;
57};
59static size_t read_cb(char *ptr, size_t size, size_t nmemb, void *userp)
60{
61 struct upload_status *upload_ctx = (struct upload_status *)userp;
62 const char *data;
63 size_t room = size * nmemb;
64 size_t len;
66 if((size == 0) || (nmemb == 0) || ((size * nmemb) < 1)) {
67 return 0;
68 }
70 data = &payload_text[upload_ctx->bytes_read];
72 len = strlen(data);
73 if(room < len)
74 len = room;
75 memcpy(ptr, data, len);
76 upload_ctx->bytes_read += len;
78 return len;
79}
81int main(void)
82{
83 CURL *curl;
85 CURLcode result = curl_global_init(CURL_GLOBAL_ALL);
86 if(result != CURLE_OK)
87 return (int)result;
89 curl = curl_easy_init();
90 if(curl) {
91 CURLM *multi;
93 multi = curl_multi_init();
94 if(multi) {
95 int still_running = 1;
96 struct curl_slist *recipients = NULL;
97 struct upload_status upload_ctx = { 0 };
99 /* This is the URL for your mailserver */
100 curl_easy_setopt(curl, CURLOPT_URL, "smtp://mail.example.com");
102 /* Note that this option is not strictly required, omitting it results
103 * in libcurl sending the MAIL FROM command with empty sender data. All
104 * autoresponses should have an empty reverse-path, and should be
105 * directed to the address in the reverse-path which triggered them.
106 * Otherwise, they could cause an endless loop. See RFC 5321 Section
107 * 4.5.5 for more details.
108 */
109 curl_easy_setopt(curl, CURLOPT_MAIL_FROM, FROM_MAIL);
111 /* Add two recipients, in this particular case they correspond to the
112 * To: and Cc: addressees in the header, but they could be any kind of
113 * recipient. */
114 recipients = curl_slist_append(recipients, TO_MAIL);
115 recipients = curl_slist_append(recipients, CC_MAIL);
116 curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
118 /* We are using a callback function to specify the payload (the headers
119 * and body of the message). You can use the CURLOPT_READDATA option to
120 * specify a FILE pointer to read from. */
121 curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_cb);
122 curl_easy_setopt(curl, CURLOPT_READDATA, &upload_ctx);
123 curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
125 /* Tell the multi stack about our easy handle */
126 curl_multi_add_handle(multi, curl);
128 do {
129 CURLMcode mresult = curl_multi_perform(multi, &still_running);
131 if(still_running)
132 /* wait for activity, timeout or "nothing" */
133 mresult = curl_multi_poll(multi, NULL, 0, 1000, NULL);
135 if(mresult)
136 break;
138 } while(still_running);
140 /* Free the list of recipients */
141 curl_slist_free_all(recipients);
143 /* Always cleanup */
144 curl_multi_remove_handle(multi, curl);
145 curl_multi_cleanup(multi);
146 }
147 curl_easy_cleanup(curl);
148 }
150 curl_global_cleanup();
152 return 0;
153}
Diagnostics4 git calls · 34 ms
CallStatusSizeTime034 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2002.1 KiB · hit28 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=28 git.response.bytes=2136 git.response.cache=HIT git.response.duration_ms=28 git.fetch.wants=9d76a57fe71758cf3ceac5cfdef918b7472eb966 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2136 git.pkt.payload.max=2115 git.sideband.band1.bytes=2114 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e19f9e9ce03cd0
- Request
- 89aa08af…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format