コード例 #1
0
static Eina_Bool
em_file_open(void *video,
             const char   *file)
{
   Emotion_Gstreamer_Video *ev = video;
   Eina_Strbuf *sbuf = NULL;
   const char *uri;

   if (!file) return EINA_FALSE;
   if (strstr(file, "://") == NULL)
     {
        sbuf = eina_strbuf_new();
        eina_strbuf_append(sbuf, "file://");
        if (strncmp(file, "./", 2) == 0)
          file += 2;
	if (strstr(file, ":/") != NULL)
	  { /* We absolutely need file:///C:/ under Windows, so adding it here */
             eina_strbuf_append(sbuf, "/");
	  }
	else if (*file != '/')
          {
             char tmp[PATH_MAX];

             if (getcwd(tmp, PATH_MAX))
               {
                  eina_strbuf_append(sbuf, tmp);
                  eina_strbuf_append(sbuf, "/");
               }
          }
        eina_strbuf_append(sbuf, file);
     }

   ev->play_started = 0;
   ev->pipeline_parsed = 0;

   uri = sbuf ? eina_strbuf_string_get(sbuf) : file;
   DBG("setting file to '%s'", uri);
   ev->pipeline = gstreamer_video_sink_new(ev, ev->obj, uri);
   if (sbuf) eina_strbuf_free(sbuf);

   if (!ev->pipeline)
     return EINA_FALSE;

   ev->eos_bus = gst_pipeline_get_bus(GST_PIPELINE(ev->pipeline));
   if (!ev->eos_bus)
     {
        ERR("could not get the bus");
        return EINA_FALSE;
     }

   gst_bus_set_sync_handler(ev->eos_bus, _eos_sync_fct, ev);

   ev->position = 0.0;

   return 1;
}
コード例 #2
0
ファイル: database_type_api.c プロジェクト: tasn/efl
EAPI Eina_Stringshare *
eolian_typedecl_c_type_get(const Eolian_Typedecl *tp)
{
   Eina_Stringshare *ret;
   Eina_Strbuf *buf;
   EINA_SAFETY_ON_NULL_RETURN_VAL(tp, NULL);
   buf = eina_strbuf_new();
   database_typedecl_to_str(tp, buf);
   ret = eina_stringshare_add(eina_strbuf_string_get(buf));
   eina_strbuf_free(buf);
   return ret;
}
コード例 #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;
}
コード例 #4
0
static void
on_error(void *user_data, Evas_Object *webview, void *event_info)
{
    Eina_Strbuf* buffer;
    const Ewk_Web_Error *error = (const Ewk_Web_Error *)event_info;

    buffer = eina_strbuf_new();
    eina_strbuf_append_printf(buffer, "<html><body><div style=\"color:#ff0000\">ERROR!</div><br><div>Code: %d<br>Description: %s<br>URL: %s</div></body</html>",
                              ewk_web_error_code_get(error), ewk_web_error_description_get(error), ewk_web_error_url_get(error));

    ewk_view_html_string_load(webview, eina_strbuf_string_get(buffer), 0, ewk_web_error_url_get(error));
    eina_strbuf_free(buffer);
}
コード例 #5
0
Eina_Bool
_alert_command_del(void *data,
                   int type EINA_UNUSED,
                   void *event)
{
   Module_Alert_Command *mac = data;
   Ecore_Exe_Event_Del *del = event;
   const char *val;

   if (mac != ecore_exe_data_get(del->exe)) return EINA_TRUE;

   DBG("mac[%p] del[%p]", mac, del);

   val = gotham_citizen_var_get(mac->gotham->me, mac->command->name);
   DBG("val[%s] value[%s]", val, eina_strbuf_string_get(mac->buf));

   if (!val) goto set_var;

   if (strcmp(val, eina_strbuf_string_get(mac->buf)))
     {
        Eina_Strbuf *buf = eina_strbuf_new();
        EINA_SAFETY_ON_NULL_GOTO(buf, clean_mac);

        eina_strbuf_append_printf(buf, ".notification send %s Variable '%s' changed from '%s' to '%s'",
                                  strlen(mac->command->notification) ? mac->command->notification : "dev",
                                  mac->command->name, val,
                                  eina_strbuf_string_get(mac->buf));
        gotham_citizen_send(mac->gotham->alfred, eina_strbuf_string_get(buf));
        eina_strbuf_free(buf);
     }

set_var:
   gotham_citizen_var_set(mac->gotham->me, mac->command->name, eina_strbuf_string_get(mac->buf));

clean_mac:
   _alert_command_clean(mac);
   return EINA_TRUE;
}
コード例 #6
0
ファイル: database_expr_api.c プロジェクト: tasn/efl
EAPI Eina_Stringshare *
eolian_expression_serialize(const Eolian_Expression *expr)
{
   EINA_SAFETY_ON_NULL_RETURN_VAL(expr, NULL);
   Eina_Strbuf *buf = eina_strbuf_new();
   if (!_expr_serialize(expr, buf, EINA_TRUE))
     {
        eina_strbuf_free(buf);
        return NULL;
     }
   const char *ret = eina_stringshare_add(eina_strbuf_string_get(buf));
   eina_strbuf_free(buf);
   return ret;
}
コード例 #7
0
ファイル: io.c プロジェクト: Stefan-Schmidt/efl
/* expand fname to full path name (so that PATH is ignored) plus turn
 * stuff into a command, and also verify whether the path exists */
static char *
get_cmdline_from_argv(const char *fname, const char **argv)
{
   Eina_Strbuf *buf;
   char        *ret;
   char         pbuf[PATH_MAX];
   const char  *arg = NULL;

   FILE *testf = fopen(fname, "rb");
   if  (!testf)
      return NULL;

   fclose(testf);

   /* for windows, we have realpath in evil, no need for GetFullPathName */
   if (!realpath(fname, pbuf))
      return NULL;

   buf = eina_strbuf_new();
   eina_strbuf_append_char(buf, '"');
   eina_strbuf_append(buf, pbuf);
   eina_strbuf_append_char(buf, '"');

   while ((arg = *(argv++)))
     {
        char c;
        eina_strbuf_append_char(buf, ' ');
        eina_strbuf_append_char(buf, '"');

        while ((c = *(arg++)))
          {
#ifndef _WIN32
             if (c == '"' || c == '$') eina_strbuf_append_char(buf, '\\');
             eina_strbuf_append_char(buf, c);
#else
             if      (c == '"') eina_strbuf_append_char(buf, '\\');
             else if (c == '%') eina_strbuf_append_char(buf,  '"');
             eina_strbuf_append_char(buf, c);
             if (c == '%') eina_strbuf_append_char(buf,  '"');
#endif
          }

        eina_strbuf_append_char(buf, '"');
     }

   ret = strdup(eina_strbuf_string_get(buf));
   eina_strbuf_free(buf);
   return ret;
}
コード例 #8
0
ファイル: eldbus_signal_handler.c プロジェクト: tasn/efl
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);
}
コード例 #9
0
ファイル: e_pattern_lock.c プロジェクト: Limsik/e17
void on_mouse_in(void *data, Evas *e, Evas_Object *obj, void *event_info) {
	Evas_Object *object = (Evas_Object*)data;
	int col, row;
	char buf[5];

	col = atoi(edje_object_data_get(object, "col"));
	row = atoi(edje_object_data_get(object, "row"));

	if(mouse_down == EINA_TRUE) {
		snprintf(buf, 5, ",%dx%d", col, row);
		eina_strbuf_append(password, buf);
		printf(_("Password is '%s'\n"), eina_strbuf_string_get(password));
	}
	printf(_("Mouse in on %dx%d\n"), col, row);
}
コード例 #10
0
ファイル: utils.c プロジェクト: wjhendr/enlightenment
char *
string_build(const char *fmt, ...)
{
   va_list ap;
   Eina_Strbuf *buffer = eina_strbuf_new();
   char *ret;

   va_start(ap, fmt);
   eina_strbuf_prepend_vprintf(buffer, fmt, ap);
   va_end(ap);

   ret = strdup(eina_strbuf_string_get(buffer));
   eina_strbuf_free(buffer);

   return ret;
}
コード例 #11
0
ファイル: albumart.c プロジェクト: mjtorn/rage
static Ecore_Con_Url *
_fetch(Eina_Strbuf *sb)
{
   Ecore_Con_Url *f;
   const char *qs;

   qs = eina_strbuf_string_get(sb);
   if (!qs) return NULL;
   f = ecore_con_url_new(qs);
   if (!f) return NULL;
   ecore_con_url_additional_header_add
   (f, "user-agent",
    "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19");
   ecore_con_url_get(f);
   return f;
}
コード例 #12
0
ファイル: ede_game.c プロジェクト: DaveMDS/ede
EAPI void
ede_game_debug_panel_update(double now)
{
   Eina_Strbuf *t;
   char *ts;
   static int last_second = 0;
   static int fps_counter = 0;
   static int FPS = 0;

   if (!_debug_panel_enable) return;

   // calc FPS
   fps_counter++;
   if ((int)now > last_second)
   {
      //~ D("last second %d %d", last_second, fps_counter);
      last_second = now;
      FPS = fps_counter;
      fps_counter = 0;
   }

   t = eina_strbuf_new();

   // game info
   eina_strbuf_append(t, "<h3>game:</h3><br>");

   ts = ede_game_time_get(now);
   eina_strbuf_append_printf(t, "FPS %d  time %s<br>", FPS, ts);
   EDE_FREE(ts);

   eina_strbuf_append_printf(t, "lives %d<br>bucks %d<br>",
                             _player_lives, _player_bucks);
   eina_strbuf_append(t, "<br>");

   // info from other components
   ede_enemy_debug_info_fill(t);
   ede_tower_debug_info_fill(t);
   ede_bullet_debug_info_fill(t);
   ede_level_debug_info_fill(t);

   ede_gui_debug_text_set(eina_strbuf_string_get(t));
   eina_strbuf_free(t);

}
コード例 #13
0
ファイル: utils.c プロジェクト: wjhendr/enlightenment
char *
replace_string(const char *string, const char *substr, const char *replacement)
{
   char *str_cpy = strdup(string);
   char *pch;
   char *ret;
   Eina_Strbuf *buffer = eina_strbuf_new();

   pch = strtok(str_cpy, substr);
   eina_strbuf_append(buffer, pch);

   while ((pch = strtok(NULL, substr)))
     eina_strbuf_append_printf(buffer, "%s%s", replacement, pch);

   ret = strdup(eina_strbuf_string_get(buffer));
   free(str_cpy);
   eina_strbuf_free(buffer);
   return ret;
}
コード例 #14
0
static void
title_set(Ecore_Evas *ee, const char *title, int progress)
{
    Eina_Strbuf* buffer;

    if (!title || !*title) {
        ecore_evas_title_set(ee, APP_NAME);
        return;
    }

    buffer = eina_strbuf_new();
    if (progress < 100)
        eina_strbuf_append_printf(buffer, "%s (%d%%) - %s", title, progress, APP_NAME);
    else
        eina_strbuf_append_printf(buffer, "%s - %s", title, APP_NAME);

    ecore_evas_title_set(ee, eina_strbuf_string_get(buffer));
    eina_strbuf_free(buffer);
}
コード例 #15
0
ファイル: e_pattern_lock.c プロジェクト: Limsik/e17
void on_mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info) {
	Evas_Object *object = (Evas_Object*)data;
	int col, row;
	char buf[4];

	if(password)
		eina_strbuf_reset(password);
	else
		password = eina_strbuf_new();

	col = atoi(edje_object_data_get(object, "col"));
	row = atoi(edje_object_data_get(object, "row"));

	snprintf(buf, 4, "%dx%d", col, row);
	eina_strbuf_append(password, buf);
	mouse_down=EINA_TRUE;

	printf(_("Mouse down on %dx%d\n"), col, row);
	printf(_("Password is '%s'\n"), eina_strbuf_string_get(password));
}
コード例 #16
0
ファイル: shotgun.c プロジェクト: Limsik/e17
static Shotgun_Data_Type
shotgun_data_tokenize(Shotgun_Auth *auth, Ecore_Con_Event_Server_Data *ev)
{
   const char *data;
   data = auth->buf ? eina_strbuf_string_get(auth->buf) : ev->data;
   if (data[0] != '<') return SHOTGUN_DATA_TYPE_UNKNOWN;

   switch (data[1])
     {
      case 'm':
        return SHOTGUN_DATA_TYPE_MSG;
      case 'i':
        return SHOTGUN_DATA_TYPE_IQ;
      case 'p':
        return SHOTGUN_DATA_TYPE_PRES;
      default:
        break;
     }
   return SHOTGUN_DATA_TYPE_UNKNOWN;
}
コード例 #17
0
ファイル: videoplayer_obj.c プロジェクト: naguirre/enna
void
_update_time_part(Evas_Object *obj, const char *part, double t)
{
   Eina_Strbuf *str;
   double s;
   int h, m;

   s = t;
   h = (int)(s / 3600.0);
   s -= h * 3600;
   m = (int)(s / 60.0);
   s -= m * 60;

   str = eina_strbuf_new();
   eina_strbuf_append_printf(str, "%02d:%02d:%02d", h, m, (int)s);

   elm_object_part_text_set(obj, part, eina_strbuf_string_get(str));

   eina_strbuf_free(str);
}
コード例 #18
0
ファイル: eail_dayselector.c プロジェクト: patrykka/eail
/**
 * @brief Implementation AtkObject->ref_child callback
 *
 * ATK doc says:\n
 * Gets a reference to the specified accessible child of the object. The
 * accessible children are 0-based so the first accessible child is at index 0,
 * the second at index 1 and so on.
 *
 * @param obj an AtkObject
 * @param i child index
 *
 * @returns an AtkObject representing the specified accessible child of the
 * accessible.
 */
static AtkObject *
eail_dayselector_ref_child(AtkObject *obj, gint i)
{
   AtkObject *child = NULL;
   Eina_Strbuf *part_name = NULL;
   Evas_Object *ds_widget = NULL, *day_check = NULL;

   g_return_val_if_fail (EAIL_IS_WIDGET(obj), NULL);

   ds_widget = eail_widget_get_widget(EAIL_WIDGET(obj) );
   part_name = _eail_dayselector_gen_day_str(i);
   day_check = elm_object_part_content_get
                  (ds_widget, eina_strbuf_string_get(part_name));

   /* dayselector consists of objects with type CHECK-widget */
   child = _eail_create_dayselector_child(day_check);

   eina_strbuf_free(part_name);
   return child;
}
コード例 #19
0
char *
textblock_escape_string(const char *text)
{
    if (!text)
        return NULL;

    Eina_Strbuf *buf = eina_strbuf_new();
    eina_strbuf_append(buf, text);

    eina_strbuf_replace_all(buf, "\n", "<br>");
    eina_strbuf_replace_all(buf, "\t", "<\t>");
    eina_strbuf_replace_all(buf, "<", "&lt;");
    eina_strbuf_replace_all(buf, ">", "&gt;");
    eina_strbuf_replace_all(buf, "&", "&amp;");

    char *res = strdup(eina_strbuf_string_get(buf));
    eina_strbuf_free(buf);

    return res;
}
コード例 #20
0
ファイル: sources.c プロジェクト: Stefan-Schmidt/efl
static Eina_Bool
_function_exists(const char *fname, Eina_Strbuf *buf)
{
   const char *ptr = eina_strbuf_string_get(buf);
   size_t flen = strlen(fname);
   while ((ptr = strstr(ptr, fname)) != NULL)
     {
        switch (*(ptr - 1))
          {
           case '\n':
           case ' ':
             switch (*(ptr + flen))
               {
                case ' ':
                case '(':
                  return EINA_TRUE;
               }
          }
        ++ptr;
     }
   return EINA_FALSE;
}
コード例 #21
0
ファイル: utils.c プロジェクト: wjhendr/enlightenment
Eina_Bool
file_read(const char *file_name, char **buffer)
{
   FILE *xml_handler;
   char data;
   Eina_Strbuf *buf;

   xml_handler = fopen(file_name, "rt");
   if (!xml_handler)
     {
        printf("Error to read file: %s\n", file_name);
        return EINA_FALSE;
     }
   buf = eina_strbuf_new();

   while ((data = fgetc(xml_handler)) != EOF)
     eina_strbuf_append_char(buf, data);

   fclose(xml_handler);
   *buffer = strdup(eina_strbuf_string_get(buf));
   eina_strbuf_free(buf);

   return EINA_TRUE;
}
コード例 #22
0
ファイル: smtp_handlers.c プロジェクト: Limsik/e17
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;
}
コード例 #23
0
ファイル: headers.c プロジェクト: Stefan-Schmidt/efl
static void
_gen_func(const Eolian_Unit *src, const Eolian_Function *fid,
          Eolian_Function_Type ftype, Eina_Strbuf *buf, char *cname,
          char *cnameu, Eina_Bool legacy)
{
   Eina_Stringshare *fcn = eolian_function_full_c_name_get(fid, ftype, legacy);
   if (!fcn)
     return;

   Eina_Bool var_as_ret = EINA_FALSE;
   const Eolian_Type *rtp = eolian_function_return_type_get(fid, ftype);
   if (ftype == EOLIAN_PROP_GET && !rtp)
     {
        void *d1, *d2;
        Eina_Iterator *itr = eolian_property_values_get(fid, ftype);
        if (eina_iterator_next(itr, &d1) && !eina_iterator_next(itr, &d2))
          {
             rtp = eolian_parameter_type_get((Eolian_Function_Parameter *)d1);
             var_as_ret = EINA_TRUE;
          }
        eina_iterator_free(itr);
     }

   Eolian_Object_Scope fsc = eolian_function_scope_get(fid, ftype);

   /* this one will never be satisfied in legacy */
   if (eolian_function_is_beta(fid))
     eina_strbuf_append_printf(buf, "#ifdef %s_BETA\n", cnameu);
   /* XXX: is this right? we expose potentially internal stuff into legacy */
   if (!legacy && (fsc == EOLIAN_SCOPE_PROTECTED))
     eina_strbuf_append_printf(buf, "#ifdef %s_PROTECTED\n", cnameu);

   const Eolian_Implement *fimp = eolian_function_implement_get(fid);

   Eina_Bool hasdoc = !!eolian_implement_documentation_get(fimp, ftype);
   if (!hasdoc && ((ftype == EOLIAN_PROP_GET) || (ftype == EOLIAN_PROP_SET)))
     hasdoc = !!eolian_implement_documentation_get(fimp, EOLIAN_PROPERTY);
   if (hasdoc)
     {
        Eina_Strbuf *dbuf = eo_gen_docs_func_gen(src, fid, ftype, 0, legacy);
        eina_strbuf_append(buf, eina_strbuf_string_get(dbuf));
        eina_strbuf_append_char(buf, '\n');
        eina_strbuf_free(dbuf);
     }
   eina_strbuf_append(buf, legacy ? "EAPI " : "EOAPI ");
   if (rtp)
     {
        Eina_Stringshare *rtps = eolian_type_c_type_get(rtp);
        eina_strbuf_append(buf, rtps);
        if (rtps[strlen(rtps) - 1] != '*')
          eina_strbuf_append_char(buf, ' ');
        eina_stringshare_del(rtps);
     }
   else
     eina_strbuf_append(buf, "void ");

   eina_strbuf_append(buf, fcn);
   eina_stringshare_del(fcn);

   Eina_Bool first = EINA_TRUE;
   Eina_Strbuf *flagbuf = NULL;
   int nidx = !legacy || !eolian_function_is_class(fid);

   eina_strbuf_append_char(buf, '(');
   if (nidx)
     {
        if ((ftype == EOLIAN_PROP_GET) || eolian_function_object_is_const(fid)
            || eolian_function_is_class(fid))
          {
             eina_strbuf_append(buf, "const ");
          }
        if (legacy)
          eina_strbuf_append_printf(buf, "%s *obj", cname);
        else
          eina_strbuf_append(buf, "Eo *obj");
        first = EINA_FALSE;
     }

   {
      Eolian_Function_Parameter *pr = NULL;
      Eina_Iterator *itr = eolian_property_keys_get(fid, ftype);
      EINA_ITERATOR_FOREACH(itr, pr)
        {
           const Eolian_Type *prt = eolian_parameter_type_get(pr);
           const char *prn = eolian_parameter_name_get(pr);
           Eina_Stringshare *prtn = eolian_type_c_type_get(prt);
           ++nidx;
           if (!first)
             eina_strbuf_append(buf, ", ");
           eina_strbuf_append_printf(buf, "%s %s", prtn, prn);
           eina_stringshare_del(prtn);
           first = EINA_FALSE;
           if (!eolian_parameter_is_nonull(pr))
             continue;
           if (!flagbuf)
             {
                flagbuf = eina_strbuf_new();
                eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
             }
           else
             eina_strbuf_append_printf(flagbuf, ", %d", nidx);
        }
      eina_iterator_free(itr);
   }

   if (!var_as_ret)
     {
        Eina_Iterator *itr = NULL;
        if (ftype == EOLIAN_PROP_GET || ftype == EOLIAN_PROP_SET)
          itr = eolian_property_values_get(fid, ftype);
        else
          itr = eolian_function_parameters_get(fid);

        Eolian_Function_Parameter *pr = NULL;
        EINA_ITERATOR_FOREACH(itr, pr)
          {
             const Eolian_Type *prt = eolian_parameter_type_get(pr);
             const char *prn = eolian_parameter_name_get(pr);
             Eina_Stringshare *prtn = eolian_type_c_type_get(prt);

             ++nidx;
             if (!first)
               eina_strbuf_append(buf, ", ");
             eina_strbuf_append(buf, prtn);
             if (prtn[strlen(prtn) - 1] != '*')
               eina_strbuf_append_char(buf, ' ');
             eina_strbuf_append(buf,
                 _get_add_star(ftype, eolian_parameter_direction_get(pr)));
             eina_strbuf_append(buf, prn);
             eina_stringshare_del(prtn);
             first = EINA_FALSE;
             if (!eolian_parameter_is_nonull(pr))
               continue;
             if (!flagbuf)
               {
                  flagbuf = eina_strbuf_new();
                  eina_strbuf_append_printf(flagbuf, " EINA_ARG_NONNULL(%d", nidx);
               }
             else
               eina_strbuf_append_printf(flagbuf, ", %d", nidx);
          }

        eina_iterator_free(itr);
     }
コード例 #24
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;
}
コード例 #25
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;
}
コード例 #26
0
ファイル: e_about.c プロジェクト: FlorentRevest/Enlightenment
E_API E_About *
e_about_new(void)
{
   E_Obj_Dialog *od;
   char buf[16384];
   FILE *f;
   Eina_Strbuf *tbuf;

   od = e_obj_dialog_new(_("About Enlightenment"), "E", "_about");
   if (!od) return NULL;
   e_obj_dialog_obj_theme_set(od, "base/theme/about", "e/widgets/about/main");
   e_obj_dialog_obj_part_text_set(od, "e.text.label", _("Close"));
   e_obj_dialog_obj_part_text_set(od, "e.text.title", _("Enlightenment"));
   e_obj_dialog_obj_part_text_set(od, "e.text.version", VERSION);
   snprintf
     (buf, sizeof(buf), "%s%s",
     _(
       "<title>Copyright &copy; 2000-2015, by the Enlightenment "
       "Development Team</><br>"
       "<br>"
       "We hope you enjoy using this software as much as we enjoyed "
       "writing it.<br>"
       "<br>"
       "To contact us please visit:<br>"
       "<hilight>http://www.enlightenment.org</><br>"
       "<br>"
       ),
     "All rights reserved.<br>"
     "<br>"
     "Redistribution and use in source and binary forms, with or without "
     "modification, are permitted provided that the following conditions "
     "are met:<br>"
     "<br>"
     "1. Redistributions of source code must retain the above copyright "
     "notice, this list of conditions and the following disclaimer.<br>"
     "2. Redistributions in binary form must reproduce the above copyright "
     "notice, this list of conditions and the following disclaimer in the "
     "documentation and/or other materials provided with the "
     "distribution.<br>"
     "<br>"
     "<hilight>THIS SOFTWARE IS PROVIDED “AS IS” AND ANY EXPRESS OR "
     "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED "
     "WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE "
     "ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR "
     "CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, "
     "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT "
     "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF "
     "USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED "
     "AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT "
     "LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN "
     "ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE "
     "POSSIBILITY OF SUCH DAMAGE.</><br>"
     );
   e_obj_dialog_obj_part_text_set(od, "e.textblock.about", buf);

   e_prefix_data_concat_static(buf, "AUTHORS");
   f = fopen(buf, "r");
   if (f)
     {
        tbuf = eina_strbuf_new();
        eina_strbuf_append(tbuf, _("<title>The Team</><br><br>"));
        while (fgets(buf, sizeof(buf), f))
          {
             int len;

             len = strlen(buf);
             if (len > 0)
               {
                  if (buf[len - 1] == '\n')
                    {
                       buf[len - 1] = 0;
                       len--;
                    }
                  if (len > 0)
                    {
                       char *p;

                       do
                         {
                            p = strchr(buf, '<');
                            if (p) *p = 0;
                         }
                       while (p);
                       do
                         {
                            p = strchr(buf, '>');
                            if (p) *p = 0;
                         }
                       while (p);
                       eina_strbuf_append_printf(tbuf, "%s<br>", buf);
                    }
               }
          }
        fclose(f);
        if (tbuf)
          {
             e_obj_dialog_obj_part_text_set(od, "e.textblock.authors",
                                            eina_strbuf_string_get(tbuf));
             eina_strbuf_free(tbuf);
          }
     }
   return (E_About *)od;
}
コード例 #27
0
static Eina_Bool
_forecasts_server_add(void *data, int type, void *event)
{
   Instance *inst;
   Ecore_Con_Event_Server_Add *ev;
   char buf[1024];
   char forecast[1024];
   char degrees;
   int err_server;
   Eina_Strbuf *city;
   city = eina_strbuf_new();
   
   inst = data;
   if (!inst)
     return EINA_TRUE;

   ev = event;
   if ((!inst->server) || (inst->server != ev->server))
     return EINA_TRUE;

   if (inst->ci->degrees == DEGREES_F)
     degrees = 'f';
   else
     degrees = 'c';

   if (inst->ci->by_code == WOEID_CITY)
   {  
	  city = url_normalize_str(inst->ci->code);
      snprintf(forecast, sizeof(forecast), "/v1/public/yql?q=select%%20*%%20from%%20weather.forecast%%20where%%20woeid%%20in%%20%%28select%%20woeid%%20from%%20geo.places%%281%%29%%20where%%20text=\"%s\"%%20%%29%%20and%%20u='%c'", eina_strbuf_string_get(city), degrees);
      eina_strbuf_free(city);
   }
   else
      snprintf(forecast, sizeof(forecast), "/v1/public/yql?q=select%%20*%%20from%%20weather.forecast%%20where%%20woeid%%3D%s%%20and%%20u%%3D%%27%c%%27", inst->ci->code, degrees);

   snprintf(buf, sizeof(buf), "GET http://%s%s HTTP/1.1\r\n"
                              "Host: %s\r\n"
                              "Connection: close\r\n\r\n",
            inst->ci->host, forecast, inst->ci->host);
   DEBUG("Server: %s", buf);
   err_server=ecore_con_server_send(inst->server, buf, strlen(buf));
   DEBUG("Server error: %d", err_server);
   return EINA_FALSE;
}
コード例 #28
0
static int
_forecasts_parse(void *data)
{
   Instance *inst;
   char *needle;
   char city[256];
   char region[256];
   char *region_ptr;
   char location[512];
   float visibility;
   int i;

   inst = data;
   if (!inst)
     return 0;
   if (!inst->buffer)
     return 0;

   /* Location */
   needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:location ");
   //DEBUG("Needle: %s", needle);

   if (!needle)
   {
      DEBUG("Parse: %s","Location");
      goto error;
  }
   needle = strstr(needle, "city=\"");
   DEBUG("Needle: %s", needle);
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%255[^\"]\"", city);

   region[0] = '\0';
   needle = strstr(needle, "region=\"");
   if (!needle) goto error;
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%255[^\"]\"", region);
   region_ptr = region;
   //get rid of leading white space
   if (region[0] = ' ')
     region_ptr++;

   if (strlen(region_ptr))
     snprintf(location, 512, "%s, %s", city, region_ptr);
   else
     snprintf(location, 512, "%s", city);

   eina_stringshare_replace(&inst->location, location);

   /* Units */
   needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:units ");
   if (!needle)
   {
      DEBUG("Parse: %s", "Units");
      goto error;
   }
   needle = strstr(needle, "distance=\"");
   if (!needle)
   {
       DEBUG("Parse: %s", "Distance");
       goto error;
    }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%2[^\"]\"", inst->units.distance);

   needle = strstr(needle, "pressure=\"");
   if (!needle)
   {   DEBUG("Parse: %s","Pressure");
       goto error;
    }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%2[^\"]\"", inst->units.pressure);

   needle = strstr(needle, "speed=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Speed");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%3[^\"]\"", inst->units.speed);

   needle = strstr(needle, "temperature=\"");
    if (!needle)
   {   DEBUG("Parse: %s", "Temp");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%c\"", &inst->units.temp);

   DEBUG("Parse Units: %s, %s, %s, %c", inst->units.distance, inst->units.pressure, inst->units.speed, inst->units.temp);

   /* Current conditions */
   needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:condition ");
   if (!needle)
   {
      DEBUG("Parse: %s", "Conditions");
      goto error;
   }

   needle = strstr(needle, "code=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Code");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%d\"", &inst->condition.code);

   needle = strstr(needle, "date=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Date");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%51[^\"]\"", inst->condition.update);

   needle = strstr(needle, "temp=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Temp");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%d\"", &inst->condition.temp);

   needle = strstr(needle, "text=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Text");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%255[^\"]\"", inst->condition.desc);

   DEBUG("Parse condition: %d, %s, %d, %s", inst->condition.code, inst->condition.update, inst->condition.temp,  inst->condition.desc);

   /* Details */
   /* Wind */
   needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:wind ");

   needle = strstr(needle, "chill=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Wind");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%d\"", &inst->details.wind.chill);

   needle = strstr(needle, "direction=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Wind direction");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%d\"", &inst->details.wind.direction);

   needle = strstr(needle, "speed=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Wind speed");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%d\"", &inst->details.wind.speed);

   DEBUG("Parse Wind: %d, %d, %d",inst->details.wind.chill, inst->details.wind.direction, inst->details.wind.speed);

   /* Atmosphere */
   needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:atmosphere ");

   needle = strstr(needle, "humidity=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Humidity");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%d\"", &inst->details.atmosphere.humidity);

    needle = strstr(needle, "pressure=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Pressure");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%f\"", &inst->details.atmosphere.pressure);
   /* Yahoo API is returning weird values here everything scaled by MB_TO_IN
    *   This is a known issue, for example see:
    *      https://github.com/monkeecreate/jquery.simpleWeather/issues/227
    * May change in the future: the below line may need removed or modified.*/
   inst->details.atmosphere.pressure /= MB_TO_IN;

   needle = strstr(needle, "rising=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Rising");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%d\"", &inst->details.atmosphere.rising);

   needle = strstr(needle, "visibility=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Visibility");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%f\"", &visibility);
   inst->details.atmosphere.visibility = visibility;

   DEBUG("Parse Atmosphere: %d, %f, %d, %f", inst->details.atmosphere.humidity, inst->details.atmosphere.pressure, inst->details.atmosphere.rising, inst->details.atmosphere.visibility);

   /* Astronomy */
   needle = strstr(eina_strbuf_string_get(inst->buffer), "<yweather:astronomy ");
   needle = strstr(needle, "sunrise=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Sunrise");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%8[^\"]\"", inst->details.astronomy.sunrise);

   needle = strstr(needle, "sunset=\"");
   if (!needle)
   {   DEBUG("Parse: %s", "Sunset");
       goto error;
   }
   needle = strstr(needle, "\"");
   sscanf(needle, "\"%8[^\"]\"", inst->details.astronomy.sunset);

   DEBUG("Parse Astronomy: %s %s", inst->details.astronomy.sunrise, inst->details.astronomy.sunset);

   /* Forecasts */
   for (i = 0; i < inst->ci->days / 5; i++)
     {
        needle = strstr(needle, "<yweather:forecast ");
        needle = strstr(needle, "code=\"");
        if (!needle)
        {   DEBUG("Parse Forecast: %d %s", i, "code");
            goto error;
        }
        needle = strstr(needle, "\"");
        sscanf(needle, "\"%d\"", &inst->forecast[i].code);

        needle = strstr(needle, "date=\"");
        if (!needle)
        {   DEBUG("Parse Forecast: %d %s", i, "date");
            goto error;
        }
        needle = strstr(needle, "\"");
        sscanf(needle, "\"%12[^\"]\"", inst->forecast[i].date);

        needle = strstr(needle, "day=\"");
        if (!needle)
        {   DEBUG("Parse Forecast: %d %s", i, "day");
            goto error;
        }
        needle = strstr(needle, "\"");
        sscanf(needle, "\"%4[^\"]\"", inst->forecast[i].day);

        needle = strstr(needle, "high=\"");
        if (!needle)
        {   DEBUG("Parse Forecast: %d %s", i, "high");
            goto error;
        }
        needle = strstr(needle, "\"");
        sscanf(needle, "\"%d\"", &inst->forecast[i].high);

        needle = strstr(needle, "low=\"");
        if (!needle)
        {   DEBUG("Parse Forecast: %d %s", i, "low");
            goto error;
        }
        needle = strstr(needle, "\"");
        sscanf(needle, "\"%d\"", &inst->forecast[i].low);

        needle = strstr(needle, "text=\"");
        if (!needle)
        {   DEBUG("Parse Forecast: %d %s", i, "text");
            goto error;
        }
        needle = strstr(needle, "\"");
        sscanf(needle, "\"%255[^\"]\"", inst->forecast[i].desc);
   }
   return 1;

error:
   fprintf(stderr, "(Forecast Module): ERROR **: Couldn't parse info from %s\n", inst->ci->host);
   return 0;
}
コード例 #29
0
ファイル: shotgun.c プロジェクト: 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;
}
コード例 #30
0
ファイル: shotgun.c プロジェクト: 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;
}