\hypertarget{ecore_con_client_example_8c-example}{}\section{ecore\+\_\+con\+\_\+client\+\_\+example.\+c}
Shows how to write a simple client (dialer that connects to the example server using \mbox{\hyperlink{group__Ecore__Con__Server__Group_gae3d7391f7da5e0f748d7b6804d010b2f}{ecore\+\_\+con\+\_\+server\+\_\+connect()}}.


\begin{DoxyCodeInclude}
\textcolor{comment}{//Compile with:}
\textcolor{comment}{// gcc -o ecore\_con\_client\_example ecore\_con\_client\_example.c `pkg-config --libs --cflags ecore ecore-con
       eina`}

\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}
\textcolor{preprocessor}{#include "config.h"}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <Ecore.h>}
\textcolor{preprocessor}{#include <Ecore\_Con.h>}
\textcolor{preprocessor}{#include <Ecore\_Getopt.h>}

\textcolor{comment}{/* Ecore\_Con client example}
\textcolor{comment}{ * 2010 Mike Blumenkrantz}
\textcolor{comment}{ */}

\textcolor{keyword}{static} \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga80f90f9716013d6104624c2e606f8915}{Ecore\_Con\_Server}} *svr;
\textcolor{keyword}{static} \textcolor{keywordtype}{int} retval = EXIT\_SUCCESS;
\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} do\_flush = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};
\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} single\_message = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};
\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} verify = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};
\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} hostname\_verify = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};
\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} do\_ssl\_upgrade = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};
\textcolor{keyword}{static} \textcolor{keywordtype}{char} *starttls\_local\_command = NULL;

\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_setup\_ssl(\textcolor{keywordtype}{void})
\{
   \mbox{\hyperlink{struct__Eina__Iterator}{Eina\_Iterator}} *it;
   \textcolor{keyword}{const} \textcolor{keywordtype}{char} *ca;

   \textcolor{keywordflow}{if} (!(it = \mbox{\hyperlink{group__Eina__File__Group_ga8c4fabb379b865a4ec134a5c4436be2a}{eina\_file\_ls}}(\textcolor{stringliteral}{"/etc/ssl/certs"})))
     \{
        retval = EXIT\_FAILURE;
        \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};
     \}

   \textcolor{comment}{/* add all the CAs */}
   \mbox{\hyperlink{group__Eina__Iterator__Group_gac7314580e18868ef229f5d2814562794}{EINA\_ITERATOR\_FOREACH}}(it, ca)
     \{
        \textcolor{keywordflow}{if} (!\mbox{\hyperlink{group__Ecore__Con__SSL__Group_ga48d588d6dd1fb2710c64c57d20bd795c}{ecore\_con\_ssl\_server\_cafile\_add}}(svr, ca))
          fprintf(stderr, \textcolor{stringliteral}{"WARNING: could not load CA: %s!\(\backslash\)n"}, ca);
        \mbox{\hyperlink{group__Eina__Stringshare__Group_ga495411b0bc85b9c0d59ec7255a025260}{eina\_stringshare\_del}}(ca);
     \}

   \mbox{\hyperlink{group__Eina__Iterator__Group_gaf9261991a4b05dc63e3401278a3281f8}{eina\_iterator\_free}}(it);

   \textcolor{keywordflow}{if} (verify)
     \mbox{\hyperlink{group__Ecore__Con__SSL__Group_ga72320d4fd96ea97997850d1fc32a88b7}{ecore\_con\_ssl\_server\_verify}}(svr);

   \textcolor{keywordflow}{if} (hostname\_verify)
     \mbox{\hyperlink{group__Ecore__Con__SSL__Group_ga6ceab74f3cdf03a7485acddda01ebd17}{ecore\_con\_ssl\_server\_verify\_basic}}(svr);

   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};
\}

\textcolor{keyword}{static} \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_on\_stdin(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \mbox{\hyperlink{group__Ecore__FD__Handler__Group_ga225121ed2123da4b52b76aa08d78c220}{Ecore\_Fd\_Handler}} *fdh 
      \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})
\{
   \textcolor{keywordtype}{char} *line = NULL;
\textcolor{preprocessor}{#ifdef \_WIN32}
   \textcolor{keywordtype}{char} lbuf[4096] = \textcolor{stringliteral}{""};
   ssize\_t r;
   \textcolor{keywordflow}{if} (fgets(lbuf, \textcolor{keyword}{sizeof}(lbuf), stdin) == NULL)
     r = -1;
   \textcolor{keywordflow}{else}
     \{
        line = strdup(lbuf);
        r = strlen(line);
     \}
\textcolor{preprocessor}{#else}
   \textcolor{keywordtype}{size\_t} len = 0;
   ssize\_t r = getline(&line, &len, stdin);
\textcolor{preprocessor}{#endif}

   \textcolor{keywordflow}{if} (r < 0)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"ERROR: could not read from stdin: %s\(\backslash\)n"}, strerror(errno));
        \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gae0c653baad8836232c0dc27f91f875d6}{ECORE\_CALLBACK\_CANCEL}};
     \}

   \textcolor{keywordflow}{if} (!svr)
     fputs(\textcolor{stringliteral}{"WARNING: not connected to server, ignored input.\(\backslash\)n"}, stderr);
   \textcolor{keywordflow}{else}
     \{
        \textcolor{keywordtype}{size\_t} clen = strlen(starttls\_local\_command);
        \textcolor{keywordflow}{if} (do\_ssl\_upgrade && ((\textcolor{keywordtype}{size\_t})r > clen) &&
            (strncmp(line, starttls\_local\_command, clen) == 0) &&
            (line[clen] == \textcolor{charliteral}{'\(\backslash\)n'} || line[clen] == \textcolor{charliteral}{'\(\backslash\)r'}))
          \{
             printf(\textcolor{stringliteral}{"INFO: starting SSL communication...\(\backslash\)n"});

             \textcolor{keywordflow}{if} (!\mbox{\hyperlink{group__Ecore__Con__SSL__Group_gadf006c82929e4bc6cb1cef4f6b7fcbb4}{ecore\_con\_ssl\_server\_upgrade}}(svr, ECORE\_CON\_USE\_MIXED | 
      ECORE\_CON\_LOAD\_CERT))
               \{
                  printf(\textcolor{stringliteral}{"ERROR: failed to upgrade to SSL!\(\backslash\)n"});
                  retval = EXIT\_FAILURE;
                  \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga79c76b9f725ceda216e9c7e5caf6cbd9}{ecore\_con\_server\_del}}(svr);
                  \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();
               \}

\textcolor{preprocessor}{#if 1}
             \textcolor{comment}{/* This just works since EFL v 1.19.  Prior to this,}
\textcolor{comment}{              * upgrade couldn't get any extra setup, such as}
\textcolor{comment}{              * certificate or verification mode as OpenSSL would}
\textcolor{comment}{              * complain.}
\textcolor{comment}{              */}
             \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (!\_setup\_ssl())
               \{
                  retval = EXIT\_FAILURE;
                  \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga79c76b9f725ceda216e9c7e5caf6cbd9}{ecore\_con\_server\_del}}(svr);
                  \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();
               \}
\textcolor{preprocessor}{#endif}

             svr = NULL; \textcolor{comment}{/* it's considered dead until ECORE\_CON\_EVENT\_SERVER\_UPGRADE */}
             \textcolor{keywordflow}{goto} end;
          \}
        \mbox{\hyperlink{group__Ecore__Con__Server__Group_gadf16abc2d4fc16a8b65709eab2cd8337}{ecore\_con\_server\_send}}(svr, line, r);
        printf(\textcolor{stringliteral}{"INFO: sent %zd bytes to server.\(\backslash\)n"}, r);
        \textcolor{keywordflow}{if} (do\_flush) \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga3ddb6c88484b59a1f5a5bacb8b6e60fe}{ecore\_con\_server\_flush}}(svr);
        \textcolor{keywordflow}{if} (single\_message)
          \{
             \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga79c76b9f725ceda216e9c7e5caf6cbd9}{ecore\_con\_server\_del}}(svr);
             svr = NULL;
             \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();
          \}
     \}

 end:
   free(line);

   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};
\}

\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_add(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, 
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add}{Ecore\_Con\_Event\_Server\_Add}} *ev)
\{
   printf(\textcolor{stringliteral}{"Server with ip %s connected!\(\backslash\)n"}, \mbox{\hyperlink{group__Ecore__Con__Server__Group_gaea2a907ae4ca478a360928fd16654d45}{ecore\_con\_server\_ip\_get}}(ev->
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}}));
   \textcolor{keywordflow}{if} (do\_ssl\_upgrade)
     printf(\textcolor{stringliteral}{"INFO: Not sending 'hello!' in tcp+ssl mode. Use: %s to upgrade the connection\(\backslash\)n"}, 
      starttls\_local\_command);
   \textcolor{keywordflow}{else}
     \mbox{\hyperlink{group__Ecore__Con__Server__Group_gadf16abc2d4fc16a8b65709eab2cd8337}{ecore\_con\_server\_send}}(ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}}, \textcolor{stringliteral}{"hello!"}, strlen(\textcolor{stringliteral}{"hello!"}));
   \textcolor{keywordflow}{if} (do\_flush) \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga3ddb6c88484b59a1f5a5bacb8b6e60fe}{ecore\_con\_server\_flush}}(ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Add_a382a9545ed7fb941a30dc4d598dc7e4d}{server}});

   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};
\}

\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_del(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, 
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Del}{Ecore\_Con\_Event\_Server\_Del}} *ev)
\{
   printf(\textcolor{stringliteral}{"Lost server with ip %s!\(\backslash\)n"}, \mbox{\hyperlink{group__Ecore__Con__Server__Group_gaea2a907ae4ca478a360928fd16654d45}{ecore\_con\_server\_ip\_get}}(ev->
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Del_a116963b404600e7154c61f94ebf52a2e}{server}}));
   \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga79c76b9f725ceda216e9c7e5caf6cbd9}{ecore\_con\_server\_del}}(svr);
   svr = NULL;
   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga95cf8e97dff0716433c2c5474d606a98}{ecore\_main\_loop\_quit}}();
   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};
\}

\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_data(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, 
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data}{Ecore\_Con\_Event\_Server\_Data}} *ev)
\{
   printf(\textcolor{stringliteral}{"Received %i bytes from server:\(\backslash\)n"}
          \textcolor{stringliteral}{">>>>>\(\backslash\)n"}
          \textcolor{stringliteral}{"%.*s\(\backslash\)n"}
          \textcolor{stringliteral}{">>>>>\(\backslash\)n"},
          ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data_a41877d1f1cb9792508b9b1d89d53bec2}{size}},
          ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data_a41877d1f1cb9792508b9b1d89d53bec2}{size}}, (\textcolor{keyword}{const} \textcolor{keywordtype}{char} *)ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Data_a8d45b6d75c55b26771d241211a0d7e7e}{data}});

   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};
\}

\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_write\_(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, 
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Write}{Ecore\_Con\_Event\_Server\_Write}} *ev)
\{
   printf(\textcolor{stringliteral}{"Sent %d bytes to server\(\backslash\)n"}, ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Write_ab6851a4fc081e2c0c6916742427cdab7}{size}});
   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};
\}

\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_error(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, 
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Error}{Ecore\_Con\_Event\_Server\_Error}} *ev)
\{
   printf(\textcolor{stringliteral}{"Server Error: %s\(\backslash\)n"}, ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Error_a716e87090f7ec3ef8b7aab9d1ca0c047}{error}});
   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};
\}

\mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}}
\_upgrade(\textcolor{keywordtype}{void} *data \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{int} type \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, 
      \mbox{\hyperlink{struct__Ecore__Con__Event__Server__Upgrade}{Ecore\_Con\_Event\_Server\_Upgrade}} *ev)
\{
   printf(\textcolor{stringliteral}{"Server upgraded to SSL %p %s\(\backslash\)n"}, ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Upgrade_a551692c9afdd9a3b3020b519069e36f3}{server}}, 
      \mbox{\hyperlink{group__Ecore__Con__Server__Group_gaea2a907ae4ca478a360928fd16654d45}{ecore\_con\_server\_ip\_get}}(ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Upgrade_a551692c9afdd9a3b3020b519069e36f3}{server}}));
   svr = ev->\mbox{\hyperlink{struct__Ecore__Con__Event__Server__Upgrade_a551692c9afdd9a3b3020b519069e36f3}{server}};
   \textcolor{keywordflow}{return} \mbox{\hyperlink{group__Ecore__Main__Loop__Group_ga1ee9db07f9a46a8b20fb83e1c6dbed09}{ECORE\_CALLBACK\_RENEW}};
\}

\textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *types\_strs[] = \{
  \textcolor{stringliteral}{"tcp"},
  \textcolor{stringliteral}{"udp"},
  \textcolor{stringliteral}{"ssl"},
  \textcolor{stringliteral}{"tcp+ssl"},
  \textcolor{stringliteral}{"local-user"},
  \textcolor{stringliteral}{"local-system"},
  NULL
\};

\textcolor{keyword}{static} \textcolor{keyword}{const} \mbox{\hyperlink{struct__Ecore__Getopt}{Ecore\_Getopt}} options = \{
  \textcolor{stringliteral}{"ecore\_con\_client\_example"}, \textcolor{comment}{/* program name */}
  NULL, \textcolor{comment}{/* usage line */}
  \textcolor{stringliteral}{"1"}, \textcolor{comment}{/* version */}
  \textcolor{stringliteral}{"(C) 2016 Enlightenment Project; 2010 Mike Blumenkrantz"}, \textcolor{comment}{/* copyright */}
  \textcolor{stringliteral}{"BSD 2-Clause"}, \textcolor{comment}{/* license */}
  \textcolor{comment}{/* long description, may be multiline and contain \(\backslash\)n */}
  \textcolor{stringliteral}{"Example of ecore\_con\_server\_connect()\(\backslash\)n"},
  \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}},
  \{
    \mbox{\hyperlink{group__Ecore__Getopt__Group_ga0bceaa55f928e281a24be27089d4b8d6}{ECORE\_GETOPT\_CHOICE}}(\textcolor{charliteral}{'t'}, \textcolor{stringliteral}{"type"}, \textcolor{stringliteral}{"Server type to use, defaults to 'tcp'"}, types\_strs
      ),
    \mbox{\hyperlink{group__Ecore__Getopt__Group_gad2ae11581fad6e818ed8bfe1a31d5635}{ECORE\_GETOPT\_STORE\_TRUE}}(\textcolor{charliteral}{'P'}, \textcolor{stringliteral}{"no-proxy"}, \textcolor{stringliteral}{"Do not use SOCKS proxy for remote
       connections."}),

    \mbox{\hyperlink{group__Ecore__Getopt__Group_gad2ae11581fad6e818ed8bfe1a31d5635}{ECORE\_GETOPT\_STORE\_TRUE}}(\textcolor{charliteral}{'f'}, \textcolor{stringliteral}{"flush"}, \textcolor{stringliteral}{"Force a flush after every send call."}),
    \mbox{\hyperlink{group__Ecore__Getopt__Group_gad2ae11581fad6e818ed8bfe1a31d5635}{ECORE\_GETOPT\_STORE\_TRUE}}(\textcolor{charliteral}{'m'}, \textcolor{stringliteral}{"single-message"}, \textcolor{stringliteral}{"Send a single message and delete
       the server."}),

    \mbox{\hyperlink{group__Ecore__Getopt__Group_gae6b958516c8e20f7488bac102c4309a9}{ECORE\_GETOPT\_STORE\_STR}}(\textcolor{charliteral}{'c'}, \textcolor{stringliteral}{"starttls-local-command"}, \textcolor{stringliteral}{"The string to use as a
       local command (it's NOT sent to remote peer) to upgrade connections when -t/--type=tcp+ssl. Defaults to
       STARTTLS, however if you need to send that to the server, change the string with this option."}),

    \mbox{\hyperlink{group__Ecore__Getopt__Group_gae0b598e4c27f72b665af7be086e2d4e6}{ECORE\_GETOPT\_STORE\_FALSE}}(0, \textcolor{stringliteral}{"no-verify"}, \textcolor{stringliteral}{"Do not verify server's certificate"}),
    \mbox{\hyperlink{group__Ecore__Getopt__Group_gae0b598e4c27f72b665af7be086e2d4e6}{ECORE\_GETOPT\_STORE\_FALSE}}(0, \textcolor{stringliteral}{"no-hostname-verify"}, \textcolor{stringliteral}{"Do not Verify server's
       hostname based on its certificate."}),

    \mbox{\hyperlink{group__Ecore__Getopt__Group_ga87a9d063b60f7c0bd79ab3fa16bb6313}{ECORE\_GETOPT\_VERSION}}(\textcolor{charliteral}{'V'}, \textcolor{stringliteral}{"version"}),
    \mbox{\hyperlink{group__Ecore__Getopt__Group_gac2fdfddf0778a319aafb547b04bc93b6}{ECORE\_GETOPT\_COPYRIGHT}}(\textcolor{charliteral}{'C'}, \textcolor{stringliteral}{"copyright"}),
    \mbox{\hyperlink{group__Ecore__Getopt__Group_ga5a0382c58582308ff65d51c14dc1b36f}{ECORE\_GETOPT\_LICENSE}}(\textcolor{charliteral}{'L'}, \textcolor{stringliteral}{"license"}),
    \mbox{\hyperlink{group__Ecore__Getopt__Group_gad7e09a56d2881f22d69dff005e38b67d}{ECORE\_GETOPT\_HELP}}(\textcolor{charliteral}{'h'}, \textcolor{stringliteral}{"help"}),

    \mbox{\hyperlink{group__Ecore__Getopt__Group_ga4950beb14005c6d864915646dfe28fe2}{ECORE\_GETOPT\_STORE\_METAVAR\_STR}}(0, NULL, \textcolor{stringliteral}{"The server name."}, \textcolor{stringliteral}{"name"}),
    \mbox{\hyperlink{group__Ecore__Getopt__Group_ga3dcc251323cdd0155b24341bf7bf1347}{ECORE\_GETOPT\_STORE\_METAVAR\_INT}}(0, NULL, \textcolor{stringliteral}{"The server port."}, \textcolor{stringliteral}{"port"}),

    \mbox{\hyperlink{group__Ecore__Getopt__Group_gaf652ac6007cd9674df603fa3dacc59e0}{ECORE\_GETOPT\_SENTINEL}}
  \}
\};

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} *argv[])
\{
   \textcolor{keywordtype}{char} *name = NULL;
   \textcolor{keywordtype}{char} *type\_choice = NULL;
   Ecore\_Con\_Type type;
   \textcolor{keywordtype}{int} port = -1;
   \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} no\_proxy = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};
   \mbox{\hyperlink{group__Eina__Types__Group_ga3fe0caf72e93b1bab1ca8ee3ccf3f226}{Eina\_Bool}} quit\_option = \mbox{\hyperlink{group__Eina__Types__Group_ga1feb115f8e9913e806e090d9bd5a7301}{EINA\_FALSE}};
   \mbox{\hyperlink{union__Ecore__Getopt__Value}{Ecore\_Getopt\_Value}} values[] = \{
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga123b1c8494301b8f76554675e8606d94}{ECORE\_GETOPT\_VALUE\_STR}}(type\_choice),
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(no\_proxy),

     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(do\_flush),
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(single\_message),

     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga123b1c8494301b8f76554675e8606d94}{ECORE\_GETOPT\_VALUE\_STR}}(starttls\_local\_command),

     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(verify),
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(hostname\_verify),

     \textcolor{comment}{/* standard block to provide version, copyright, license and help */}
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(quit\_option), \textcolor{comment}{/* -V/--version quits */}
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(quit\_option), \textcolor{comment}{/* -C/--copyright quits */}
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(quit\_option), \textcolor{comment}{/* -L/--license quits */}
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga832f91eecd39de313b8351305cba80d3}{ECORE\_GETOPT\_VALUE\_BOOL}}(quit\_option), \textcolor{comment}{/* -h/--help quits */}

     \textcolor{comment}{/* positional argument */}
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga123b1c8494301b8f76554675e8606d94}{ECORE\_GETOPT\_VALUE\_STR}}(name),
     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga048498f4546a0dd78c541168db62494e}{ECORE\_GETOPT\_VALUE\_INT}}(port),

     \mbox{\hyperlink{group__Ecore__Getopt__Group_ga0440d57be0af2a77dc5de02be19aeae2}{ECORE\_GETOPT\_VALUE\_NONE}} \textcolor{comment}{/* sentinel */}
   \};
   \textcolor{keywordtype}{int} args;

   \mbox{\hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}}();
   \mbox{\hyperlink{group__Ecore__Init__Group_ga77757609684a2c922dc5ec398274751b}{ecore\_init}}();
   \mbox{\hyperlink{group__Ecore__Con__Lib__Group_gacf5ecf42c516bb9c8b6759721e9559bd}{ecore\_con\_init}}();

   args = \mbox{\hyperlink{group__Ecore__Getopt__Group_gab9fb5bf2f2edd9bd3a3519faa8e3ebfa}{ecore\_getopt\_parse}}(&options, values, argc, argv);
   \textcolor{keywordflow}{if} (args < 0)
     \{
        fputs(\textcolor{stringliteral}{"ERROR: Could not parse command line options.\(\backslash\)n"}, stderr);
        retval = EXIT\_FAILURE;
        \textcolor{keywordflow}{goto} end;
     \}

   \textcolor{keywordflow}{if} (quit\_option) \textcolor{keywordflow}{goto} end;

   args = \mbox{\hyperlink{group__Ecore__Getopt__Group_ga9870510212af9a71d94fc0f8461cff79}{ecore\_getopt\_parse\_positional}}(&options, values, argc, argv, args);
   \textcolor{keywordflow}{if} (args < 0)
     \{
        fputs(\textcolor{stringliteral}{"ERROR: Could not parse positional arguments.\(\backslash\)n"}, stderr);
        retval = EXIT\_FAILURE;
        \textcolor{keywordflow}{goto} end;
     \}

   \textcolor{keywordflow}{if} (!type\_choice) type\_choice = \textcolor{stringliteral}{"tcp"};

   \textcolor{keywordflow}{if} (strcmp(type\_choice, \textcolor{stringliteral}{"tcp"}) == 0)
     type = ECORE\_CON\_REMOTE\_TCP;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (strcmp(type\_choice, \textcolor{stringliteral}{"udp"}) == 0)
     type = ECORE\_CON\_REMOTE\_UDP;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (strcmp(type\_choice, \textcolor{stringliteral}{"ssl"}) == 0)
     type = ECORE\_CON\_REMOTE\_TCP | ECORE\_CON\_USE\_MIXED | ECORE\_CON\_LOAD\_CERT;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (strcmp(type\_choice, \textcolor{stringliteral}{"tcp+ssl"}) == 0)
     \{
        type = ECORE\_CON\_REMOTE\_TCP;
        do\_ssl\_upgrade = \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}};
     \}
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (strcmp(type\_choice, \textcolor{stringliteral}{"local-user"}) == 0)
     type = ECORE\_CON\_LOCAL\_USER;
   \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (strcmp(type\_choice, \textcolor{stringliteral}{"local-system"}) == 0)
     type = ECORE\_CON\_LOCAL\_SYSTEM;
   \textcolor{keywordflow}{else}
     \{
        fprintf(stderr, \textcolor{stringliteral}{"ERROR: unsupported --type/-t '%s'\(\backslash\)n"}, type\_choice);
        retval = EXIT\_FAILURE;
        \textcolor{keywordflow}{goto} end;
     \}

   \textcolor{keywordflow}{if} ((!starttls\_local\_command) || (starttls\_local\_command[0] == \textcolor{charliteral}{'\(\backslash\)0'}))
     starttls\_local\_command = \textcolor{stringliteral}{"STARTTLS"};

   \textcolor{keywordflow}{if} (no\_proxy) type |= ECORE\_CON\_NO\_PROXY;

   svr = \mbox{\hyperlink{group__Ecore__Con__Server__Group_gae3d7391f7da5e0f748d7b6804d010b2f}{ecore\_con\_server\_connect}}(type, name, port, NULL);
   \textcolor{keywordflow}{if} (!svr) \textcolor{keywordflow}{goto} end;

   \textcolor{keywordflow}{if} (strcmp(type\_choice, \textcolor{stringliteral}{"ssl"}) == 0)
     \{
        \textcolor{keywordflow}{if} (!\_setup\_ssl())
          \textcolor{keywordflow}{goto} no\_mainloop;
     \}

\textcolor{comment}{/* set event handler for server connect */}
   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga4eed60012259c24f9ac75852c5ec1950}{ECORE\_CON\_EVENT\_SERVER\_ADD}}, (
      \mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_add, NULL);
\textcolor{comment}{/* set event handler for server disconnect */}
   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_gabf1abac1d209506c2813837e36dfe37b}{ECORE\_CON\_EVENT\_SERVER\_DEL}}, (
      \mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_del, NULL);
\textcolor{comment}{/* set event handler for receiving server data */}
   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga4bd54e9f3c04f7d601bd15b2e109f050}{ECORE\_CON\_EVENT\_SERVER\_DATA}}, (
      \mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_data, NULL);
\textcolor{comment}{/* set event handler that notifies of sent data */}
   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_gaf2c11acc6236e8c96592c283b8bf9bba}{ECORE\_CON\_EVENT\_SERVER\_WRITE}},
       (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_write\_, NULL);
\textcolor{comment}{/* set event handler that notifies of errors */}
   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga66525bf4b03416a77d5c25407b9f2e15}{ECORE\_CON\_EVENT\_SERVER\_ERROR}},
       (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_error, NULL);
\textcolor{comment}{/* set event handler that notifies of upgrades */}
   \mbox{\hyperlink{group__Ecore__Event__Group_gae75b0b1b2c50e73b8e42afc628b00a62}{ecore\_event\_handler\_add}}(\mbox{\hyperlink{group__Ecore__Con__Events__Group_ga3dd70cd0b388ac0df8f8bff5057c4f52}{ECORE\_CON\_EVENT\_SERVER\_UPGRADE}}
      , (\mbox{\hyperlink{group__Ecore__Event__Group_ga64b4df04cbafda481593d0bc29617c6d}{Ecore\_Event\_Handler\_Cb}})\_upgrade, NULL);

   \mbox{\hyperlink{group__Ecore__FD__Handler__Group_ga832e68eb7f15912abeadef816bb5d2f5}{ecore\_main\_fd\_handler\_add}}(STDIN\_FILENO, 
      \mbox{\hyperlink{group__Ecore__FD__Handler__Group_ggab5644f471dfa3bd182619601d9b60608a1699f804eccf88e7e169a4a20f1d44e7}{ECORE\_FD\_READ}}, \_on\_stdin, NULL, NULL, NULL);

\textcolor{comment}{/* start client */}
   \mbox{\hyperlink{group__Ecore__Main__Loop__Group_gaf103b9f668bb3e4fed12e52c6180132d}{ecore\_main\_loop\_begin}}();

 no\_mainloop:
   \textcolor{keywordflow}{if} (svr)
     \{
        \mbox{\hyperlink{group__Ecore__Con__Server__Group_ga79c76b9f725ceda216e9c7e5caf6cbd9}{ecore\_con\_server\_del}}(svr);
        svr = NULL;
     \}

end:
   \mbox{\hyperlink{group__Ecore__Con__Lib__Group_gaccfd8dd2a1187b71339b5cc39dc83938}{ecore\_con\_shutdown}}();
   \mbox{\hyperlink{group__Ecore__Init__Group_ga768298b932f18d7e7593a447493e5cde}{ecore\_shutdown}}();
   \mbox{\hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}}();

   \textcolor{keywordflow}{return} retval;
\}
\end{DoxyCodeInclude}
 