Ejemplo n.º 1
0
char *python_format_func( json_t *json, char *format, void *template_ptr )
{
  Template *t = (Template *) template_ptr;
  char *value = json_get_string_value( t->mp, json );
  char *ret_val = NULL;
  PyObject *format_func;
  PyObject *arglist;
  PyObject *py_ret;
  PyObject *py_json;

  format_func = apr_hash_get( t->formats, format, APR_HASH_KEY_STRING );

  py_json = PyCObject_FromVoidPtrAndDesc( json, "_p_json_t", NULL );
  arglist = Py_BuildValue( "ssO", value, format, py_json );
  py_ret = PyObject_CallObject( format_func, arglist );

  if ( PyString_CheckExact( py_ret ) ) {
    ret_val = apr_pstrdup( t->mp, PyString_AS_STRING( py_ret ) );
  }

  return ret_val;
}
Ejemplo n.º 2
0
static HRESULT show_dialog(BSTR callback_id, BSTR args)
{
	wchar_t buf[10];
	int ret_code;
	wchar_t* message = 0;
	wchar_t* buttons = 0;
	wchar_t* title = 0;
	int num_buttons = 0;
	wchar_t* btn_text[MAX_BUTTONS];
	int btn_text_len[MAX_BUTTONS];
	unsigned int cursor = 0;

	JsonArray array;
	JsonItem item;

	// args should be like "["message","title","button1,button2"]"

	// Validate array contents
	if (!json_parse_and_validate_args(args, &array, JSON_VALUE_STRING,
									JSON_VALUE_STRING,
									JSON_VALUE_STRING,
									JSON_VALUE_INVALID)) {
		json_free_args(array);
		return -1;
	}

	// message
	item = json_array_get_first(array);
	message = json_get_string_value(item);

	// title
	item = json_array_get_next(item);
	title = json_get_string_value(item);

	// buttons
	item = json_array_get_next(item);
	buttons = json_get_string_value(item);
	if (*buttons == 0)
		goto button_done; // No button ; consider that a valid use case

button_parsing:

	btn_text[num_buttons] = buttons + cursor;
	btn_text_len[num_buttons] = 0;

	// Search for separator
	while (cursor < wcslen(buttons) && *(buttons + cursor) != L',') {
		cursor++;
		btn_text_len[num_buttons]++;
	}

	num_buttons++;

	cursor++;
	
	if (cursor < wcslen(buttons) && num_buttons < MAX_BUTTONS)
		goto button_parsing;

button_done:

	json_free_args(array);

	ret_code = DisplayMessage(title, wcslen(title), message, wcslen(message), btn_text, btn_text_len, num_buttons);

	if (message)
		free(message);
	if (title)
		free(title);
	if (buttons)
		free(buttons);

	wsprintf(buf, L"%d", ret_code);

	cordova_success_callback(callback_id, FALSE, buf);

	return S_OK;
}