sysdis-project/plane/dep/client.c

501 lines
21 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html>
<head data-suburl="">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="author" content="xdrm-brackets" />
<meta name="description" content="proxy.ftp.c" />
<meta name="keywords" content="go, git, self-hosted, gogs">
<meta name="referrer" content="no-referrer" />
<meta name="_csrf" content="oL9HDhjy3U7tPSwjawLkQB4VNfA6MTQ5MDcxOTc2NTY0Nzg0MDkyNQ==" />
<meta name="_suburl" content="" />
<meta property="og:url" content="https://git.xdrm.io/xdrm-brackets/proxy.ftp.c" />
<meta property="og:type" content="object" />
<meta property="og:title" content="xdrm-brackets/proxy.ftp.c">
<meta property="og:description" content="">
<link rel="shortcut icon" href="/img/favicon.png" />
<script src="/js/jquery-1.11.3.min.js"></script>
<script src="/js/libs/jquery.are-you-sure.js"></script>
<link rel="stylesheet" href="/assets/font-awesome-4.6.3/css/font-awesome.min.css">
<link rel="stylesheet" href="/assets/octicons-4.3.0/octicons.min.css">
<link rel="stylesheet" href="/css/semantic-2.2.7.min.css">
<link rel="stylesheet" href="/css/gogs.css?v=73519fd9811805bce6fc4aa2d24bb413">
<script src="/js/semantic-2.2.7.min.js"></script>
<script src="/js/gogs.js?v=73519fd9811805bce6fc4aa2d24bb413"></script>
<title>xdrm-brackets/proxy.ftp.c - xdrm-brackets&#39; git server</title>
<meta name="theme-color" content="#ff5343">
</head>
<body>
<div class="full height">
<noscript>Please enable JavaScript in your browser!</noscript>
<div class="following bar light">
<div class="ui container">
<div class="ui grid">
<div class="column">
<div class="ui top secondary menu">
<a class="item brand" href="/">
<img class="ui mini image" src="/img/favicon.png">
</a>
<a class="item" href="/">Home</a>
<a class="item" href="/explore/repos">Explore</a>
<a class="item" target="_blank" href="https://gogs.io/docs" rel="noreferrer">Help</a>
<div class="right menu">
<a class="item" href="/user/sign_up">
<i class="octicon octicon-person"></i> Register
</a>
<a class="item" href="/user/login?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
<i class="octicon octicon-sign-in"></i> Sign In
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="repository file list">
<div class="header-wrapper">
<div class="ui container">
<div class="ui vertically padded grid head">
<div class="column">
<div class="ui header">
<div class="ui huge breadcrumb">
<i class="mega-octicon octicon-repo"></i>
<a href="/xdrm-brackets">xdrm-brackets</a>
<div class="divider"> / </div>
<a href="/xdrm-brackets/proxy.ftp.c">proxy.ftp.c</a>
</div>
<div class="ui right">
<div class="ui labeled button" tabindex="0">
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/watch?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
<i class="icon fa-eye-slash"></i>Watch
</a>
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/watchers">
1
</a>
</div>
<div class="ui labeled button" tabindex="0">
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/action/star?redirect_to=%2fxdrm-brackets%2fproxy.ftp.c%2fsrc%2fmaster%2fdep%2fclient.c">
<i class="icon fa-star-o"></i>Star
</a>
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/stars">
0
</a>
</div>
<div class="ui labeled button" tabindex="0">
<a class="ui button " href="/repo/fork/49">
<i class="octicon octicon-repo-forked"></i>Fork
</a>
<a class="ui basic label" href="/xdrm-brackets/proxy.ftp.c/forks">
0
</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="ui tabs container">
<div class="ui tabular menu navbar">
<a class="active item" href="/xdrm-brackets/proxy.ftp.c">
<i class="octicon octicon-file-text"></i> Files
</a>
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/issues">
<i class="octicon octicon-issue-opened"></i> Issues <span class="ui gray small label">0</span>
</a>
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/pulls">
<i class="octicon octicon-git-pull-request"></i> Pull Requests <span class="ui gray small label">0</span>
</a>
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/commits/master">
<i class="octicon octicon-history"></i> Commits <span class="ui blue small label">23</span>
</a>
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/releases">
<i class="octicon octicon-tag"></i> Releases <span class="ui gray small label">0</span>
</a>
<a class=" item" href="/xdrm-brackets/proxy.ftp.c/wiki">
<i class="octicon octicon-book"></i> Wiki
</a>
</div>
</div>
<div class="ui tabs divider"></div>
</div>
<div class="ui container">
<p id="repo-desc">
<span class="no-description text-italic">No Description</span>
<a class="link" href=""></a>
</p>
<div class="ui secondary menu">
<div class="fitted item choose reference">
<div class="ui floating filter dropdown" data-no-results="No results found.">
<div class="ui basic small button">
<span class="text">
<i class="octicon octicon-git-branch"></i>
Branch:
<strong>master</strong>
</span>
<i class="dropdown icon"></i>
</div>
<div class="menu">
<div class="ui icon search input">
<i class="filter icon"></i>
<input name="search" placeholder="Filter branch or tag...">
</div>
<div class="header">
<div class="ui grid">
<div class="two column row">
<a class="reference column" href="#" data-target="#branch-list">
<span class="text black">
<i class="octicon octicon-git-branch"></i> Branches
</span>
</a>
<a class="reference column" href="#" data-target="#tag-list">
<span class="text ">
<i class="reference tags icon"></i> Tags
</span>
</a>
</div>
</div>
</div>
<div id="branch-list" class="scrolling menu" >
<div class="item selected" data-url="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c">master</div>
</div>
<div id="tag-list" class="scrolling menu" style="display: none">
</div>
</div>
</div>
</div>
<div class="fitted item">
<div class="ui breadcrumb">
<a class="section" href="/xdrm-brackets/proxy.ftp.c/src/master">proxy.ftp.c</a>
<div class="divider"> / </div>
<span class="section"><a href="/xdrm-brackets/proxy.ftp.c/src/master/dep">dep</a></span>
<div class="divider"> / </div>
<span class="active section">client.c</span>
</div>
</div>
<div class="right fitted item">
<div id="file-buttons" class="ui tiny blue buttons">
</div>
</div>
</div>
<div id="file-content" class="tab-size-8">
<h4 class="ui top attached header" id="repo-read-file">
<i class="file text outline icon ui left"></i>
<strong>client.c</strong> <span class="text grey normal">3.9KB</span>
<div class="ui right file-actions">
<div class="ui buttons">
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/src/18a5e4338baaec92912eee057d26004b57b0b2a0/dep/client.c">Permalink</a>
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/commits/master/dep/client.c">History</a>
<a class="ui button" href="/xdrm-brackets/proxy.ftp.c/raw/master/dep/client.c">Raw</a>
</div>
<i class="octicon octicon-pencil btn-octicon poping up disabled" data-content="You must fork this repository before editing the file" data-position="bottom center" data-variation="tiny inverted"></i>
<i class="octicon octicon-trashcan btn-octicon poping up disabled" data-content="You must have write access to make or propose changes to this file" data-position="bottom center" data-variation="tiny inverted"></i>
</div>
</h4>
<div class="ui attached table segment">
<div id="" class="file-view code-view has-emoji">
<table>
<tbody>
<tr>
<td class="lines-num"><span id="L1">1</span><span id="L2">2</span><span id="L3">3</span><span id="L4">4</span><span id="L5">5</span><span id="L6">6</span><span id="L7">7</span><span id="L8">8</span><span id="L9">9</span><span id="L10">10</span><span id="L11">11</span><span id="L12">12</span><span id="L13">13</span><span id="L14">14</span><span id="L15">15</span><span id="L16">16</span><span id="L17">17</span><span id="L18">18</span><span id="L19">19</span><span id="L20">20</span><span id="L21">21</span><span id="L22">22</span><span id="L23">23</span><span id="L24">24</span><span id="L25">25</span><span id="L26">26</span><span id="L27">27</span><span id="L28">28</span><span id="L29">29</span><span id="L30">30</span><span id="L31">31</span><span id="L32">32</span><span id="L33">33</span><span id="L34">34</span><span id="L35">35</span><span id="L36">36</span><span id="L37">37</span><span id="L38">38</span><span id="L39">39</span><span id="L40">40</span><span id="L41">41</span><span id="L42">42</span><span id="L43">43</span><span id="L44">44</span><span id="L45">45</span><span id="L46">46</span><span id="L47">47</span><span id="L48">48</span><span id="L49">49</span><span id="L50">50</span><span id="L51">51</span><span id="L52">52</span><span id="L53">53</span><span id="L54">54</span><span id="L55">55</span><span id="L56">56</span><span id="L57">57</span><span id="L58">58</span><span id="L59">59</span><span id="L60">60</span><span id="L61">61</span><span id="L62">62</span><span id="L63">63</span><span id="L64">64</span><span id="L65">65</span><span id="L66">66</span><span id="L67">67</span><span id="L68">68</span><span id="L69">69</span><span id="L70">70</span><span id="L71">71</span><span id="L72">72</span><span id="L73">73</span><span id="L74">74</span><span id="L75">75</span><span id="L76">76</span><span id="L77">77</span><span id="L78">78</span><span id="L79">79</span><span id="L80">80</span><span id="L81">81</span><span id="L82">82</span><span id="L83">83</span><span id="L84">84</span><span id="L85">85</span><span id="L86">86</span><span id="L87">87</span><span id="L88">88</span><span id="L89">89</span><span id="L90">90</span><span id="L91">91</span><span id="L92">92</span><span id="L93">93</span><span id="L94">94</span><span id="L95">95</span><span id="L96">96</span><span id="L97">97</span><span id="L98">98</span><span id="L99">99</span><span id="L100">100</span><span id="L101">101</span><span id="L102">102</span><span id="L103">103</span><span id="L104">104</span><span id="L105">105</span><span id="L106">106</span><span id="L107">107</span></td>
<td class="lines-code"><pre><code class="c"><ol class="linenums"><li class="L1" rel="L1">#include &#34;client.h&#34;</li>
<li class="L2" rel="L2"></li>
<li class="L3" rel="L3"></li>
<li class="L4" rel="L4">int CONNECT_CLIENT(char* serverHost, char* serverPort, int* pSocket){</li>
<li class="L5" rel="L5"> if( DEBUGMOD&amp;HDR ) printf(&#34;====== CONNECT_CLIENT(%s, %s, %d) ======\n\n&#34;, serverHost, serverPort, *pSocket);</li>
<li class="L6" rel="L6"></li>
<li class="L7" rel="L7"> struct addrinfo hints; // contiendra le filtre/format</li>
<li class="L8" rel="L8"> struct addrinfo* addrinfo; // contiendra les infos</li>
<li class="L9" rel="L9"> int CONNECT; // file_desc(s)</li>
<li class="L10" rel="L10"> int GETADDRINFO; // contiendra l&#39;erreur ou pas de getaddrinfo()</li>
<li class="L11" rel="L11"> char BUFFER[MAX_BUF_LEN]; // BUFFER de communication</li>
<li class="L12" rel="L12"></li>
<li class="L13" rel="L13"> /* [1] On définit le filtre/format</li>
<li class="L14" rel="L14"> =======================================================*/</li>
<li class="L15" rel="L15"> memset(&amp;hints, 0, sizeof(struct addrinfo)); // on vide le filtre</li>
<li class="L16" rel="L16"> hints.ai_family = AF_UNSPEC; // Allow IPv4 ou IPv6</li>
<li class="L17" rel="L17"> hints.ai_socktype = SOCK_STREAM; // TCP (SOCK_DGRAM = UDP)</li>
<li class="L18" rel="L18"> hints.ai_flags = 0; // non spécifié</li>
<li class="L19" rel="L19"> hints.ai_protocol = 0; // non spécifié</li>
<li class="L20" rel="L20"></li>
<li class="L21" rel="L21"> if( DEBUGMOD&amp;SCK ) printf(&#34;============HINTS===========\n&#34;);</li>
<li class="L22" rel="L22"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_FLAGS = %d\n&#34;, hints.ai_flags ); // int</li>
<li class="L23" rel="L23"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_FAMILY = %d\n&#34;, hints.ai_family ); // int</li>
<li class="L24" rel="L24"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_SOCKTYPE = %d\n&#34;, hints.ai_socktype ); // int</li>
<li class="L25" rel="L25"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_PROTOCOL = %d\n&#34;, hints.ai_protocol ); // int</li>
<li class="L26" rel="L26"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_ADDRLEN = %d\n&#34;, hints.ai_addrlen ); // int</li>
<li class="L27" rel="L27"> if( DEBUGMOD&amp;SCK ) printf(&#34;\n&#34;);</li>
<li class="L28" rel="L28"></li>
<li class="L29" rel="L29"></li>
<li class="L30" rel="L30"> /* [2] On récupère les infos</li>
<li class="L31" rel="L31"> =======================================================*/</li>
<li class="L32" rel="L32"> GETADDRINFO = getaddrinfo(serverHost, serverPort, &amp;hints, &amp;addrinfo);</li>
<li class="L33" rel="L33"></li>
<li class="L34" rel="L34"> // si erreur</li>
<li class="L35" rel="L35"> if( GETADDRINFO &lt; 0 ) return -1;</li>
<li class="L36" rel="L36"></li>
<li class="L37" rel="L37"> if( DEBUGMOD&amp;SCK ) printf(&#34;=============RES============\n&#34;);</li>
<li class="L38" rel="L38"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_FLAGS = %d\n&#34;, addrinfo-&gt;ai_flags ); // int</li>
<li class="L39" rel="L39"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_FAMILY = %d\n&#34;, addrinfo-&gt;ai_family ); // int</li>
<li class="L40" rel="L40"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_SOCKTYPE = %d\n&#34;, addrinfo-&gt;ai_socktype ); // int</li>
<li class="L41" rel="L41"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_PROTOCOL = %d\n&#34;, addrinfo-&gt;ai_protocol ); // int</li>
<li class="L42" rel="L42"> if( DEBUGMOD&amp;SCK ) printf( &#34;AI_ADDRLEN = %d\n&#34;, addrinfo-&gt;ai_addrlen ); // int</li>
<li class="L43" rel="L43"> if( DEBUGMOD&amp;SCK ) printf(&#34;\n&#34;);</li>
<li class="L44" rel="L44"></li>
<li class="L45" rel="L45"> /* [3] Création de la socket</li>
<li class="L46" rel="L46"> =======================================================*/</li>
<li class="L47" rel="L47"> *pSocket = socket(addrinfo-&gt;ai_family, addrinfo-&gt;ai_socktype, 0);</li>
<li class="L48" rel="L48"></li>
<li class="L49" rel="L49"> if( DEBUGMOD&amp;SCK ) printf(&#34;SOCKET = %d\n&#34;, *pSocket);</li>
<li class="L50" rel="L50"></li>
<li class="L51" rel="L51"> // si erreur</li>
<li class="L52" rel="L52"> if( *pSocket == -1 ) return -1;</li>
<li class="L53" rel="L53"></li>
<li class="L54" rel="L54"></li>
<li class="L55" rel="L55"> /* [4] On établit la connection</li>
<li class="L56" rel="L56"> =======================================================*/</li>
<li class="L57" rel="L57"> CONNECT = connect(</li>
<li class="L58" rel="L58"> *pSocket,</li>
<li class="L59" rel="L59"> addrinfo-&gt;ai_addr,</li>
<li class="L60" rel="L60"> addrinfo-&gt;ai_addrlen</li>
<li class="L61" rel="L61"> );</li>
<li class="L62" rel="L62"></li>
<li class="L63" rel="L63"> if( DEBUGMOD&amp;SCK ) printf(&#34;CONNECT = %d\n&#34;, CONNECT);</li>
<li class="L64" rel="L64"></li>
<li class="L65" rel="L65"> // si erreur</li>
<li class="L66" rel="L66"> if( CONNECT == -1 ) return -1;</li>
<li class="L67" rel="L67"></li>
<li class="L68" rel="L68"> // on a plus besoin des infos de l&#39;adresse</li>
<li class="L69" rel="L69"> freeaddrinfo(addrinfo);</li>
<li class="L70" rel="L70"></li>
<li class="L71" rel="L71"></li>
<li class="L72" rel="L72"> /* [5] On retourne la SOCKET</li>
<li class="L73" rel="L73"> =======================================================*/</li>
<li class="L74" rel="L74"> return *pSocket;</li>
<li class="L75" rel="L75">}</li>
<li class="L76" rel="L76"></li>
<li class="L77" rel="L77"></li>
<li class="L78" rel="L78"></li>
<li class="L79" rel="L79"></li>
<li class="L80" rel="L80"></li>
<li class="L81" rel="L81"></li>
<li class="L82" rel="L82">int CLIENT_SEND(int* pSocket, char* pRequest, char** pAnswer){</li>
<li class="L83" rel="L83"> if( DEBUGMOD&amp;HDR ) printf(&#34;====== CLIENT_SEND(%d, %s, %s) ======\n\n&#34;, *pSocket, pRequest, *pAnswer);</li>
<li class="L84" rel="L84"> char BUFFER[MAX_BUF_LEN] = {0};</li>
<li class="L85" rel="L85"></li>
<li class="L86" rel="L86"> /* [1] On écrit sur la socket</li>
<li class="L87" rel="L87"> =======================================================*/</li>
<li class="L88" rel="L88"> int nbSend = swrite(pSocket, pRequest);</li>
<li class="L89" rel="L89"></li>
<li class="L90" rel="L90"> if( DEBUGMOD&amp;BUF ) printf(&#34;nbSend: %d\n&#34;, nbSend);</li>
<li class="L91" rel="L91"> if( DEBUGMOD&amp;BUF ) printf(&#34;Message: %s\n&#34;, pRequest);</li>
<li class="L92" rel="L92"></li>
<li class="L93" rel="L93"> // si pas tout envoyé</li>
<li class="L94" rel="L94"> if( strlen(pRequest) != nbSend ) return -1;</li>
<li class="L95" rel="L95"></li>
<li class="L96" rel="L96"> /* [2] On attends et lit la réponse</li>
<li class="L97" rel="L97"> =======================================================*/</li>
<li class="L98" rel="L98"> int nbRecup = WAIT_SOCKET_UPDATE(pSocket, BUFFER);</li>
<li class="L99" rel="L99"></li>
<li class="L100" rel="L100"> /* [3] On retourne la réponse par référence</li>
<li class="L101" rel="L101"> =======================================================*/</li>
<li class="L102" rel="L102"> *pAnswer = malloc( MAX_BUF_LEN );</li>
<li class="L103" rel="L103"> strcpy(*pAnswer, BUFFER);</li>
<li class="L104" rel="L104"></li>
<li class="L105" rel="L105"> if( DEBUGMOD&amp;BUF ) printf(&#34;nbReceived: %d\n&#34;, nbRecup);</li>
<li class="L106" rel="L106"> if( DEBUGMOD&amp;BUF ) printf(&#34;Message: %s\n&#34;, *pAnswer);</li>
<li class="L107" rel="L107">}</li>
</ol></code></pre></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<script>
function submitDeleteForm() {
var message = prompt("delete_confirm_message\n\ndelete_commit_summary", "Delete ''");
if (message != null) {
$("#delete-message").val(message);
$("#delete-file-form").submit()
}
}
</script>
</div>
</div>
</div>
<footer>
<div class="ui container">
<div class="ui left">
© 2017 Gogs Version: 0.10.10.0308 Page: <strong>52ms</strong> Template: <strong>2ms</strong>
</div>
<div class="ui right links">
<div class="ui language bottom floating slide up dropdown link item">
<i class="world icon"></i>
<div class="text">English</div>
<div class="menu">
<a class="item active selected" href="#">English</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-CN"></a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-HK"></a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=zh-TW"></a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=de-DE">Deutsch</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=fr-FR">Français</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=nl-NL">Nederlands</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=lv-LV">Latviešu</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=ru-RU">Русский</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=ja-JP"></a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=es-ES">Español</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=pt-BR">Português do Brasil</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=pl-PL">Polski</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=bg-BG">български</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=it-IT">Italiano</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=fi-FI">Suomalainen</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=tr-TR">Türkçe</a>
<a class="item " href="/xdrm-brackets/proxy.ftp.c/src/master/dep/client.c?lang=cs-CZ">čeština</a>
</div>
</div>
<a href="/assets/librejs/librejs.html" style="display:none" data-jslicense="1">Javascript Licenses</a>
<a target="_blank" href="https://gogs.io">Website</a>
<span class="version">Go1.8</span>
</div>
</div>
</footer>
</body>
<link rel="stylesheet" href="/plugins/highlight-9.6.0/github.css">
<script src="/plugins/highlight-9.6.0/highlight.pack.js"></script>
<script src="/js/libs/emojify-1.1.0.min.js"></script>
<script src="/js/libs/clipboard-1.5.9.min.js"></script>
</html>