END_TEST

START_TEST(binbuf_manage_simple)
{
   Eina_Binbuf *buf;
   const char *_cbuf = "12\0 456 78\0 abcthis is some more random junk here!";
   const unsigned char *cbuf = (const unsigned char *) _cbuf;
   size_t size = sizeof(cbuf) - 1; /* We don't care about the real NULL */
   unsigned char *alloc_buf = malloc(size);
   memcpy(alloc_buf, cbuf, size);

   eina_init();

   buf = eina_binbuf_manage_new_length(alloc_buf, size);
   fail_if(!buf);

   fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
   fail_if(size != eina_binbuf_length_get(buf));
   eina_binbuf_append_length(buf, cbuf, size);
   fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
   fail_if(memcmp(eina_binbuf_string_get(buf) + size, cbuf, size));
   fail_if(2 * size != eina_binbuf_length_get(buf));

   eina_binbuf_free(buf);

   eina_shutdown();
}
Esempio n. 2
0
END_TEST

/* eina_binbuf_manage_new_length and eina_binbuf_manage_read_only_new_length
 * are deprecated */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
START_TEST(binbuf_manage_simple)
{
   Eina_Binbuf *buf;
   const char *_cbuf = "12\0 456 78\0 abcthis is some more random junk here!";
   const unsigned char *cbuf = (const unsigned char *) _cbuf;
   size_t size = sizeof(cbuf) - 1; /* We don't care about the real NULL */
   unsigned char *alloc_buf = malloc(size);
   memcpy(alloc_buf, cbuf, size);

   eina_init();

   buf = eina_binbuf_manage_new_length(alloc_buf, size);
   fail_if(!buf);

   fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
   fail_if(size != eina_binbuf_length_get(buf));
   eina_binbuf_append_length(buf, cbuf, size);
   fail_if(memcmp(eina_binbuf_string_get(buf), cbuf, size));
   fail_if(memcmp(eina_binbuf_string_get(buf) + size, cbuf, size));
   fail_if(2 * size != eina_binbuf_length_get(buf));

   eina_binbuf_free(buf);

   eina_shutdown();
}
Esempio n. 3
0
static Eina_Bool
_ecore_con_socks_svr_init_v4(Ecore_Con_Server *svr, Ecore_Con_Socks_v4 *v4)
{
   size_t addrlen, buflen, ulen = 1;
   unsigned char *sbuf;

   addrlen = v4->lookup ? strlen(svr->name) + 1 : 0;
   if (v4->username) ulen += v4->ulen;
   buflen = sizeof(char) * (8  + ulen + addrlen);
   sbuf = malloc(buflen);
   if (!sbuf)
     {
        ecore_con_event_server_error(svr, "Memory allocation failure!");
        _ecore_con_server_kill(svr);
        return EINA_FALSE;
     }
   /* http://en.wikipedia.org/wiki/SOCKS */
   sbuf[0] = 4;
   sbuf[1] = v4->bind ? 2 : 1;
   sbuf[2] = svr->port >> 8;
   sbuf[3] = svr->port & 0xff;
   if (addrlen)
     {
        sbuf[4] = sbuf[5] = sbuf[6] = 0;
        sbuf[7] = 1;
     }
   else
     /* SOCKSv4 only handles IPV4, so addrlen is always 4 */
     memcpy(sbuf + 4, svr->ecs_addr, 4);
   if (v4->username)
     memcpy(sbuf + 8, v4->username, ulen);
   else
     sbuf[8] = 0;
   if (addrlen) memcpy(sbuf + 8 + ulen, svr->name, addrlen);

   svr->ecs_buf = eina_binbuf_manage_new_length(sbuf, buflen);
   return EINA_TRUE;
}
Esempio n. 4
0
static Eina_Bool
_ecore_con_socks_svr_init_v5(Ecore_Con_Server *svr, Ecore_Con_Socks_v5 *v5)
{
   size_t buflen;
   unsigned int x;
   unsigned char *sbuf;

   if (v5->username)
     buflen = sizeof(char) * (2  + ECORE_CON_SOCKS_V5_TOTAL_METHODS);
   else
     buflen = 3;
   sbuf = malloc(buflen);
   if (!sbuf)
     {
        ecore_con_event_server_error(svr, "Memory allocation failure!");
        _ecore_con_server_kill(svr);
        return EINA_FALSE;
     }
   /* http://en.wikipedia.org/wiki/SOCKS
    * http://tools.ietf.org/html/rfc1928
    */
   sbuf[0] = 5;
   if (v5->username)
     {
       sbuf[1] = ECORE_CON_SOCKS_V5_TOTAL_METHODS;
       for (x = 2; x < 2 + ECORE_CON_SOCKS_V5_TOTAL_METHODS; x++)
         sbuf[x] = ECORE_CON_SOCKS_V5_METHODS[x - 2];
     }
   else
     {
        sbuf[1] = 1;
        sbuf[2] = ECORE_CON_SOCKS_V5_METHOD_NONE;
     }

   svr->ecs_buf = eina_binbuf_manage_new_length(sbuf, buflen);
   return EINA_TRUE;
}