Ejemplo n.º 1
0
/**
 * @brief Send arbitrary data to a connected server
 *
 * This function is used to send arbitrary data to a connected server using @p client through HTTP PUT.
 * It relies on the user to set required headers by operating on the client's #Azy_Net object.
 * @param client The client (NOT NULL)
 * @param send_data The data+length to send (NOT NULL)
 * @param data Optional data to pass to associated callbacks
 * @return The #Azy_Client_Call_Id of the transmission, to be used with azy_client_callback_set,
 * or 0 on failure
 * @see azy_net_header_set
 */
Azy_Client_Call_Id
azy_client_put(Azy_Client         *client,
               const Azy_Net_Data *send_data,
               void               *data)
{
   Eina_Strbuf *msg;
   Azy_Client_Handler_Data *hd;

   if (!AZY_MAGIC_CHECK(client, AZY_MAGIC_CLIENT))
     {
        AZY_MAGIC_FAIL(client, AZY_MAGIC_CLIENT);
        return 0;
     }
   EINA_SAFETY_ON_NULL_RETURN_VAL(send_data, 0);
   EINA_SAFETY_ON_NULL_RETURN_VAL(send_data->data, 0);

   azy_net_message_length_set(client->net, send_data->size);
   azy_net_type_set(client->net, AZY_NET_TYPE_PUT);
   msg = azy_net_header_create(client->net);
   EINA_SAFETY_ON_NULL_GOTO(msg, error);
#ifdef ISCOMFITOR
   DBG("\nSENDING >>>>>>>>>>>>>>>>>>>>>>>>\n%.*s%.*s\n>>>>>>>>>>>>>>>>>>>>>>>>",
       eina_strbuf_length_get(msg), eina_strbuf_string_get(msg), (int)send_data->size, send_data->data);
#endif
   EINA_SAFETY_ON_TRUE_GOTO(!ecore_con_server_send(client->net->conn, eina_strbuf_string_get(msg), eina_strbuf_length_get(msg)), error);
   INFO("Send [1/2] complete! %zi bytes queued for sending.", eina_strbuf_length_get(msg));
   eina_strbuf_free(msg);
   msg = NULL;

   EINA_SAFETY_ON_TRUE_GOTO(!ecore_con_server_send(client->net->conn, send_data->data, send_data->size), error);
   INFO("Send [2/2] complete! %" PRIi64 " bytes queued for sending.", send_data->size);
   ecore_con_server_flush(client->net->conn);

   EINA_SAFETY_ON_TRUE_RETURN_VAL(!(hd = calloc(1, sizeof(Azy_Client_Handler_Data))), 0);

   if (!client->conns)
     {
        client->recv = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
                                               (Ecore_Event_Handler_Cb)_azy_client_handler_data, hd);
        ecore_con_server_data_set(client->net->conn, client);
     }

   hd->client = client;
   hd->content_data = data;
   hd->type = AZY_NET_TYPE_PUT;
   AZY_MAGIC_SET(hd, AZY_MAGIC_CLIENT_DATA_HANDLER);

   while (++azy_client_send_id__ < 1) ;

   hd->id = azy_client_send_id__;
   client->conns = eina_list_append(client->conns, hd);

   return azy_client_send_id__;

error:
   if (msg)
     eina_strbuf_free(msg);
   return 0;
}
Ejemplo n.º 2
0
static char *
_get_abbreviated_name(const char *prefix, const char *fname)
{
   Eina_Strbuf *buf = eina_strbuf_new();

   const char *last_p = strrchr(prefix, '_');
   last_p = (last_p) ? (last_p + 1) : prefix;

   const char *tmp = strstr(fname, last_p);
   int len = strlen(last_p);

   if ((tmp) &&
       ((tmp == fname) || (*(tmp - 1) == '_')) &&
       ((*(tmp + len) == '\0') || (*(tmp + len) == '_')))
     {
        int plen = strlen(prefix);
        len += (tmp - fname);

        if ((plen >= len) && !strncmp(prefix + plen - len, fname, len))
          {
             eina_strbuf_append_n(buf, prefix, plen - len);
          }
     }

   if (eina_strbuf_length_get(buf) == 0)
     eina_strbuf_append_printf(buf, "%s_", prefix);
   eina_strbuf_append(buf, fname);

   char *ret = eina_strbuf_string_steal(buf);
   eina_strbuf_free(buf);
   return ret;
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
    Eina_Strbuf *buf;

    eina_init();

    buf = eina_strbuf_new();

    eina_strbuf_append_length(buf, "buffe", 5);
    eina_strbuf_append_char(buf, 'r');
    printf("%s\n", eina_strbuf_string_get(buf));

    eina_strbuf_insert_escaped(buf, "my ", 0);
    printf("%s\n", eina_strbuf_string_get(buf));
    eina_strbuf_reset(buf);

    eina_strbuf_append_escaped(buf, "my buffer");
    printf("%s\n", eina_strbuf_string_get(buf));
    eina_strbuf_reset(buf);

    eina_strbuf_append_printf(buf, "%s%c", "buffe", 'r');
    eina_strbuf_insert_printf(buf, " %s: %d", 6, "length", eina_strbuf_length_get(buf));
    printf("%s\n", eina_strbuf_string_get(buf));

    eina_strbuf_remove(buf, 0, 7);
    printf("%s\n", eina_strbuf_string_get(buf));

    eina_strbuf_replace_all(buf, "length", "size");
    printf("%s\n", eina_strbuf_string_get(buf));

    eina_strbuf_free(buf);
    eina_shutdown();

    return 0;
}
Ejemplo n.º 4
0
static void
_match_append(Eina_Strbuf *match, const char *key, const char *value)
{
   if (!value) return;

   if ((eina_strbuf_length_get(match) + strlen(",=''") + strlen(key) + strlen(value))
       >= DBUS_MAXIMUM_MATCH_RULE_LENGTH)
     {
        ERR("cannot add match %s='%s' to %s: too long!", key, value,
            eina_strbuf_string_get(match));
        return;
     }

   eina_strbuf_append_printf(match, ",%s='%s'", key, value);
}
Ejemplo n.º 5
0
Eina_Bool
send_smtp(Email *e)
{
   char *buf;
   size_t size;
   Email_Message *msg;
   Email_Contact *ec;
   Eina_Strbuf *bbuf;

   e->current = EMAIL_OP_SEND;
   msg = e->op_ids->data;
   switch (e->smtp_state)
     {
      case 0:
        e->smtp_state++;
      case EMAIL_SMTP_STATE_FROM:
        if ((!msg->from) && (!msg->sender))
          {
             char buf[1024];
             snprintf(buf, sizeof(buf), "%s@%s", e->username, e->features.smtp_features.domain);
             msg->sender = email_contact_new(buf);
          }
        ec = msg->sender;
        size = sizeof(char) * (sizeof(EMAIL_SMTP_FROM) + strlen(ec->address)) - 2;
        buf = alloca(size);
        snprintf(buf, size, EMAIL_SMTP_FROM, ec->address);
        email_write(e, buf, size - 1);
        e->smtp_state++;
        e->internal_state = 0;
        break;
      case EMAIL_SMTP_STATE_TO:
        ec = eina_list_nth(msg->recipients, e->internal_state++);
        if (!ec)
          {
             e->smtp_state++;
             e->internal_state = 0;
             return send_smtp(e);
          }
        size = sizeof(char) * (sizeof(EMAIL_SMTP_TO) + strlen(ec->address)) - 2;
        buf = alloca(size);
        snprintf(buf, size, EMAIL_SMTP_TO, ec->address);
        email_write(e, buf, size - 1);
        break;
      case EMAIL_SMTP_STATE_DATA:
        email_write(e, EMAIL_SMTP_DATA, sizeof(EMAIL_SMTP_DATA) - 1);
        e->smtp_state++;
        e->internal_state = 0;
        break;
      default:
        bbuf = email_message_serialize(msg);
        e->smtp_state++;
        if (bbuf)
          {
             email_write(e, eina_strbuf_string_get(bbuf), eina_strbuf_length_get(bbuf));
             eina_strbuf_free(bbuf);
          }
        else
          return EINA_FALSE;
     }
   return EINA_TRUE;
}
Ejemplo n.º 6
0
/**
 * @brief Make an HTTP GET or POST request using a connected client with no HTTP BODY
 *
 * This function is used to make a GET or POST request using @p client to the uri of the client's
 * #Azy_Net object (azy_net_get(client)) using HTTP method @p type, content-type
 * defined by @p transport, and the optional deserialization function specified by @p cb.
 * @param client The client (NOT NULL)
 * @param type The HTTP method to use (NOT NULL)
 * @param netdata The HTTP BODY to send with a POST
 * @param cb The deserialization callback to use for the response
 * @param data The user data to be passed to resulting callbacks
 * @return The #Azy_Client_Call_Id of the transmission, to be used with azy_client_callback_set,
 * or 0 on failure
 */
Azy_Client_Call_Id
azy_client_blank(Azy_Client    *client,
                 Azy_Net_Type   type,
                 Azy_Net_Data  *netdata,
                 Azy_Content_Cb cb,
                 void          *data)
{
   Eina_Strbuf *msg;
   Azy_Client_Handler_Data *hd;

   DBG("(client=%p, net=%p)", client, client->net);

   if (!AZY_MAGIC_CHECK(client, AZY_MAGIC_CLIENT))
     {
        AZY_MAGIC_FAIL(client, AZY_MAGIC_CLIENT);
        return 0;
     }
   EINA_SAFETY_ON_NULL_RETURN_VAL(client->net, 0);
   EINA_SAFETY_ON_TRUE_RETURN_VAL((type != AZY_NET_TYPE_GET) && (type != AZY_NET_TYPE_POST), 0);

   while (++azy_client_send_id__ < 1) ;

   client->net->type = type;

   if (!client->net->http.req.http_path)
     {
        WARN("NULL URI passed, defaulting to \"/\"");
        azy_net_uri_set(client->net, "/");
     }
   if (netdata && netdata->size && (type == AZY_NET_TYPE_POST))
     azy_net_message_length_set(client->net, netdata->size);

   msg = azy_net_header_create(client->net);
   EINA_SAFETY_ON_NULL_GOTO(msg, error);

#ifdef ISCOMFITOR
   char buf[64];
   snprintf(buf, sizeof(buf), "\nSENDING >>>>>>>>>>>>>>>>>>>>>>>>\n%%.%zus\n>>>>>>>>>>>>>>>>>>>>>>>>",
            eina_strbuf_length_get(msg));
   DBG(buf, eina_strbuf_string_get(msg));
#endif

   EINA_SAFETY_ON_TRUE_GOTO(!ecore_con_server_send(client->net->conn, eina_strbuf_string_get(msg), eina_strbuf_length_get(msg)), error);
   if (netdata && netdata->size && (type == AZY_NET_TYPE_POST))
     {
        INFO("Send [1/2] complete! %zu bytes queued for sending.", eina_strbuf_length_get(msg));
        EINA_SAFETY_ON_TRUE_GOTO(!ecore_con_server_send(client->net->conn, netdata->data, netdata->size), error);
        INFO("Send [2/2] complete! %" PRIi64 " bytes queued for sending.", netdata->size);
     }
   else
     INFO("Send [1/1] complete! %zu bytes queued for sending.", eina_strbuf_length_get(msg));
   eina_strbuf_free(msg);
   msg = NULL;

   ecore_con_server_flush(client->net->conn);

   hd = calloc(1, sizeof(Azy_Client_Handler_Data));
   EINA_SAFETY_ON_NULL_RETURN_VAL(hd, 0);
   hd->client = client;
   hd->callback = cb;
   hd->type = type;
   hd->content_data = data;
   if (netdata && netdata->size && (type == AZY_NET_TYPE_POST))
     {
        hd->send = eina_strbuf_new();
        eina_strbuf_append_length(hd->send, (char *)netdata->data, netdata->size);
     }

   hd->id = azy_client_send_id__;
   AZY_MAGIC_SET(hd, AZY_MAGIC_CLIENT_DATA_HANDLER);
   if (!client->conns)
     {
        client->recv = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
                                               (Ecore_Event_Handler_Cb)_azy_client_handler_data, hd);
        ecore_con_server_data_set(client->net->conn, client);
     }

   client->conns = eina_list_append(client->conns, hd);

   DBG("(client=%p, net=%p, hd=%p)", client, client->net, hd);
   return azy_client_send_id__;
error:
   if (msg) eina_strbuf_free(msg);
   return 0;
}
Ejemplo n.º 7
0
/**
 * @brief Make a method call using a connected client
 *
 * This function is used to make a method call on @p client as defined in
 * @p content, using content-type defined by @p transport and the deserialization
 * function specified by @p cb.  This should generally not be used by users, as azy_parser
 * will automatically generate the correct calls from a .azy file.
 * @param client The client (NOT NULL)
 * @param content The content containing the method name and parameters (NOT NULL)
 * @param transport The content-type (xml/json/etc) to use
 * @param cb The deserialization callback to use for the response
 * @return The #Azy_Client_Call_Id of the transmission, to be used with azy_client_callback_set,
 * or 0 on failure
 */
Azy_Client_Call_Id
azy_client_call(Azy_Client       *client,
                Azy_Content      *content,
                Azy_Net_Transport transport,
                Azy_Content_Cb    cb)
{
   Eina_Strbuf *msg;
   Azy_Client_Handler_Data *hd;

   DBG("(client=%p, net=%p, content=%p)", client, client->net, content);

   if (!AZY_MAGIC_CHECK(client, AZY_MAGIC_CLIENT))
     {
        AZY_MAGIC_FAIL(client, AZY_MAGIC_CLIENT);
        return 0;
     }
   EINA_SAFETY_ON_NULL_RETURN_VAL(client->net, 0);
   EINA_SAFETY_ON_NULL_RETURN_VAL(content, 0);
   EINA_SAFETY_ON_NULL_RETURN_VAL(content->method, 0);

   INFO("New method call: '%s'", content->method);

   while (++azy_client_send_id__ < 1) ;

   content->id = azy_client_send_id__;

   azy_net_transport_set(client->net, transport);
   if (!azy_content_serialize_request(content, transport))
     return 0;
   azy_net_type_set(client->net, AZY_NET_TYPE_POST);
   if (!client->net->http.req.http_path)
     {
        WARN("URI currently set to NULL, defaulting to \"/\"");
        azy_net_uri_set(client->net, "/");
     }

   azy_net_message_length_set(client->net, content->length);
   msg = azy_net_header_create(client->net);
   EINA_SAFETY_ON_NULL_GOTO(msg, error);

   if (azy_rpc_log_dom >= 0)
     {
        char buf[64];
        snprintf(buf, sizeof(buf), "\nSENDING >>>>>>>>>>>>>>>>>>>>>>>>\n%%.%is%%.%llis\n>>>>>>>>>>>>>>>>>>>>>>>>",
            eina_strbuf_length_get(msg), content->length);
        RPC_DBG(buf, eina_strbuf_string_get(msg), content->buffer);
     }

   EINA_SAFETY_ON_TRUE_GOTO(!ecore_con_server_send(client->net->conn, eina_strbuf_string_get(msg), eina_strbuf_length_get(msg)), error);
   INFO("Send [1/2] complete! %zu bytes queued for sending.", eina_strbuf_length_get(msg));
   eina_strbuf_free(msg);
   msg = NULL;

   EINA_SAFETY_ON_TRUE_GOTO(!ecore_con_server_send(client->net->conn, content->buffer, content->length), error);
   INFO("Send [2/2] complete! %lli bytes queued for sending.", content->length);
   ecore_con_server_flush(client->net->conn);

   hd = calloc(1, sizeof(Azy_Client_Handler_Data));
   EINA_SAFETY_ON_NULL_RETURN_VAL(hd, 0);
   hd->client = client;
   hd->method = eina_stringshare_ref(content->method);
   hd->callback = cb;
   hd->type = AZY_NET_TYPE_POST;
   hd->content_data = content->data;
   hd->send = eina_strbuf_new();
   eina_strbuf_append_length(hd->send, (char *)content->buffer, content->length);

   hd->id = azy_client_send_id__;
   AZY_MAGIC_SET(hd, AZY_MAGIC_CLIENT_DATA_HANDLER);
   if (!client->conns)
     {
        client->recv = ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA,
                                               (Ecore_Event_Handler_Cb)_azy_client_handler_data, hd);
        ecore_con_server_data_set(client->net->conn, client);
     }

   client->conns = eina_list_append(client->conns, hd);

   DBG("(client=%p, net=%p, content=%p, hd=%p)", client, client->net, content, hd);
   return azy_client_send_id__;
error:
   if (msg)
     eina_strbuf_free(msg);
   return 0;
}
Ejemplo n.º 8
0
static void
_gen_func(const Eolian_Unit *src, const Eolian_Class *cl,
          const Eolian_Function *fid, Eolian_Function_Type ftype,
          Eina_Strbuf *buf, const Eolian_Implement *impl, Eina_Strbuf *lbuf)
{
   Eina_Bool is_empty = eolian_implement_is_empty(impl, ftype);
   Eina_Bool is_auto = eolian_implement_is_auto(impl, ftype);

   if ((ftype != EOLIAN_PROP_GET) && (ftype != EOLIAN_PROP_SET))
     ftype = eolian_function_type_get(fid);

   Eina_Bool is_prop = (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET);
   Eina_Bool var_as_ret = EINA_FALSE;

   const Eolian_Expression *def_ret = NULL;
   const Eolian_Type *rtp = eolian_function_return_type_get(fid, ftype);
   if (rtp)
     {
        is_auto = EINA_FALSE; /* can't do auto if func returns */
        def_ret = eolian_function_return_default_value_get(fid, ftype);
     }

   const char *func_suffix = "";
   if (ftype == EOLIAN_PROP_GET)
     {
        func_suffix = "_get";
        if (!rtp)
          {
             void *d1, *d2;
             Eina_Iterator *itr = eolian_property_values_get(fid, ftype);
             if (eina_iterator_next(itr, &d1) && !eina_iterator_next(itr, &d2))
               {
                  Eolian_Function_Parameter *pr = d1;
                  rtp = eolian_parameter_type_get(pr);
                  var_as_ret = EINA_TRUE;
                  def_ret = eolian_parameter_default_value_get(pr);
               }
             eina_iterator_free(itr);
          }
     }
   else if (ftype == EOLIAN_PROP_SET)
     func_suffix = "_set";

   Eina_Strbuf *params = eina_strbuf_new(); /* par1, par2, par3, ... */
   Eina_Strbuf *params_full = eina_strbuf_new(); /* T par1, U par2, ... for decl */
   Eina_Strbuf *params_full_imp = eina_strbuf_new(); /* as above, for impl */
   Eina_Strbuf *params_init = eina_strbuf_new(); /* default value inits */

   Eina_Stringshare *promise_param_name = NULL;
   Eina_Stringshare *promise_param_type = NULL;

   /* property keys */
   {
      Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
      Eolian_Function_Parameter *pr;
      EINA_ITERATOR_FOREACH(itr, pr)
        {
           const char *prn = eolian_parameter_name_get(pr);
           const Eolian_Type *pt = eolian_parameter_type_get(pr);
           Eina_Stringshare *ptn = eolian_type_c_type_get(pt);

           if (eina_strbuf_length_get(params))
             eina_strbuf_append(params, ", ");
           eina_strbuf_append(params, prn);

           eina_strbuf_append_printf(params_full, ", %s", ptn);
           eina_strbuf_append_printf(params_full_imp, ", %s", ptn);
           if (ptn[strlen(ptn) - 1] != '*')
             {
                eina_strbuf_append_char(params_full, ' ');
                eina_strbuf_append_char(params_full_imp, ' ');
             }
           eina_strbuf_append(params_full, prn);
           eina_strbuf_append(params_full_imp, prn);
           if (is_empty || is_auto)
             eina_strbuf_append(params_full_imp, " EINA_UNUSED");

           eina_stringshare_del(ptn);
        }
      eina_iterator_free(itr);
   }

   /* property values or method params if applicable */
   if (!var_as_ret)
     {
        Eina_Iterator *itr;
        if (is_prop)
          itr = eolian_property_values_get(fid, ftype);
        else
          itr = eolian_function_parameters_get(fid);
        Eolian_Function_Parameter *pr;
        EINA_ITERATOR_FOREACH(itr, pr)
          {
             Eolian_Parameter_Dir pd = eolian_parameter_direction_get(pr);
             const Eolian_Expression *dfv = eolian_parameter_default_value_get(pr);
             const char *prn = eolian_parameter_name_get(pr);
             const Eolian_Type *pt = eolian_parameter_type_get(pr);
             Eina_Stringshare *ptn = eolian_type_c_type_get(pt);

             Eina_Bool had_star = ptn[strlen(ptn) - 1] == '*';
             const char *add_star = _get_add_star(ftype, pd);

             if (eina_strbuf_length_get(params))
               eina_strbuf_append(params, ", ");

             eina_strbuf_append(params_full_imp, ", ");
             eina_strbuf_append(params_full_imp, ptn);
             if (!had_star)
               eina_strbuf_append_char(params_full_imp, ' ');
             eina_strbuf_append(params_full_imp, add_star);
             eina_strbuf_append(params_full_imp, prn);
             if (!dfv && is_empty)
               eina_strbuf_append(params_full_imp, " EINA_UNUSED");
             eina_strbuf_append(params, prn);

             eina_strbuf_append(params_full, ", ");
             eina_strbuf_append(params_full, ptn);
             if (!had_star)
               eina_strbuf_append_char(params_full, ' ');
             eina_strbuf_append(params_full, add_star);
             eina_strbuf_append(params_full, prn);

             if (is_auto)
               {
                  if (ftype == EOLIAN_PROP_SET)
                    eina_strbuf_append_printf(params_init, "   %s = pd->%s;\n", prn, prn);
                  else
                    {
                       eina_strbuf_append_printf(params_init, "   if (%s) *%s = pd->%s;\n",
                                                 prn, prn, prn);
                    }
               }
             else if ((ftype != EOLIAN_PROP_SET) && dfv)
               {
                  Eolian_Value val = eolian_expression_eval(src, dfv, EOLIAN_MASK_ALL);
                  if (val.type)
                    {
                       Eina_Stringshare *vals = eolian_expression_value_to_literal(&val);
                       eina_strbuf_append_printf(params_init, "   if (%s) *%s = %s;",
                                                 prn, prn, vals);
                       eina_stringshare_del(vals);
                       if (eolian_expression_type_get(dfv) == EOLIAN_EXPR_NAME)
                         {
                            Eina_Stringshare *vs = eolian_expression_serialize(dfv);
                            eina_strbuf_append_printf(params_init, " /* %s */", vs);
                            eina_stringshare_del(vs);
                         }
                       eina_strbuf_append_char(params_init, '\n');
                    }
               }

             eina_stringshare_del(ptn);
          }
Ejemplo n.º 9
0
Archivo: shotgun.c Proyecto: Limsik/e17
static Eina_Bool
data(Shotgun_Auth *auth, int type __UNUSED__, Ecore_Con_Event_Server_Data *ev)
{
   char *recv, *data, *p;
   size_t size;

   if ((auth != ecore_con_server_data_get(ev->server)) || (!auth))
     return ECORE_CALLBACK_PASS_ON;

   ecore_timer_reset(auth->keepalive);
   if (ev->size == 1)
     {
        DBG("Received carriage return");
        return ECORE_CALLBACK_RENEW;
     }
   else if ((ev->size == 38) &&
            (!memcmp(ev->data, "<?xml version=\"1.0", sizeof("<?xml version=\"1.0") - 1)) &&
            (((unsigned char*)ev->data)[ev->size - 1] == '>'))
     {
        DBG("Received xml version tag");
        return ECORE_CALLBACK_RENEW;
     }
   if (eina_log_domain_level_check(shotgun_log_dom, EINA_LOG_LEVEL_DBG))
     {
        recv = alloca(ev->size + 1);
        memcpy(recv, ev->data, ev->size);
        for (p = recv + ev->size - 1; isspace(*p); p--)
          *p = 0;
        recv[ev->size] = 0;
        DBG("Receiving %i bytes:\n%s", ev->size, recv);
     }

   if (!shotgun_data_detect(auth, ev))
     return ECORE_CALLBACK_RENEW;

   if (auth->state < SHOTGUN_CONNECTION_STATE_CONNECTED)
     {
        shotgun_login(auth, ev);
        return ECORE_CALLBACK_RENEW;
     }

   data = auth->buf ? (char*)eina_strbuf_string_get(auth->buf) : (char*)ev->data;
   size = auth->buf ? eina_strbuf_length_get(auth->buf) : (size_t)ev->size;

   switch (shotgun_data_tokenize(auth, ev))
     {
      case SHOTGUN_DATA_TYPE_MSG:
        shotgun_message_feed(auth, data, size);
        break;
      case SHOTGUN_DATA_TYPE_IQ:
        shotgun_iq_feed(auth, data, size);
        break;
      case SHOTGUN_DATA_TYPE_PRES:
        shotgun_presence_feed(auth, data, size);
        break;
      default:
        ERR("UNPARSABLE TAG %d", shotgun_data_tokenize(auth, ev));
        break;
     }
   if (auth->buf) eina_strbuf_free(auth->buf);
   auth->buf = NULL;

   return ECORE_CALLBACK_RENEW;
}
Ejemplo n.º 10
0
Archivo: shotgun.c Proyecto: Limsik/e17
static Eina_Bool
shotgun_data_detect(Shotgun_Auth *auth, Ecore_Con_Event_Server_Data *ev)
{
   size_t len = ev->size;
   const char *tag, *data = (char*)ev->data;
   char buf[24] = {0};

   if (((char*)ev->data)[ev->size - 1] != '>')
     {
        if (!auth->buf)
          {
             DBG("Creating event buffer");
             auth->buf = eina_strbuf_new();
          }
        if ((len >= 21) &&
                 (!memcmp(data, "<?xml version=", sizeof("<?xml version=") - 1)))
          {
             DBG("Received xml version tag");
             data += 21, len -= 21;
          }
        DBG("Appending %zu to buffer", len);
        //fprintf(stdout, "%*s\n", len, (char*)data);
        eina_strbuf_append_length(auth->buf, data, len);
        return EINA_FALSE;
     }

   if (auth->buf)
     {
        DBG("Appending %i to buffer", ev->size);
        //fprintf(stdout, "%*s\n", ev->size, (char*)ev->data);
        eina_strbuf_append_length(auth->buf, ev->data, ev->size);
     }


   data = auth->buf ? (char*)eina_strbuf_string_get(auth->buf) : (char*)ev->data;
   len = auth->buf ? eina_strbuf_length_get(auth->buf) : (size_t)ev->size;

   if ((len >= 21) &&
            (!memcmp(data, "<?xml version=", sizeof("<?xml version=") - 1)))
     {
        DBG("Received xml version tag");
        data += 21, len -= 21;
     }

   tag = data + 1, len--;;
   while ((tag[0] != '>') && (tag[0] != ' '))
     {
        //DBG("\ndata: '%s'\ntag: '%s'", data, tag);
        tag++, len--;
     }

   if (!memcmp(data, "<stream:stream", sizeof("<stream:stream") - 1)) return EINA_TRUE;
   if ((tag[len - 2] == '/') && (len >= 7) && memcmp(data, "<stream", 7)) return EINA_TRUE;
   //fprintf(stderr, "tag: %*s || end: %*s\n", tag - data - 1, data + 1, tag - data - 1, tag + len - (tag - data));
   if ((data != tag + len - (tag - data) - 1) && (!memcmp(data + 1, tag + len - (tag - data), tag - data - 1)))
     {
        if (eina_log_domain_level_check(shotgun_log_dom, EINA_LOG_LEVEL_DBG))
          {
             memcpy(buf, data + 1, sizeof(buf) - 1);
             DBG("'%s' and '%s' match!", buf, tag + len - (tag - data));
             DBG("Releasing buffered event!");
          }
        return EINA_TRUE;
     }

   memcpy(buf, data + 1, sizeof(buf) - 1);
   DBG("'%s' and '%s' do not match!", buf, tag + len - (tag - data));
   if (!auth->buf)
     {
        DBG("Creating event buffer");
        auth->buf = eina_strbuf_new();
        DBG("Appending %i to buffer", ev->size);
        eina_strbuf_append_length(auth->buf, ev->data, ev->size);
     }
   return EINA_FALSE;
}
Ejemplo n.º 11
0
static int
_append_section(const char *desc, int ind, int curl, Eina_Strbuf *buf,
                Eina_Strbuf *wbuf, Eina_Bool use_legacy)
{
   while (*desc)
     {
        eina_strbuf_reset(wbuf);
        while (*desc && isspace(*desc) && (*desc != '\n'))
          eina_strbuf_append_char(wbuf, *desc++);
        if (*desc == '\\')
          {
             desc++;
             if ((*desc != '@') && (*desc != '$'))
               eina_strbuf_append_char(wbuf, '\\');
             eina_strbuf_append_char(wbuf, *desc++);
          }
        else if (*desc == '@')
          {
             const char *ref = ++desc;
             if (isalpha(*desc) || (*desc == '_'))
               {
                  eina_strbuf_append(wbuf, "@ref ");
                  while (isalnum(*desc) || (*desc == '.') || (*desc == '_'))
                    ++desc;
                  if (*(desc - 1) == '.') --desc;
                  Eina_Stringshare *refn = eina_stringshare_add_length(ref, desc - ref);
                  _generate_ref(refn, wbuf, use_legacy);
                  eina_stringshare_del(refn);
               }
             else
               eina_strbuf_append_char(wbuf, '@');
          }
        else if (*desc == '$')
          {
             desc++;
             if (isalpha(*desc))
               eina_strbuf_append(wbuf, "@c ");
             else
               eina_strbuf_append_char(wbuf, '$');
          }
        while (*desc && !isspace(*desc))
          eina_strbuf_append_char(wbuf, *desc++);
        int limit = DOC_LIMIT(ind);
        int wlen = eina_strbuf_length_get(wbuf);
        if ((int)(curl + wlen) > limit)
          {
             curl = 3;
             eina_strbuf_append_char(buf, '\n');
             curl += _indent_line(buf, ind);
             eina_strbuf_append(buf, " * ");
             if (*eina_strbuf_string_get(wbuf) == ' ')
               eina_strbuf_remove(wbuf, 0, 1);
          }
        curl += eina_strbuf_length_get(wbuf);
        eina_strbuf_append(buf, eina_strbuf_string_get(wbuf));
        if (*desc == '\n')
          {
             desc++;
             eina_strbuf_append_char(buf, '\n');
             while (*desc == '\n')
               {
                  _indent_line(buf, ind);
                  eina_strbuf_append(buf, " *\n");
                  desc++;
               }
             curl = _indent_line(buf, ind) + 3;
             eina_strbuf_append(buf, " * ");
          }
     }
   return curl;
}
Ejemplo n.º 12
0
/**
 * @brief Send data to a client
 *
 * This function is used to queue arbitrary data to send to a client through its module.  It will automatically
 * generate all http header strings from @p net (if provided) including the content-length (based on @p data).
 * @param module The client's #Azy_Server_Module object (NOT NULL)
 * @param net An #Azy_Net object containing http information to use
 * @param data The data to send
 * @return EINA_TRUE on success, else EINA_FALSE
 */
Eina_Bool
azy_server_module_send(Azy_Server_Module *module,
                       Azy_Net *net,
                       const Azy_Net_Data *data)
{
   Eina_Strbuf *header;
   char chunk_size[20];
   Eina_Binbuf *chunk_data;
   Eina_Bool nullify = EINA_FALSE;

   if (!AZY_MAGIC_CHECK(module, AZY_MAGIC_SERVER_MODULE))
     {
        AZY_MAGIC_FAIL(module, AZY_MAGIC_SERVER_MODULE);
        return EINA_FALSE;
     }

   if (net)
     {
        if (!module->client->current)
          {
             module->client->current = net;
             nullify = EINA_TRUE;
          }

        if (net->headers_sent)
          goto post_header;

        Eina_Bool s;
        if ((data) && (net->http.transfer_encoding != AZY_NET_TRANSFER_ENCODING_CHUNKED))
          azy_net_content_length_set(net, data->size);
        if (!net->http.res.http_code)
          azy_net_code_set(net, 200);  /* OK */
        azy_net_type_set(net, AZY_NET_TYPE_RESPONSE);
        EINA_SAFETY_ON_TRUE_RETURN_VAL(!(header = azy_net_header_create(net)), EINA_FALSE);
        EINA_SAFETY_ON_NULL_RETURN_VAL(module->client->current->conn, EINA_FALSE);
        s = !!ecore_con_client_send(module->client->current->conn, eina_strbuf_string_get(header), eina_strbuf_length_get(header));
        eina_strbuf_free(header);
        if (!s)
          {
             ERR("Could not queue header for sending!");
             return EINA_FALSE;
          }
        net->headers_sent = EINA_TRUE;
     }

post_header:

   if ((!net) || (net->http.transfer_encoding != AZY_NET_TRANSFER_ENCODING_CHUNKED))
     {
        if (!data || !data->data) return EINA_TRUE;

        EINA_SAFETY_ON_NULL_RETURN_VAL(module->client->current->conn, EINA_FALSE);
        EINA_SAFETY_ON_TRUE_RETURN_VAL(!ecore_con_client_send(module->client->current->conn, data->data, data->size), EINA_FALSE);
        goto post_send;
     }

   if (!data || !data->data)
     {
        EINA_SAFETY_ON_NULL_RETURN_VAL(module->client->current->conn, EINA_FALSE);
        EINA_SAFETY_ON_TRUE_RETURN_VAL(!ecore_con_client_send(module->client->current->conn, "0\r\n\r\n", 5), EINA_FALSE);
        goto post_send;
     }

   net->refcount++;
   sprintf((char *)chunk_size, "%" PRIx64 "\r\n", data->size);
   chunk_data = eina_binbuf_new();
   eina_binbuf_append_length(chunk_data, (unsigned char *)chunk_size, strlen(chunk_size));
   eina_binbuf_append_length(chunk_data, data->data, data->size);
   eina_binbuf_append_length(chunk_data, (unsigned char *)"\r\n", 2);
   EINA_SAFETY_ON_NULL_RETURN_VAL(module->client->current->conn, EINA_FALSE);
   EINA_SAFETY_ON_TRUE_RETURN_VAL(!ecore_con_client_send(module->client->current->conn,
                                  eina_binbuf_string_get(chunk_data), eina_binbuf_length_get(chunk_data)), EINA_FALSE);
   eina_binbuf_free(chunk_data);


post_send:
   if (nullify) module->client->current = NULL;
   return EINA_TRUE;
}
Ejemplo n.º 13
0
Archivo: docs.c Proyecto: tasn/efl
static int
_append_section(const Eolian_State *state, const char *desc, int ind, int curl,
                Eina_Strbuf *buf, Eina_Strbuf *wbuf)
{
   Eina_Bool try_note = EINA_TRUE;
   while (*desc)
     {
        eina_strbuf_reset(wbuf);
        while (*desc && isspace(*desc) && (*desc != '\n'))
          eina_strbuf_append_char(wbuf, *desc++);
        if (try_note)
          {
#define CHECK_NOTE(str) !strncmp(desc, str ": ", sizeof(str ":"))
             if (CHECK_NOTE("Note"))
               {
                  eina_strbuf_append(wbuf, "@note ");
                  desc += sizeof("Note:");
               }
             else if (CHECK_NOTE("Warning"))
               {
                  eina_strbuf_append(wbuf, "@warning ");
                  desc += sizeof("Warning:");
               }
             else if (CHECK_NOTE("Remark"))
               {
                  eina_strbuf_append(wbuf, "@remark ");
                  desc += sizeof("Remark:");
               }
             else if (CHECK_NOTE("TODO"))
               {
                  eina_strbuf_append(wbuf, "@todo ");
                  desc += sizeof("TODO:");
               }
#undef CHECK_NOTE
             try_note = EINA_FALSE;
          }
        if (*desc == '\\')
          {
             desc++;
             if ((*desc != '@') && (*desc != '$'))
               eina_strbuf_append_char(wbuf, '\\');
             eina_strbuf_append_char(wbuf, *desc++);
          }
        else if (*desc == '@')
          {
             const char *ref = ++desc;
             if (isalpha(*desc) || (*desc == '_'))
               {
                  eina_strbuf_append(wbuf, "@ref ");
                  while (isalnum(*desc) || (*desc == '.') || (*desc == '_'))
                    ++desc;
                  if (*(desc - 1) == '.') --desc;
                  Eina_Stringshare *refn = eina_stringshare_add_length(ref, desc - ref);
                  _generate_ref(state, refn, wbuf);
                  eina_stringshare_del(refn);
               }
             else
               eina_strbuf_append_char(wbuf, '@');
          }
        else if (*desc == '$')
          {
             desc++;
             if (isalpha(*desc))
               eina_strbuf_append(wbuf, "@c ");
             else
               eina_strbuf_append_char(wbuf, '$');
          }
        while (*desc && !isspace(*desc))
          eina_strbuf_append_char(wbuf, *desc++);
        int limit = DOC_LIMIT(ind);
        int wlen = eina_strbuf_length_get(wbuf);
        if ((int)(curl + wlen) > limit)
          {
             curl = 3;
             eina_strbuf_append_char(buf, '\n');
             curl += _indent_line(buf, ind);
             eina_strbuf_append(buf, " * ");
             if (*eina_strbuf_string_get(wbuf) == ' ')
               eina_strbuf_remove(wbuf, 0, 1);
          }
        curl += eina_strbuf_length_get(wbuf);
        eina_strbuf_append(buf, eina_strbuf_string_get(wbuf));
        if (*desc == '\n')
          {
             desc++;
             eina_strbuf_append_char(buf, '\n');
             while (*desc == '\n')
               {
                  _indent_line(buf, ind);
                  eina_strbuf_append(buf, " *\n");
                  desc++;
                  try_note = EINA_TRUE;
               }
             curl = _indent_line(buf, ind) + 3;
             eina_strbuf_append(buf, " * ");
          }
     }
   return curl;
}