Esempio n. 1
0
static void
file_view_show_extended_data (AnjutaFileView* view, GtkTreeIter* iter)
{
	AnjutaFileViewPrivate* priv = ANJUTA_FILE_VIEW_GET_PRIVATE (view);

	GtkTreeModel* file_model = GTK_TREE_MODEL (priv->model);
	gboolean is_dummy, is_dir;
	GFile* file;
	GFileInfo* file_info;
	time_t time;
	gchar* display;
	gchar time_str[128];
	AnjutaVcsStatus status;

	gtk_tree_model_get (file_model, iter, COLUMN_DUMMY, &is_dummy,
	                    COLUMN_IS_DIR, &is_dir, -1);
	if (is_dummy || is_dir)
		return;


	gtk_tree_model_get (file_model, iter, COLUMN_FILE, &file, 
	                    COLUMN_STATUS, &status, -1);

	file_info = g_file_query_info (file,
	                               "standard::*,time::changed",
	                               G_FILE_QUERY_INFO_NONE,
	                               NULL, NULL);
	g_object_unref (file);
	if (!file_info)
		return;

	time = g_file_info_get_attribute_uint64(file_info, "time::changed");
	strftime(time_str, 127, "%x %X", localtime(&time));
	if (get_status_string(status))
	{
		display = g_markup_printf_escaped("%s\n"
		                                  "<small><tt>%s</tt></small>\n"
		                                  "<small>%s</small>",
		                                  g_file_info_get_display_name(file_info),
		                                  time_str,
		                                  get_status_string(status));
	}
	else
	{
		display = g_markup_printf_escaped("%s\n"
		                                  "<small><tt>%s</tt></small>",
		                                  g_file_info_get_display_name(file_info),
		                                  time_str);
	}
	gtk_tree_store_set (GTK_TREE_STORE(file_model), iter,
	                    COLUMN_DISPLAY, display,
	                    -1);

	g_object_unref (file_info);
	g_free(display);
}
Esempio n. 2
0
/* Write a status line with code NO followed by the string TEXT and
   directly followed by the remaining strings up to a NULL. */
void
write_status_strings (int no, const char *text, ...)
{
  va_list arg_ptr;
  const char *s;

  if (!statusfp || !status_currently_allowed (no) )
    return;  /* Not enabled or allowed. */

  fputs ("[GNUPG:] ", statusfp);
  fputs (get_status_string (no), statusfp);
  if ( text )
    {
      putc ( ' ', statusfp);
      va_start (arg_ptr, text);
      s = text;
      do
        {
          for (; *s; s++)
            {
              if (*s == '\n')
                fputs ("\\n", statusfp);
              else if (*s == '\r')
                fputs ("\\r", statusfp);
              else
                fputc (*(const byte *)s, statusfp);
            }
        }
      while ((s = va_arg (arg_ptr, const char*)));
      va_end (arg_ptr);
    }
  putc ('\n', statusfp);
  if (fflush (statusfp) && opt.exit_on_status_write_error)
    g10_exit (0);
}
Esempio n. 3
0
void
write_status_text (int no, const char *text)
{
  if (!statusfp || !status_currently_allowed (no) )
    return;  /* Not enabled or allowed. */

  es_fputs ("[GNUPG:] ", statusfp);
  es_fputs (get_status_string (no), statusfp);
  if ( text )
    {
      es_putc ( ' ', statusfp);
      for (; *text; text++)
        {
          if (*text == '\n')
            es_fputs ("\\n", statusfp);
          else if (*text == '\r')
            es_fputs ("\\r", statusfp);
          else
            es_fputc ( *(const byte *)text, statusfp);
        }
    }
  es_putc ('\n', statusfp);
  if (es_fflush (statusfp) && opt.exit_on_status_write_error)
    g10_exit (0);
}
Esempio n. 4
0
void send_motor_status()
{
	char* sstr;
	sprintf(buff, "Motor Status: \r\n");
	send_message(buff);

	for (int i=0; i<5; i++) {	
		sstr = get_status_string( FiveMotorConfigData.motor_status[i] );
		sprintf(buff, "%c:%s  ", motor_letters[i], sstr);
		send_message(buff);
	}
	strcpy(buff, "\r\n");	
	send_message(buff);

	send_limit_states();
		
	sprintf(buff, "Raw Status: %x %x %x %x %x", 
						FiveMotorConfigData.motor_status[0], 
						FiveMotorConfigData.motor_status[1],
						FiveMotorConfigData.motor_status[2],
						FiveMotorConfigData.motor_status[3],
						FiveMotorConfigData.motor_status[4]  );
	strcat(buff, "\r\n");	
	form_response(buff);
}
Esempio n. 5
0
static void
nvme_qpair_print_completion(struct nvme_qpair *qpair,
			    struct nvme_completion *cpl)
{
	nvme_printf(qpair->ctrlr, "%s (%02x/%02x) sqid:%d cid:%d cdw0:%x sqhd:%04x p:%x m:%x dnr:%x\n",
		    get_status_string(cpl->status.sct, cpl->status.sc),
		    cpl->status.sct, cpl->status.sc, cpl->sqid, cpl->cid, cpl->cdw0,
		    cpl->sqhd, cpl->status.p, cpl->status.m, cpl->status.dnr);
}
Esempio n. 6
0
void
write_status_error (const char *where, int errcode)
{
  if (!statusfp || !status_currently_allowed (STATUS_ERROR))
    return;  /* Not enabled or allowed. */

  fprintf (statusfp, "[GNUPG:] %s %s %u\n",
           get_status_string (STATUS_ERROR), where, gpg_err_code (errcode));
  if (fflush (statusfp) && opt.exit_on_status_write_error)
    g10_exit (0);
}
Esempio n. 7
0
/**
 * Returns a new HttpResponse object wrapping a default response. Use
 * the set_XXX methods to change the object.
 */
static HttpResponse create_HttpResponse(Socket_T S) {
  HttpResponse res= NULL;

  NEW(res);
  res->S= S;
  res->status= SC_OK;
  res->outputbuffer= StringBuffer_create(256);
  res->is_committed= FALSE;
  res->protocol= SERVER_PROTOCOL;
  res->status_msg= get_status_string(SC_OK);
  return res;
}
Esempio n. 8
0
/* Read and return the status from remote tape connection HANDLE.  If
   an error occurred, return -1 and set errno.  */
static long int
get_status (int handle)
{
  char command_buffer[COMMAND_BUFFER_SIZE];
  const char *status = get_status_string (handle, command_buffer);
  if (status)
    {
      long int result = atol (status);
      if (0 <= result)
	return result;
      errno = EIO;
    }
  return -1;
}
Esempio n. 9
0
static void print_test(FILE *f,
                       struct criterion_test_stats *ts,
                       struct criterion_suite_stats *ss) {

    fprintf(f, JSON_TEST_TEMPLATE_BEGIN,
            ts->test->name,
            (size_t) (ts->passed_asserts + ts->failed_asserts),
            get_status_string(ts, ss)
        );

    if (is_disabled(ts->test, ss->suite)) {
        fprintf(f, JSON_SKIPPED_MSG_ENTRY);
    } else if (ts->crashed) {
        fprintf(f, JSON_CRASH_MSG_ENTRY);
    } else if (ts->timed_out) {
        fprintf(f, JSON_TIMEOUT_MSG_ENTRY);
    } else if (ts->failed) {
        fprintf(f, JSON_TEST_FAILED_TEMPLATE_BEGIN);

        bool first = true;
        for (struct criterion_assert_stats *asrt = ts->asserts; asrt; asrt = asrt->next) {
            if (!asrt->passed) {
                if (!first) {
                    fprintf(f, ",\n");
                } else {
                    first = false;
                }

                bool sf = criterion_options.short_filename;
                char *dup = strdup(*asrt->message ? asrt->message : "");
                char *saveptr = NULL;
                char *line = strtok_r(dup, "\n", &saveptr);

                fprintf(f, JSON_FAILURE_MSG_ENTRY,
                        sf ? basename_compat(asrt->file) : asrt->file,
                        asrt->line,
                        line
                    );

                while ((line = strtok_r(NULL, "\n", &saveptr))) {
                    fprintf(f, ",\n            \"  %s\"", line);
                }
                free(dup);
            }
        }
        fprintf(f, JSON_TEST_FAILED_TEMPLATE_END);
    }

    fprintf(f, JSON_TEST_TEMPLATE_END);
}
Esempio n. 10
0
gpg_error_t
gpgsm_status2 (ctrl_t ctrl, int no, ...)
{
  gpg_error_t err = 0;
  va_list arg_ptr;
  const char *text;

  va_start (arg_ptr, no);

  if (ctrl->no_server && ctrl->status_fd == -1)
    ; /* No status wanted. */
  else if (ctrl->no_server)
    {
      if (!statusfp)
        {
          if (ctrl->status_fd == 1)
            statusfp = stdout;
          else if (ctrl->status_fd == 2)
            statusfp = stderr;
          else
            statusfp = fdopen (ctrl->status_fd, "w");

          if (!statusfp)
            {
              log_fatal ("can't open fd %d for status output: %s\n",
                         ctrl->status_fd, strerror(errno));
            }
        }

      fputs ("[GNUPG:] ", statusfp);
      fputs (get_status_string (no), statusfp);

      while ( (text = va_arg (arg_ptr, const char*) ))
        {
          putc ( ' ', statusfp );
          for (; *text; text++)
            {
              if (*text == '\n')
                fputs ( "\\n", statusfp );
              else if (*text == '\r')
                fputs ( "\\r", statusfp );
              else
                putc ( *(const byte *)text,  statusfp );
            }
        }
      putc ('\n', statusfp);
      fflush (statusfp);
    }
  else
    {
Esempio n. 11
0
/**
 * Send an error message
 * @param res HttpResponse object
 * @param code Error Code to lookup and send
 * @param msg Optional error message (may be NULL)
 */
void send_error(HttpResponse res, int code, const char *msg) {
  char server[STRLEN];
  const char *err= get_status_string(code);

  reset_response(res);
  set_content_type(res, "text/html");
  set_status(res, code);
  StringBuffer_append(res->outputbuffer,
	   "<html><head><title>%d %s</title></head>"\
	   "<body bgcolor=#FFFFFF><h2>%s</h2>%s<p>"\
	   "<hr><a href='%s'><font size=-1>%s</font></a>"\
	   "</body></html>\r\n",
	    code, err, err, msg?msg:"", SERVER_URL, get_server(server, STRLEN));
  DEBUG("HttpRequest error: %s %d %s\n", SERVER_PROTOCOL, code, msg ? msg : err);
}
Esempio n. 12
0
void DeInterlaceWindow::create_objects()
{
	int x = 10, y = 10;
	add_tool(new BC_Title(x, y, _("Select deinterlacing mode")));
	y += 25;
	add_tool(mode = new DeInterlaceMode(client, this, x, y));
	mode->create_objects();
	y += 25;
	optional_controls_x=x;
	optional_controls_y=y;
	y += 125;
	char string[BCTEXTLEN];
	get_status_string(string, 0);
	add_tool(status = new BC_Title(x, y, string));
	flash();
	show_window();
	set_mode(client->config.mode,0);
}
Esempio n. 13
0
/* Write a status line with code NO followed by the outout of the
 * printf style FORMAT.  The caller needs to make sure that LFs and
 * CRs are not printed.  */
void
wks_write_status (int no, const char *format, ...)
{
  va_list arg_ptr;

  if (!statusfp)
    return;  /* Not enabled.  */

  es_fputs ("[GNUPG:] ", statusfp);
  es_fputs (get_status_string (no), statusfp);
  if (format)
    {
      es_putc (' ', statusfp);
      va_start (arg_ptr, format);
      es_vfprintf (statusfp, format, arg_ptr);
      va_end (arg_ptr);
    }
  es_putc ('\n', statusfp);
}
Esempio n. 14
0
static off_t
get_status_off (int handle)
{
  char command_buffer[COMMAND_BUFFER_SIZE];
  const char *status = get_status_string (handle, command_buffer);

  if (! status)
    return -1;
  else
    {
      /* Parse status, taking care to check for overflow.
	 We can't use standard functions,
	 since off_t might be longer than long.  */

      off_t count = 0;
      int negative;

      for (;  *status == ' ' || *status == '\t';  status++)
	continue;

      negative = *status == '-';
      status += negative || *status == '+';

      for (;;)
	{
	  int digit = *status++ - '0';
	  if (9 < (unsigned) digit)
	    break;
	  else
	    {
	      off_t c10 = 10 * count;
	      off_t nc = negative ? c10 - digit : c10 + digit;
	      if (c10 / 10 != count || (negative ? c10 < nc : nc < c10))
		return -1;
	      count = nc;
	    }
	}

      return count;
    }
}
Esempio n. 15
0
/**
 * Send an error message to the client. This is a helper function,
 * used internal if the service function fails to setup the framework
 * properly; i.e. with a valid HttpRequest and a valid HttpResponse.
 */
static void internal_error(Socket_T S, int status, char *msg) {
  char date[STRLEN];
  char server[STRLEN];
  const char *status_msg= get_status_string(status);
  
  get_date(date, STRLEN);
  get_server(server, STRLEN);
  socket_print(S, 
	       "%s %d %s\r\n"
	       "Date: %s\r\n"
	       "Server: %s\r\n"
	       "Content-Type: text/html\r\n"
	       "Connection: close\r\n"
	       "\r\n"
	       "<html><head><title>%s</title></head>"
	       "<body bgcolor=#FFFFFF><h2>%s</h2>%s<p>"
	       "<hr><a href='%s'><font size=-1>%s</font></a>"
	       "</body></html>\r\n",
	       SERVER_PROTOCOL, status, status_msg, date, server,
	       status_msg, status_msg, msg, SERVER_URL, server);
  DEBUG("HttpRequest error: %s %d %s\n", SERVER_PROTOCOL, status, msg ? msg : status_msg);
}
Esempio n. 16
0
            {
              if (*text == '\n')
                fputs ( "\\n", statusfp );
              else if (*text == '\r')
                fputs ( "\\r", statusfp );
              else
                putc ( *(const byte *)text,  statusfp );
            }
        }
      putc ('\n', statusfp);
      fflush (statusfp);
    }
  else
    {
      err = vprint_assuan_status_strings (ctrl->server_local->assuan_ctx,
                                          get_status_string (no), arg_ptr);
    }

  va_end (arg_ptr);
  return err;
}

gpg_error_t
gpgsm_status (ctrl_t ctrl, int no, const char *text)
{
  return gpgsm_status2 (ctrl, no, text, NULL);
}

gpg_error_t
gpgsm_status_with_err_code (ctrl_t ctrl, int no, const char *text,
                            gpg_err_code_t ec)
Esempio n. 17
0
BOOL
pw_callback(process_info_t *pi, void **param)
{
    char *resstr;
    char reschar;
    int res;
    WCHAR buf[MAX_CMDLINE];
    DWORD version;
    BOOL under_dr;
    
    WCHAR qual_name[MAX_CMDLINE];
    if (exe)
        generate_process_name(pi, qual_name, BUFFER_SIZE_ELEMENTS(qual_name));

    if ( (pid && pi->ProcessID == pid) ||
         (exe && (!wcsicmp(wexe, pi->ProcessName) || !wcsicmp(wexe,  qual_name))) ||
         listall || listdr)
        {
            version = -1;
            res = under_dynamorio_ex(pi->ProcessID, &version);
            switch (res) {
            case DLL_PROFILE : resstr=NAME" profile"; reschar='P'; break;
            case DLL_RELEASE : resstr=NAME" release"; reschar='R'; break;
            case DLL_DEBUG : resstr=NAME" debug"; reschar='D'; break;
            case DLL_CUSTOM : resstr=NAME" custom"; reschar='C'; break;
            case DLL_NONE : resstr="native"; reschar='N'; break;
            case DLL_UNKNOWN : 
            default : resstr="<error>"; reschar='?';
            }

            under_dr = !(res == DLL_NONE || res == DLL_UNKNOWN);

            if (!listdr || under_dr) {
                if (!nopid && !showmem) {
                    if (onlypid)
                        fprintf(fp, "%d\n", (DWORD) pi->ProcessID);
                    else
                        fprintf(fp, "PID %d, ", (DWORD) pi->ProcessID);
                }
                if (!showmem && !onlypid) {
                    WCHAR qual_name[MAX_CMDLINE];
                    WCHAR *name_to_use = pi->ProcessName;
#ifdef X64
                    HANDLE hproc = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, 
                                               (DWORD) pi->ProcessID);
                    if (is_wow64(hproc)) {
                        if (!no32)
                            fprintf(fp, "32-bit, ");
                        /* FIXME: currently x64 process can't see 32-bit
                         * drmarker
                         */
                        resstr="<unknown>";
                    }
                    CloseHandle(hproc);
#endif
                    if (!noqnames) {
                        generate_process_name(pi, qual_name,
                                              BUFFER_SIZE_ELEMENTS(qual_name));
                        name_to_use = qual_name;
                    }
                    fprintf(fp, "Process %S, ", name_to_use);
                    if (version == -1 || !showbuild)
                        fprintf(fp, "running %s\n", resstr);
                    else
                        fprintf(fp, "running %s (build %d)\n", resstr, version);
                }
                if (cmdline) {
                    res = get_process_cmdline(pi->ProcessID, buf,
                                              BUFFER_SIZE_ELEMENTS(buf));
                    NULL_TERMINATE_BUFFER(buf);
                    if (res == ERROR_SUCCESS) {
                        fprintf(fp, "\tCmdline: %S\n", buf);
                    }
                    else fprintf(fp, "\t<Cmdline err %d>\n", res);
                }
                if (qname) {
                    WCHAR cmdline[MAX_CMDLINE];
                    res = get_process_cmdline(pi->ProcessID, 
                                              cmdline, BUFFER_SIZE_ELEMENTS(cmdline));
                    NULL_TERMINATE_BUFFER(cmdline);
                    if (res == ERROR_SUCCESS) {
                        if (!get_commandline_qualifier(cmdline, buf,
                                                       BUFFER_SIZE_ELEMENTS(buf), !strip))
                            buf[0] = L'\0'; /* no args */
                        NULL_TERMINATE_BUFFER(buf);
                    }
                    if (res == ERROR_SUCCESS)
                        fprintf(fp, "\tQname: %S%s%S\n", pi->ProcessName,
                                buf[0] == L'\0' ? "" : "-", buf);
                    else 
                        fprintf(fp, "\t<Qname err %d>\n", res);
                    
                }
                if (under_dr && hotp) {
                    hotp_policy_status_table_t *status_tbl = NULL;
                    res = get_hotp_status(pi->ProcessID, &status_tbl);
                    if (res == ERROR_SUCCESS) {
                        uint j;
                        hotp_policy_status_t *cur;
                        fprintf(fp, "\tHotpatching:\n", res); 
                        for (j = 0; j < status_tbl->num_policies; j++) {
                            char status_buf[MAX_PATH];
                            cur = &(status_tbl->policy_status_array[j]);
                            if (get_status_string(status_buf, MAX_PATH,
                                                  cur->inject_status,
                                                  cur->mode))
                                fprintf(fp, "\t  Patch %s: %s\n",
                                        cur->policy_id, status_buf);
                        }
                    }
                    else if (res == ERROR_DRMARKER_ERROR) {
                        fprintf(fp, "\tHot Patching Not Enabled\n", res);
                    }
                    else {
                        fprintf(fp, "\t<Hotpatch Query Error %d>\n", res);
                    }
                }
                if (under_dr && showstats) {
                    dr_statistics_t *stats = get_dynamorio_stats(pi->ProcessID);
                    if (stats != NULL) {
                        uint i;
                        fprintf(fp, "\t%.*s\n",
                                BUFFER_SIZE_ELEMENTS(stats->process_name),
                                stats->process_name);
                        for (i = 0; i < stats->num_stats; i++) {
                            fprintf(fp, "\t%*.*s :%9d\n",
                                    BUFFER_SIZE_ELEMENTS(stats->stats[i].name),
                                    BUFFER_SIZE_ELEMENTS(stats->stats[i].name),
                                    stats->stats[i].name, stats->stats[i].value);
                        }
                    }
                    free_dynamorio_stats(stats);
                }
                if (showmem) {
                    print_mem_stats(pi, reschar, version);
                }
                count++;
            }
        } 
    return TRUE;
}
Esempio n. 18
0
/**
 * Sets the status code for the response
 * @param res HttpResponse object
 * @param code A HTTP status code <100-510>
 * @param msg The status code string message 
 */
void set_status(HttpResponse res, int code) {
  res->status= code;
  res->status_msg= get_status_string(code);
}
Esempio n. 19
0
static void *broadcast_progress_thread(void *data)
{
	int status = -1;
	int source = -1;
	int step = 0;
	int percent = 0;
	int fd = -1;

	for (;;) {
		struct mg_mgr *mgr = (struct mg_mgr *) data;
		struct progress_msg msg;
		char str[512];
		int ret;

		if (fd < 0)
			fd = progress_ipc_connect(true);

		ret = progress_ipc_receive(&fd, &msg);
		if (ret != sizeof(msg))
			return NULL;

		if (msg.status != status || msg.status == FAILURE) {
			status = msg.status;

			snprintf(str, sizeof(str),
				"{\r\n"
				"\t\"type\": \"status\",\r\n"
				"\t\"status\": \"%s\"\r\n"
				"}\r\n",
				get_status_string(msg.status));
			broadcast(mgr, str);
		}

		if (msg.source != source) {
			source = msg.source;

			snprintf(str, sizeof(str),
				"{\r\n"
				"\t\"type\": \"source\",\r\n"
				"\t\"source\": \"%s\"\r\n"
				"}\r\n",
				get_source_string(msg.source));
			broadcast(mgr, str);
		}

		if (msg.status == SUCCESS && msg.source == SOURCE_WEBSERVER && run_postupdate) {
			ipc_message ipc = {};

			ipc_postupdate(&ipc);
		}

		if (msg.infolen) {
			snprintf(str, sizeof(str),
				"{\r\n"
				"\t\"type\": \"info\",\r\n"
				"\t\"source\": \"%s\"\r\n"
				"}\r\n",
				msg.info);
			broadcast(mgr, str);
		}

		if ((msg.cur_step != step || msg.cur_percent != percent) &&
				msg.cur_step) {
			step = msg.cur_step;
			percent = msg.cur_percent;

			snprintf(str, sizeof(str),
				"{\r\n"
				"\t\"type\": \"step\",\r\n"
				"\t\"number\": \"%d\",\r\n"
				"\t\"step\": \"%d\",\r\n"
				"\t\"name\": \"%s\",\r\n"
				"\t\"percent\": \"%d\"\r\n"
				"}\r\n",
				msg.nsteps,
				msg.cur_step,
				msg.cur_step ? msg.cur_image: "",
				msg.cur_percent);
			broadcast(mgr, str);
		}
	}

	return NULL;
}
Esempio n. 20
0
extern SANE_Status control_option (SANE_Handle handle, const SANE_Option_Descriptor *option, SANE_Int index, SANE_Action action, void *value, int *ret) {
    SANE_Status status;
    char *old_value;

    switch (option->type) {
    case SANE_TYPE_BOOL:
        old_value = o_printf (*((SANE_Bool *) value) ? "SANE_TRUE" : "SANE_FALSE");
        break;
    case SANE_TYPE_INT:
        old_value = o_printf ("%d", *((SANE_Int *) value));
        break;
    case SANE_TYPE_FIXED:
        old_value = o_printf ("%f", SANE_UNFIX (*((SANE_Fixed *) value)));
        break;
    case SANE_TYPE_STRING:
        old_value = o_printf ("\"%s\"", (char *) value);
        break;
    default:
        old_value = o_strdup ("?");
        break;
    }

    status = sane_control_option (handle, index, action, value, ret);

    switch (option->type) {
    case SANE_TYPE_BOOL:
        o_log(DEBUGM, "sane_control_option (%d, %s, %s) -> (%s, %s)",
                 index, get_action_string (action),
                 *((SANE_Bool *) value) ? "SANE_TRUE" : "SANE_FALSE",
                 get_status_string (status),
                 old_value);
        break;
    case SANE_TYPE_INT:
        o_log(DEBUGM, "sane_control_option (%d, %s, %d) -> (%s, %s)",
                 index, get_action_string (action),
                 *((SANE_Int *) value),
                 get_status_string (status),
                 old_value);
        break;
    case SANE_TYPE_FIXED:
        o_log(DEBUGM, "sane_control_option (%d, %s, %f) -> (%s, %s)",
                 index, get_action_string (action),
                 SANE_UNFIX (*((SANE_Fixed *) value)),
                 get_status_string (status),
                 old_value);
        break;
    case SANE_TYPE_STRING:
        o_log(DEBUGM, "sane_control_option (%d, %s, \"%s\") -> (%s, %s)",
                 index, get_action_string (action),
                 (char *) value,
                 get_status_string (status),
                 old_value);
        break;
    default:
        break;
    }

    free (old_value);

    if (status != SANE_STATUS_GOOD)
        o_log(WARNING, "Error setting option %s: %s", option->name, sane_strstatus(status));

    return status;
}
Esempio n. 21
0
/*
 * Write a status line with a buffer using %XX escapes.  If WRAP is >
 * 0 wrap the line after this length.  If STRING is not NULL it will
 * be prepended to the buffer, no escaping is done for string.
 * A wrap of -1 forces spaces not to be encoded as %20.
 */
void
write_status_text_and_buffer ( int no, const char *string,
                               const char *buffer, size_t len, int wrap )
{
    const char *s, *text;
    int esc, first;
    int lower_limit = ' ';
    size_t n, count, dowrap;

    if( !statusfp || !status_currently_allowed (no) )
	return;  /* Not enabled or allowed. */

    if (wrap == -1) {
        lower_limit--;
        wrap = 0;
    }

    text = get_status_string (no);
    count = dowrap = first = 1;
    do {
        if (dowrap) {
            fprintf (statusfp, "[GNUPG:] %s ", text );
            count = dowrap = 0;
            if (first && string) {
                fputs (string, statusfp);
                count += strlen (string);
                /* Make sure that there is space after the string.  */
                if (*string && string[strlen (string)-1] != ' ')
                  {
                    putc (' ', statusfp);
                    count++;
                  }
            }
            first = 0;
        }
        for (esc=0, s=buffer, n=len; n && !esc; s++, n-- ) {
            if ( *s == '%' || *(const byte*)s <= lower_limit
                           || *(const byte*)s == 127 )
                esc = 1;
            if ( wrap && ++count > wrap ) {
                dowrap=1;
                break;
            }
        }
        if (esc) {
            s--; n++;
        }
        if (s != buffer)
            fwrite (buffer, s-buffer, 1, statusfp );
        if ( esc ) {
            fprintf (statusfp, "%%%02X", *(const byte*)s );
            s++; n--;
        }
        buffer = s;
        len = n;
        if ( dowrap && len )
            putc ( '\n', statusfp );
    } while ( len );

    putc ('\n',statusfp);
    if ( fflush (statusfp) && opt.exit_on_status_write_error )
      g10_exit (0);
}