Пример #1
0
int message_serialize_error_response(msgpack_packer *pk,
    struct api_error *api_error, uint32_t msgid)
{
  struct message_object *err_data;
  array err_array;

  if (!pk || !api_error || !api_error->isset)
    return (-1);

  msgpack_pack_array(pk, 4);

  pack_uint8(pk, MESSAGE_TYPE_RESPONSE);
  pack_uint32(pk, msgid);

  err_array.size = 2;
  err_array.obj = CALLOC(2, struct message_object);

  if (!err_array.obj) {
    LOG_WARNING("Couldn't allocate memory for err_array object");
    return (-1);
  }

  err_data = &err_array.obj[0];
  err_data->type = OBJECT_TYPE_INT;
  err_data->data.integer = api_error->type;

  err_data = &err_array.obj[1];
  err_data->type = OBJECT_TYPE_STR;
  err_data->data.string = cstring_to_string(api_error->msg);

  if (!err_data->data.string.str) {
    LOG_WARNING("Couldn't allocate memory for string in err_array object");
    return (-1);
  }

  if (pack_params(pk, err_array) == -1)
    return (-1);

  pack_nil(pk);

  FREE(err_array.obj);

  return (0);
}
Пример #2
0
void optparser(int argc, char **argv)
{
  verbose_level = VERBOSE_OFF;
  int option_index = 0;
  int c;

  string name = cstring_to_string(argv[0]);

  struct option long_options[] = {
    {"help", no_argument, 0, 'h'},
    {"version", no_argument, 0, 'V'},
    {0, 0, 0, 0}
  };

  while (1){
    c = getopt_long(argc, argv, "hvV", long_options, &option_index);

    if (c == -1)
      break;

    switch (c){

    case 'h':
      print_usage(name);
      exit(0);
    case 'V':
      print_version();
      exit(0);
    case 'v':
      verbose_level++;
      break;
    default:
      LOG_ERROR("Illegal option passed.\n");
      print_usage(name);
      abort();
    }
  }

}
Пример #3
0
int
litsig_text_tool(struct pine *ps, int cmd, CONF_S **cl, unsigned int flags)
{
    char           **apval;
    int		     rv = 0;

    if(cmd != MC_EXIT && fixed_var((*cl)->var, NULL, NULL))
      return(rv);

    apval = APVAL((*cl)->var, ew);

    switch(cmd){
      case MC_ADD:
      case MC_EDIT :
	if(apval){
	    char *input = NULL, *result = NULL, *err = NULL, *cstring_version;
	    char *olddefval = NULL, *start_with;
	    size_t len;

	    if(!*apval && (*cl)->var->current_val.p &&
	       (*cl)->var->current_val.p[0]){
		if(!strncmp((*cl)->var->current_val.p,
			    DSTRING,
			    (len=strlen(DSTRING)))){
		    /* strip DSTRING and trailing paren */
		    olddefval = (char *)fs_get(strlen((*cl)->var->current_val.p)+1);
		    strncpy(olddefval, (*cl)->var->current_val.p+len,
			    strlen((*cl)->var->current_val.p)-len-1);
		    olddefval[strlen((*cl)->var->current_val.p)-len-1] = '\0';
		    start_with = olddefval;
		}
		else{
		    olddefval = cpystr((*cl)->var->current_val.p);
		    start_with = olddefval;
		}
	    }
	    else
	      start_with = (*apval) ? *apval : "";

	    input = (char *)fs_get((strlen(start_with)+1) * sizeof(char));
	    input[0] = '\0';
	    cstring_to_string(start_with, input);
	    err = signature_edit_lit(input, &result,
				     ((*cl)->var == role_comment_ptr)
					 ? "COMMENT EDITOR"
					 : "SIGNATURE EDITOR",
				     ((*cl)->var == role_comment_ptr)
					 ? h_composer_commentedit
					 : h_composer_sigedit);

	    if(!err){
		if(olddefval && !strcmp(input, result) &&
		   want_to(_("Leave unset and use default "), 'y',
			   'y', NO_HELP, WT_FLUSH_IN) == 'y'){
		    rv = 0;
		}
		else{
		    cstring_version = string_to_cstring(result);

		    if(apval && *apval)
		      fs_give((void **)apval);
		    
		    if(apval){
			*apval = cstring_version;
			cstring_version = NULL;
		    }

		    if(cstring_version)
		      fs_give((void **)&cstring_version);

		    rv = 1;
		}
	    }
	    else
	      rv = 0;

	    if(err){
		q_status_message1(SM_ORDER, 3, 5, "%s", err);
		fs_give((void **)&err);
	    }

	    if(result)
	      fs_give((void **)&result);
	    if(olddefval)
	      fs_give((void **)&olddefval);
	    if(input)
	      fs_give((void **)&input);
	}

	ps->mangled_screen = 1;
	break;
	
      default:
	rv = text_tool(ps, cmd, cl, flags);
	break;
    }

    /*
     * At this point, if changes occurred, var->user_val.X is set.
     * So, fix the current_val, and handle special cases...
     *
     * NOTE: we don't worry about the "fixed variable" case here, because
     *       editing such vars should have been prevented above...
     */
    if(rv == 1){
	/*
	 * Now go and set the current_val based on user_val changes
	 * above.  Turn off command line settings...
	 */
	set_current_val((*cl)->var, TRUE, FALSE);

	if((*cl)->value)
	  fs_give((void **)&(*cl)->value);

	(*cl)->value = pretty_value(ps, *cl);

	exception_override_warning((*cl)->var);

	/*
	 * The value of literal sig can affect whether signature file is
	 * used or not. So it affects what we display for sig file variable.
	 */
	if((*cl)->next && (*cl)->next->var == &ps->vars[V_SIGNATURE_FILE]){
	    if((*cl)->next->value)
	      fs_give((void **)&(*cl)->next->value);
	    
	    (*cl)->next->value = pretty_value(ps, (*cl)->next);
	}
    }

    return(rv);
}