示例#1
0
static int
hc_prop(http_connection_t *hc, const char *remain, void *opaque,
        http_cmd_t method)
{
    htsbuf_queue_t out;
    rstr_t *r;
    int rval, i;
    prop_t *p;
    const char *action = http_arg_get_req(hc, "action");

    if(remain == NULL)
        return 404;

    p = prop_from_path(remain);

    if(p == NULL)
        return 404;

    htsbuf_queue_init(&out, 0);

    switch(method) {
    case HTTP_CMD_GET:

        if(action != NULL) {
            event_t *e = event_create_action_str(action);
            prop_send_ext_event(p, e);
            event_release(e);
            rval = HTTP_STATUS_OK;
            break;
        }

        r = prop_get_string(p, NULL);

        if(r == NULL) {

            char **childs = prop_get_name_of_childs(p);
            if(childs == NULL) {
                rval = HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE;
                break;
            }
            for(i = 0; childs[i] != NULL; i++) {
                htsbuf_qprintf(&out, "\t%s\n", childs[i]);
            }
        } else {
            htsbuf_append(&out, rstr_get(r), strlen(rstr_get(r)));
            htsbuf_append(&out, "\n", 1);
            rstr_release(r);
        }
        rval = http_send_reply(hc, 0, "text/ascii", NULL, NULL, 0, &out);
        break;

    default:
        rval = HTTP_STATUS_METHOD_NOT_ALLOWED;
        break;
    }

    prop_ref_dec(p);

    return rval;
}
示例#2
0
static void
news_sink(void *opaque, prop_event_t event, ...)
{
  prop_t *p = opaque;
  event_t *e;
  va_list ap;

  va_start(ap, event);

  switch(event) {
  case PROP_DESTROYED:
    prop_unsubscribe(va_arg(ap, prop_sub_t *));
    prop_ref_dec(p);
    break;

  case PROP_EXT_EVENT:
    e = va_arg(ap, event_t *);
    if(event_is_type(e, EVENT_DYNAMIC_ACTION)) {
      const event_payload_t *ep = (const event_payload_t *)e;
      if(!strcmp(ep->payload, "dismiss")) {
	rstr_t *id = prop_get_string(p, "id", NULL);
	dismis_news(rstr_get(id));
	rstr_release(id);
	prop_destroy(opaque);
      }
    }
    break;

  default:
    break;
  }
  va_end(ap);
}
示例#3
0
static void
notifications_update(void *opaque, prop_event_t event, ...)
{
  statusbar_t *sb = opaque;
  prop_t *p, *txt;
  statusbar_entry_t *sbe;
  char *buf;
  rstr_t *msg;
  int i, l;
  va_list ap;
  va_start(ap, event);

  switch(event) {
  case PROP_ADD_CHILD:
    p = va_arg(ap, prop_t *);

    txt = prop_get_by_name(PNVEC("self", "text"), 1,
			   PROP_TAG_NAMED_ROOT, p, "self",
			   NULL);
    if(txt != NULL) {
      msg = prop_get_string(txt);

      if(msg != NULL) {
	buf = mystrdupa(rstr_get(msg));
	l = strlen(buf);
	for(i = 0; i < l; i++)
	  if(buf[i] < ' ')
	    buf[i] = ' ';

	sbe = calloc(1, sizeof(statusbar_entry_t));
	sbe->p = prop_ref_inc(p);
	sbe->id = gtk_statusbar_push(GTK_STATUSBAR(sb->bar), sb->ctxid, buf);
	LIST_INSERT_HEAD(&sb->entries, sbe, link);
	rstr_release(msg);
      }
      prop_ref_dec(txt);
    }
    break;

  case PROP_DEL_CHILD:
    p = va_arg(ap, prop_t *);

    LIST_FOREACH(sbe, &sb->entries, link)
      if(sbe->p == p)
	break;

    if(sbe == NULL)
      break;

    prop_ref_dec(sbe->p);
    gtk_statusbar_remove(GTK_STATUSBAR(sb->bar), sb->ctxid, sbe->id);
    LIST_REMOVE(sbe, link);
    free(sbe);
    break;

  default:
    break;
  }
}
示例#4
0
文件: scevents.c 项目: BPaden/garglk
/*
 * evt_handle_preftime_notifications()
 *
 * Print messages and handle resources for the event where we're in mid-event
 * and getting close to some number of turns from its end.
 */
static void
evt_handle_preftime_notifications (sc_gameref_t game, sc_int event)
{
  const sc_filterref_t filter = gs_get_filter (game);
  const sc_prop_setref_t bundle = gs_get_bundle (game);
  sc_vartype_t vt_key[4];
  sc_int preftime1, preftime2;
  const sc_char *preftext;

  vt_key[0].string = "Events";
  vt_key[1].integer = event;

  vt_key[2].string = "PrefTime1";
  preftime1 = prop_get_integer (bundle, "I<-sis", vt_key);
  if (preftime1 == gs_event_time (game, event))
    {
      vt_key[2].string = "PrefText1";
      preftext = prop_get_string (bundle, "S<-sis", vt_key);
      if (!sc_strempty (preftext))
        {
          pf_buffer_string (filter, preftext);
          pf_buffer_character (filter, '\n');
        }

      vt_key[2].string = "Res";
      vt_key[3].integer = 2;
      res_handle_resource (game, "sisi", vt_key);
    }

  vt_key[2].string = "PrefTime2";
  preftime2 = prop_get_integer (bundle, "I<-sis", vt_key);
  if (preftime2 == gs_event_time (game, event))
    {
      vt_key[2].string = "PrefText2";
      preftext = prop_get_string (bundle, "S<-sis", vt_key);
      if (!sc_strempty (preftext))
        {
          pf_buffer_string (filter, preftext);
          pf_buffer_character (filter, '\n');
        }

      vt_key[2].string = "Res";
      vt_key[3].integer = 3;
      res_handle_resource (game, "sisi", vt_key);
    }
}
示例#5
0
文件: connman.c 项目: Ezio-PS/movian
static void
input_req_event(void *opaque, event_t *e)
{
  connman_service_t *cs = opaque;
  if(cs->cs_input_req_inv == NULL)
    return;

  if(event_is_action(e, ACTION_OK)) {

    rstr_t *username = prop_get_string(cs->cs_input_req_prop, "username", NULL);
    rstr_t *password = prop_get_string(cs->cs_input_req_prop, "password", NULL);

    GVariant *result;
    GVariantBuilder *builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));

    g_variant_builder_add(builder, "{sv}", "Passphrase",
			  g_variant_new_string(rstr_get(password)));

    if(cs->cs_input_req_want_identity)
      g_variant_builder_add(builder, "{sv}", "Identity",
			    g_variant_new_string(rstr_get(username)));

    result = g_variant_new("(a{sv})", builder);

    TRACE(TRACE_DEBUG, "CONNMAN", "Auth response: %s",
	  g_variant_print(result, TRUE));

    g_dbus_method_invocation_return_value(cs->cs_input_req_inv, result);

    g_variant_builder_unref(builder);
    rstr_release(username);
    rstr_release(password);
    connman_stop_input_request(cs);
  }

  if(event_is_action(e, ACTION_CANCEL)) {
    g_dbus_method_invocation_return_dbus_error(cs->cs_input_req_inv,
					       "net.connman.Agent.Error.Canceled",
					       "Canceled by user");
    connman_stop_input_request(cs);
  }

}
示例#6
0
文件: scevents.c 项目: BPaden/garglk
/*
 * evt_start_event()
 *
 * Change an event from WAITING to RUNNING.
 */
static void
evt_start_event (sc_gameref_t game, sc_int event)
{
  const sc_filterref_t filter = gs_get_filter (game);
  const sc_prop_setref_t bundle = gs_get_bundle (game);
  sc_vartype_t vt_key[4];
  sc_int time1, time2, obj1, obj1dest;

  if (evt_trace)
    sc_trace ("Event: starting event %ld\n", event);

  /* If event is visible, print its start text. */
  if (evt_can_see_event (game, event))
    {
      const sc_char *starttext;

      /* Get and print start text. */
      vt_key[0].string = "Events";
      vt_key[1].integer = event;
      vt_key[2].string = "StartText";
      starttext = prop_get_string (bundle, "S<-sis", vt_key);
      if (!sc_strempty (starttext))
        {
          pf_buffer_string (filter, starttext);
          pf_buffer_character (filter, '\n');
        }

      /* Handle any associated resource. */
      vt_key[2].string = "Res";
      vt_key[3].integer = 0;
      res_handle_resource (game, "sisi", vt_key);
    }

  /* Move event object to destination. */
  vt_key[0].string = "Events";
  vt_key[1].integer = event;
  vt_key[2].string = "Obj1";
  obj1 = prop_get_integer (bundle, "I<-sis", vt_key) - 1;
  vt_key[2].string = "Obj1Dest";
  obj1dest = prop_get_integer (bundle, "I<-sis", vt_key) - 1;
  evt_move_object (game, obj1, obj1dest);

  /* Set the event's state and time. */
  gs_set_event_state (game, event, ES_RUNNING);

  vt_key[2].string = "Time1";
  time1 = prop_get_integer (bundle, "I<-sis", vt_key);
  vt_key[2].string = "Time2";
  time2 = prop_get_integer (bundle, "I<-sis", vt_key);
  gs_set_event_time (game, event, sc_randomint (time1, time2));

  if (evt_trace)
    sc_trace ("Event: start event handling done, %ld\n", event);
}
示例#7
0
int
text_dialog_kbrd(const char *message, char** answer, int flags)
{
  htsmsg_t *m;
  rstr_t *r;

  prop_t *p = prop_create_root(NULL);

  prop_set_string(prop_create(p, "type"), "textDialogKbrd");
  prop_set_string_ex(prop_create(p, "message"), NULL, message,
		     flags & MESSAGE_POPUP_RICH_TEXT ?
		     PROP_STR_RICH : PROP_STR_UTF8);
  prop_t *string = prop_create(p, "input");
  if(flags & MESSAGE_POPUP_CANCEL)
    prop_set_int(prop_create(p, "cancel"), 1);
  if(flags & MESSAGE_POPUP_OK)
    prop_set_int(prop_create(p, "ok"), 1);
  
  event_t *e = popup_display_kbrd(p, string);
  if (event_is_action(e, ACTION_OK))
  {
    m = htsmsg_create_map();  
      
    r = prop_get_string(string);
    htsmsg_add_str(m, "input", r ? rstr_get(r) : "");
    rstr_release(r);
      
    htsmsg_get_str(m, "input");
    
    setstr(answer, m, "input");
  }
  
  prop_destroy(p);
  
  if(event_is_action(e, ACTION_CANCEL)){
      event_release(e);
      return -1;
  } 

  event_release(e);
  
  return 0;
}
示例#8
0
int
text_dialog(const char *message, char **answer, int flags)
{
  rstr_t *r;
  *answer = NULL;
  prop_t *p = prop_ref_inc(prop_create_root(NULL));

  prop_set_string(prop_create(p, "type"), "textDialog");
  prop_set_string_ex(prop_create(p, "message"), NULL, message,
		     flags & MESSAGE_POPUP_RICH_TEXT ?
		     PROP_STR_RICH : PROP_STR_UTF8);
  prop_t *string = prop_create(p, "input");
  if(flags & MESSAGE_POPUP_CANCEL)
    prop_set_int(prop_create(p, "cancel"), 1);
  if(flags & MESSAGE_POPUP_OK)
    prop_set_int(prop_create(p, "ok"), 1);
  
  event_t *e = popup_display(p);
  
  if(event_is_action(e, ACTION_OK)) {
    r = prop_get_string(string, NULL);

    if(r)
      *answer = strdup(rstr_get(r));
    rstr_release(r);
  }
  
  prop_destroy(p);
  prop_ref_dec(p);
  if(event_is_action(e, ACTION_CANCEL)) {
    event_release(e);
    return -1;
  } 

  event_release(e);
  
  return 0;
}
示例#9
0
static void
popups_update(void *opaque, prop_event_t event, ...)
{
  gtk_ui_t *gu = opaque;
  prop_t *p;
  rstr_t *str;
  popup_t *pop;
  va_list ap;
  va_start(ap, event);

  switch(event) {
  case PROP_ADD_CHILD:
    p = va_arg(ap, prop_t *);

    if((str = prop_get_string(p, "type", NULL)) != NULL) {
      if(!strcmp(rstr_get(str), "auth"))
	popup_create_auth(gu, p);
      rstr_release(str);
    }
    break;

  case PROP_DEL_CHILD:
    p = va_arg(ap, prop_t *);

    LIST_FOREACH(pop, &gu->popups, link)
      if(pop->p == p)
	break;

    if(pop != NULL)
      popup_destroy(pop);
    break;

  default:
    break;
  }
}
示例#10
0
文件: sclocale.c 项目: BPaden/garglk
/*
 * loc_detect_game_locale()
 *
 * Set an autodetected value for the locale based on looking at a game's
 * compilation date.
 */
void
loc_detect_game_locale (sc_prop_setref_t bundle)
{
  assert (bundle);

  /* If an explicit locale has already been set, ignore the call. */
  if (loc_is_autodetect_enabled)
    {
      sc_vartype_t vt_key[1];
      const sc_char *compile_date;
      const sc_locale_t *matched;

      /* Read the game's compilation date from the properties. */
      vt_key[0].string = "CompileDate";
      compile_date = prop_get_string (bundle, "S<-s", vt_key);

      /* Search for a matching locale based on the game compilation date. */
      matched = loc_find_matching_locale (compile_date, AVAILABLE_LOCALES);

      /* If a locale matched, set the global locale to it. */
      if (matched)
        loc_locale = matched;
    }
}
示例#11
0
文件: scresour.c 项目: JohnW71/garglk
/*
 * res_handle_resource()
 *
 * General helper for handling graphics and sound resources.  Supplied with a
 * partial key to the node containing resources, it identifies what resource
 * is appropriate, and sets this as the requested resource in the game, for
 * later use on sync'ing, using the handler appropriate for the game version.
 *
 * The partial format is something like "sis" (the bit to follow I<- or S<-
 * in prop_get), and the partial key is guaranteed to contain at least
 * strlen(partial_format) elements.
 */
void
res_handle_resource (sc_gameref_t game,
                     const sc_char *partial_format,
                     const sc_vartype_t vt_partial[])
{
    const sc_prop_setref_t bundle = gs_get_bundle (game);
    sc_vartype_t vt_key[2], *vt_full;
    sc_int partial_length, resource_start_offset;
    sc_bool embedded;
    sc_char *format;
    assert (gs_is_game_valid (game));
    assert (partial_format && vt_partial);

    /*
     * Check for resources.  If this game doesn't use any, exit now to avoid the
     * overhead of pointless lookups and allocations.
     */
    if (!(res_has_sound (game) || res_has_graphics (game)))
        return;

    /*
     * Get the global offset for all resources.  For version 3.9 games this
     * should be zero.  For version 4.0 games, it's the start of resource data
     * in the TAF file where resources are embedded.
     */
    vt_key[0].string = "ResourceOffset";
    resource_start_offset = prop_get_integer (bundle, "I<-s", vt_key);

    /*
     * Get the flag that indicated embedded resources.  For version 3.9 games
     * this should be false.  If not set, offset and length are forced to zero
     * for interface functions.
     */
    vt_key[0].string = "Globals";
    vt_key[1].string = "Embedded";
    embedded = prop_get_boolean (bundle, "B<-ss", vt_key);

    /*
     * Allocate a format for use with properties calls, five characters longer
     * than the partial passed in.  Build a key one element larger than the
     * partial supplied, and copy over all supplied elements.
     */
    partial_length = strlen (partial_format);
    format = sc_malloc (partial_length + 5);

    vt_full = sc_malloc ((partial_length + 1) * sizeof (vt_partial[0]));
    memcpy (vt_full, vt_partial, partial_length * sizeof (vt_partial[0]));

    /* Search for sound resources, and offer if found. */
    if (res_has_sound (game))
    {
        const sc_char *soundfile;
        sc_int soundoffset, soundlen;

        /* Get soundfile property from the node supplied. */
        vt_full[partial_length].string = "SoundFile";
        strcpy (format, "S<-");
        strcat (format, partial_format);
        strcat (format, "s");
        soundfile = prop_get_string (bundle, format, vt_full);

        /* If a sound is defined, handle it. */
        if (!sc_strempty (soundfile))
        {
            if (embedded)
            {
                /* Retrieve offset and length. */
                vt_full[partial_length].string = "SoundOffset";
                strcpy (format, "I<-");
                strcat (format, partial_format);
                strcat (format, "s");
                soundoffset = prop_get_integer (bundle, format, vt_full)
                              + resource_start_offset;

                vt_full[partial_length].string = "SoundLen";
                strcpy (format, "I<-");
                strcat (format, partial_format);
                strcat (format, "s");
                soundlen = prop_get_integer (bundle, format, vt_full);
            }
            else
            {
                /* Coerce offset and length to zero. */
                soundoffset = 0;
                soundlen = 0;
            }

            /*
             * If the sound is the special "##", latch stop, otherwise note
             * details to play on sync.
             */
            if (!strcmp (soundfile, "##"))
            {
                game->stop_sound = TRUE;
                res_clear_resource (&game->requested_sound);
            }
            else
            {
                res_set_resource (&game->requested_sound,
                                  soundfile, soundoffset, soundlen);
            }
        }
    }

    /* Now do the same thing for graphics resources. */
    if (res_has_graphics (game))
    {
        const sc_char *graphicfile;
        sc_int graphicoffset, graphiclen;

        /* Get graphicfile property from the node supplied. */
        vt_full[partial_length].string = "GraphicFile";
        strcpy (format, "S<-");
        strcat (format, partial_format);
        strcat (format, "s");
        graphicfile = prop_get_string (bundle, format, vt_full);

        /* If a graphic is defined, handle it. */
        if (!sc_strempty (graphicfile))
        {
            if (embedded)
            {
                /* Retrieve offset and length. */
                vt_full[partial_length].string = "GraphicOffset";
                strcpy (format, "I<-");
                strcat (format, partial_format);
                strcat (format, "s");
                graphicoffset = prop_get_integer (bundle, format, vt_full)
                                + resource_start_offset;

                vt_full[partial_length].string = "GraphicLen";
                strcpy (format, "I<-");
                strcat (format, partial_format);
                strcat (format, "s");
                graphiclen = prop_get_integer (bundle, format, vt_full);
            }
            else
            {
                /* Coerce offset and length to zero. */
                graphicoffset = 0;
                graphiclen = 0;
            }

            /* Graphics resource retrieved, note to show on sync. */
            res_set_resource (&game->requested_graphic,
                              graphicfile, graphicoffset, graphiclen);
        }
    }

    /* Free allocated memory. */
    sc_free (format);
    sc_free (vt_full);
}
示例#12
0
event_t *
popup_display_kbrd(prop_t *p, prop_t *string)
{
  prop_courier_t *pc = prop_courier_create_waitable();
  event_t *e = NULL;

  prop_t *r = prop_create(p, "eventSink");
  prop_sub_t *s = prop_subscribe(0, 
				 PROP_TAG_CALLBACK, eventsink, &e, 
				 PROP_TAG_ROOT, r,
				 PROP_TAG_COURIER, pc,
				 NULL);

  /* Will show the popup */
  if(prop_set_parent(p, prop_create(prop_get_global(), "popups"))) {
    /* popuproot is a zombie, this is an error */
    abort();
  }

  while (e == NULL || (!event_is_action(e, ACTION_OK) && !event_is_action(e, ACTION_CANCEL)))
  {
    while(e == NULL)
      prop_courier_wait_and_dispatch(pc);
    if (!event_is_action(e, ACTION_OK) && !event_is_action(e, ACTION_CANCEL))
    {
      char *tmpInput;
      htsmsg_t *m;
      rstr_t *r;
      m = htsmsg_create_map();  
      
      r = prop_get_string(string);
      htsmsg_add_str(m, "input", r ? rstr_get(r) : "");
      rstr_release(r);
      htsmsg_get_str(m, "input");
    
      setstr(&tmpInput, m, "input");
      if (event_is_action(e, ACTION_KBRD_A))
        strcat(tmpInput, "a");
      else if (event_is_action(e, ACTION_KBRD_B))
        strcat(tmpInput, "b");
      else if (event_is_action(e, ACTION_KBRD_C))
        strcat(tmpInput, "c");
      else if (event_is_action(e, ACTION_KBRD_D))
        strcat(tmpInput, "d");
      else if (event_is_action(e, ACTION_KBRD_E))
        strcat(tmpInput, "e");
      else if (event_is_action(e, ACTION_KBRD_F))
        strcat(tmpInput, "f");
      else if (event_is_action(e, ACTION_KBRD_G))
        strcat(tmpInput, "g");
      else if (event_is_action(e, ACTION_KBRD_H))
        strcat(tmpInput, "h");
      else if (event_is_action(e, ACTION_KBRD_I))
        strcat(tmpInput, "i");
      else if (event_is_action(e, ACTION_KBRD_J))
        strcat(tmpInput, "j");
      else if (event_is_action(e, ACTION_KBRD_K))
        strcat(tmpInput, "k");
      else if (event_is_action(e, ACTION_KBRD_L))
        strcat(tmpInput, "l");
      else if (event_is_action(e, ACTION_KBRD_M))
        strcat(tmpInput, "m");
      else if (event_is_action(e, ACTION_KBRD_N))
        strcat(tmpInput, "n");
      else if (event_is_action(e, ACTION_KBRD_O))
        strcat(tmpInput, "o");
      else if (event_is_action(e, ACTION_KBRD_P))
        strcat(tmpInput, "p");
      else if (event_is_action(e, ACTION_KBRD_Q))
        strcat(tmpInput, "q");
      else if (event_is_action(e, ACTION_KBRD_R))
        strcat(tmpInput, "r");
      else if (event_is_action(e, ACTION_KBRD_S))
        strcat(tmpInput, "s");
      else if (event_is_action(e, ACTION_KBRD_T))
        strcat(tmpInput, "t");
      else if (event_is_action(e, ACTION_KBRD_U))
        strcat(tmpInput, "u");
      else if (event_is_action(e, ACTION_KBRD_V))
        strcat(tmpInput, "v");
      else if (event_is_action(e, ACTION_KBRD_W))
        strcat(tmpInput, "w");
      else if (event_is_action(e, ACTION_KBRD_X))
        strcat(tmpInput, "x");
      else if (event_is_action(e, ACTION_KBRD_Y))
        strcat(tmpInput, "y");
      else if (event_is_action(e, ACTION_KBRD_Z))
        strcat(tmpInput, "z");
      else if (event_is_action(e, ACTION_KBRD_0))
        strcat(tmpInput, "0");
      else if (event_is_action(e, ACTION_KBRD_1))
        strcat(tmpInput, "1");
      else if (event_is_action(e, ACTION_KBRD_2))
        strcat(tmpInput, "2");
      else if (event_is_action(e, ACTION_KBRD_3))
        strcat(tmpInput, "3");
      else if (event_is_action(e, ACTION_KBRD_4))
        strcat(tmpInput, "4");
      else if (event_is_action(e, ACTION_KBRD_5))
        strcat(tmpInput, "5");
      else if (event_is_action(e, ACTION_KBRD_6))
        strcat(tmpInput, "6");
      else if (event_is_action(e, ACTION_KBRD_7))
        strcat(tmpInput, "7");
      else if (event_is_action(e, ACTION_KBRD_8))
        strcat(tmpInput, "8");
      else if (event_is_action(e, ACTION_KBRD_9))
        strcat(tmpInput, "9");
      else if (event_is_action(e, ACTION_KBRD_COMMA))
        strcat(tmpInput, ",");
      else if (event_is_action(e, ACTION_KBRD_DOT))
        strcat(tmpInput, ".");
      else if (event_is_action(e, ACTION_KBRD_SPACE))
        strcat(tmpInput, " ");
      else if (event_is_action(e, ACTION_BS))
      {
        if (strlen(tmpInput) > 0)
        {
          strncpy(tmpInput, tmpInput, strlen(tmpInput) - 1);
	  tmpInput[strlen(tmpInput) - 1] = '\0';
        }
      }
      prop_set_string(string, tmpInput);
      e = NULL;
    }
  }
  prop_unsubscribe(s);
  return e;
}
示例#13
0
int
keyring_lookup(const char *id, char **username, char **password,
	       char **domain, int *remember_me, const char *source,
	       const char *reason, int flags)
{
  htsmsg_t *m;
  rstr_t *r;
  int remember = !!(flags & KEYRING_REMEMBER_ME_SET);

  hts_mutex_lock(&keyring_mutex);

  if(flags & KEYRING_QUERY_USER) {
    htsmsg_t *parent;
    prop_t *p = prop_create_root(NULL);

    prop_set_string(prop_create(p, "type"), "auth");
    prop_set_string(prop_create(p, "id"), id);
    prop_set_string(prop_create(p, "source"), source);
    prop_set_string(prop_create(p, "reason"), reason);
    prop_set_int(prop_create(p, "disableUsername"), username == NULL);


    prop_set_int(prop_create(p, "canRemember"),
		 !!(flags & KEYRING_SHOW_REMEMBER_ME));
    prop_t *rememberMe = prop_create(p, "rememberMe");
    prop_set_int(rememberMe, remember);

    prop_sub_t *remember_sub = 
	prop_subscribe(0,
		   PROP_TAG_CALLBACK_INT, set_remember, &remember,
		   PROP_TAG_ROOT, rememberMe,
		   NULL);

    prop_t *user = prop_create(p, "username");
    prop_t *pass = prop_create(p, "password");
 
    TRACE(TRACE_INFO, "keyring", "Requesting credentials for %s : %s : %s",
	  id, source, reason);


    event_t *e = popup_display(p);

    prop_unsubscribe(remember_sub);

    if(flags & KEYRING_ONE_SHOT)
      parent = NULL;
    else if(remember)
      parent = persistent_keyring;
    else
      parent = temporary_keyring;

    if(parent != NULL)
      htsmsg_delete_field(parent, id);

    if(event_is_action(e, ACTION_OK)) {
      /* OK */

      m = htsmsg_create_map();

      if(username != NULL) {
	r = prop_get_string(user);
	htsmsg_add_str(m, "username", r ? rstr_get(r) : "");
	*username = strdup(r ? rstr_get(r) : "");
	rstr_release(r);
      }

      r = prop_get_string(pass);
      htsmsg_add_str(m, "password", r ? rstr_get(r) : "");
      *password = strdup(r ? rstr_get(r) : "");
      rstr_release(r);

      if(parent != NULL) {
	htsmsg_add_msg(parent, id, m);

	if(parent == persistent_keyring)
	  keyring_store();
      }

    } else {
      /* CANCEL */
      if(parent == persistent_keyring)
	keyring_store();
    }

    if(remember_me != NULL)
      *remember_me = remember;

    prop_destroy(p);

    if(event_is_action(e, ACTION_CANCEL)) {
      /* return CANCEL to caller */
      hts_mutex_unlock(&keyring_mutex);
      event_release(e);
      return -1;
    }
    event_release(e);

  } else {

    if((m = htsmsg_get_map(temporary_keyring, id)) == NULL &&
       (m = htsmsg_get_map(persistent_keyring, id)) == NULL) {
      hts_mutex_unlock(&keyring_mutex);
      return 1;
    }
    
    setstr(username, m, "username");
    setstr(password, m, "password");
    setstr(domain, m, "domain");
  }

  hts_mutex_unlock(&keyring_mutex);
  return 0;
}
示例#14
0
文件: keyring.c 项目: Hr-/showtime
int
keyring_lookup(const char *id, char **username, char **password,
	       char **domain, int query, const char *source,
	       const char *reason, int force_temporary)
{
  htsmsg_t *m;
  rstr_t *r;


  hts_mutex_lock(&keyring_mutex);

  if(query) {
    htsmsg_t *parent;
    prop_t *p = prop_create_root(NULL);

    prop_set_string(prop_create(p, "type"), "auth");
    prop_set_string(prop_create(p, "id"), id);
    prop_set_string(prop_create(p, "source"), source);
    prop_set_string(prop_create(p, "reason"), reason);

    int remember = !force_temporary;
    prop_set_int(prop_create(p, "canRemember"), remember);
    prop_t *rememberMe = prop_create(p, "rememberMe");
    prop_set_int(rememberMe, remember);

    prop_sub_t *remember_sub = 
	prop_subscribe(0,
		   PROP_TAG_CALLBACK_INT, set_remember, &remember,
		   PROP_TAG_ROOT, rememberMe,
		   NULL);

    prop_t *user = prop_create(p, "username");
    prop_t *pass = prop_create(p, "password");
 
    TRACE(TRACE_INFO, "keyring", "Requesting credentials for %s : %s : %s",
	  id, source, reason);


    event_t *e = popup_display(p);

    prop_unsubscribe(remember_sub);

    if(remember)
      parent = persistent_keyring;
    else
      parent = temporary_keyring;

    htsmsg_delete_field(parent, id);

    if(event_is_action(e, ACTION_OK)) {
      /* OK */

      m = htsmsg_create_map();

      r = prop_get_string(user);
      htsmsg_add_str(m, "username", r ? rstr_get(r) : "");
      rstr_release(r);

      r = prop_get_string(pass);
      htsmsg_add_str(m, "password", r ? rstr_get(r) : "");
      rstr_release(r);

      htsmsg_add_msg(parent, id, m);

      if(parent == persistent_keyring)
	keyring_store();

    } else {
      /* CANCEL, store without adding anything */
      keyring_store();
    }

    prop_destroy(p);

    if(event_is_action(e, ACTION_CANCEL)) {
      /* return CANCEL to caller */
      hts_mutex_unlock(&keyring_mutex);
      event_release(e);
      return -1;
    }
    event_release(e);
  }

  if((m = htsmsg_get_map(temporary_keyring, id)) == NULL &&
     (m = htsmsg_get_map(persistent_keyring, id)) == NULL) {
    hts_mutex_unlock(&keyring_mutex);
    return 1;
  }

  setstr(username, m, "username");
  setstr(password, m, "password");
  setstr(domain, m, "domain");

  hts_mutex_unlock(&keyring_mutex);
  return 0;
}
示例#15
0
文件: scevents.c 项目: BPaden/garglk
/*
 * evt_finish_event()
 *
 * Move an event to FINISHED, or restart it.
 */
static void
evt_finish_event (sc_gameref_t game, sc_int event)
{
  const sc_filterref_t filter = gs_get_filter (game);
  const sc_prop_setref_t bundle = gs_get_bundle (game);
  sc_vartype_t vt_key[4];
  sc_int obj2, obj2dest, obj3, obj3dest;
  sc_int task, startertype, restarttype;
  sc_bool taskdir;

  if (evt_trace)
    sc_trace ("Event: finishing event %ld\n", event);

  /* Set up invariant parts of the key. */
  vt_key[0].string = "Events";
  vt_key[1].integer = event;

  /* If event is visible, print its finish text. */
  if (evt_can_see_event (game, event))
    {
      const sc_char *finishtext;

      /* Get and print finish text. */
      vt_key[2].string = "FinishText";
      finishtext = prop_get_string (bundle, "S<-sis", vt_key);
      if (!sc_strempty (finishtext))
        {
          pf_buffer_string (filter, finishtext);
          pf_buffer_character (filter, '\n');
        }

      /* Handle any associated resource. */
      vt_key[2].string = "Res";
      vt_key[3].integer = 4;
      res_handle_resource (game, "sisi", vt_key);
    }

  /* Move event objects to destination. */
  vt_key[2].string = "Obj2";
  obj2 = prop_get_integer (bundle, "I<-sis", vt_key) - 1;
  vt_key[2].string = "Obj2Dest";
  obj2dest = prop_get_integer (bundle, "I<-sis", vt_key) - 1;
  evt_move_object (game, obj2, obj2dest);

  vt_key[2].string = "Obj3";
  obj3 = prop_get_integer (bundle, "I<-sis", vt_key) - 1;
  vt_key[2].string = "Obj3Dest";
  obj3dest = prop_get_integer (bundle, "I<-sis", vt_key) - 1;
  evt_move_object (game, obj3, obj3dest);

  /* See if there is an affected task. */
  vt_key[2].string = "TaskAffected";
  task = prop_get_integer (bundle, "I<-sis", vt_key) - 1;
  if (task >= 0)
    {
      vt_key[2].string = "TaskFinished";
      taskdir = !prop_get_boolean (bundle, "B<-sis", vt_key);
      if (task_can_run_task_directional (game, task, taskdir))
        {
          if (evt_trace)
            {
              sc_trace ("Event: event running task %ld, %s\n",
                        task, taskdir ? "forwards" : "backwards");
            }

          task_run_task (game, task, taskdir);
        }
      else
        {
          if (evt_trace)
            sc_trace ("Event: event can't run task %ld\n", task);
        }
    }

  /* Handle possible restart. */
  vt_key[2].string = "RestartType";
  restarttype = prop_get_integer (bundle, "I<-sis", vt_key);
  switch (restarttype)
    {
    case 0:                    /* Don't restart. */
      startertype = evt_get_starter_type (game, event);
      switch (startertype)
        {
        case 1:                /* Immediate. */
        case 2:                /* Random delay. */
        case 3:                /* After task. */
          gs_set_event_state (game, event, ES_FINISHED);
          gs_set_event_time (game, event, 0);
          break;

        default:
          sc_fatal ("evt_finish_event:"
                    " unknown value for starter type, %ld\n", startertype);
        }
      break;

    case 1:                    /* Restart immediately. */
      if (evt_fixup_v390_v380_immediate_restart (game, event))
        break;
      else
        evt_start_event (game, event);
      break;

    case 2:                    /* Restart after delay. */
      startertype = evt_get_starter_type (game, event);
      switch (startertype)
        {
        case 1:                /* Immediate. */
          if (evt_fixup_v390_v380_immediate_restart (game, event))
            break;
          else
            evt_start_event (game, event);
          break;

        case 2:                /* Random delay. */
          {
            sc_int start, end;

            gs_set_event_state (game, event, ES_WAITING);
            vt_key[2].string = "StartTime";
            start = prop_get_integer (bundle, "I<-sis", vt_key);
            vt_key[2].string = "EndTime";
            end = prop_get_integer (bundle, "I<-sis", vt_key);
            gs_set_event_time (game, event, sc_randomint (start, end));
            break;
          }

        case 3:                /* After task. */
          gs_set_event_state (game, event, ES_AWAITING);
          gs_set_event_time (game, event, 0);
          break;

        default:
          sc_fatal ("evt_finish_event: unknown StarterType\n");
        }
      break;

    default:
      sc_fatal ("evt_finish_event: unknown RestartType\n");
    }

  if (evt_trace)
    sc_trace ("Event: finish event handling done, %ld\n", event);
}
示例#16
0
static int
hc_prop(http_connection_t *hc, const char *remain, void *opaque,
	http_cmd_t method)
{
  htsbuf_queue_t out;
  rstr_t *r;
  int rval, i;
  prop_t *p = NULL;
  char *req = (char *)http_arg_get_req(hc, "requests");
  char *request;
  char *saved;

  if(req == NULL)
    return 404;

  htsbuf_queue_init(&out, 0);

  switch(method) {
  case HTTP_CMD_POST:
    for (request = strtok_r(req, ",", &saved);
         request;
         request = strtok_r(NULL, ",", &saved))
    {
      p = prop_from_path(request);
      if (p == NULL) {
        htsbuf_qprintf(&out, "error:404");
      }
      else {
        r = prop_get_string(p, NULL);

        if(r == NULL) {

          char **childs = prop_get_name_of_childs(p);
          if(childs == NULL) {
            htsbuf_qprintf(&out, "error:404");
          }
          else {
            htsbuf_qprintf(&out, "dir");
            for(i = 0; childs[i] != NULL; i++) {
	      htsbuf_qprintf(&out, "%c%s", i ? ',' : ':', childs[i]);
            }
          }
        } else {
          htsbuf_qprintf(&out, "value:");
          htsbuf_append(&out, rstr_get(r), strlen(rstr_get(r)));
          rstr_release(r);
        }
      }
      htsbuf_append(&out, "\n", 1);
    }
    rval = http_send_reply(hc, 0, "text/ascii", NULL, NULL, 0, &out);
    break;

  default:
    rval = HTTP_STATUS_METHOD_NOT_ALLOWED;
    break;
  }

  prop_ref_dec(p);

  return rval;
}