Commit 625614ac authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

new. new. new.

2002-03-27  Jody Goldberg <jody@gnome.org>

	* src/io-context.c (gnm_io_get_password) : new.
	* src/command-context.c (cmd_context_get_password) : new.
	* src/workbook-control-gui.c (wbcg_get_password) : new.
parent a02c4c8d
2002-03-27 Jody Goldberg <jody@gnome.org>
* ms-biff.c (ms_biff_query_set_decrypt) : protect against NULL
passwords.
2002-03-25 Jody Goldberg <jody@gnome.org>
* Release 1.1.2
......
......@@ -77,7 +77,7 @@ makekey (guint32 block, RC4_KEY *key, MD5_CTX *valContext)
memset (pwarray, 0, 64);
/* 40 bit of hashed password, set by verifypwd () */
/* 40 bit of hashed password, set by verify_password () */
memcpy (pwarray, valContext->digest, 5);
/* put block number in byte 6...9 */
......@@ -197,13 +197,14 @@ skip_bytes (BiffQuery *q, int start, int count)
#define sizeof_BIFF_FILEPASS (6 + 3*16)
gboolean
ms_biff_query_set_decrypt (BiffQuery *q)
ms_biff_query_set_decrypt (BiffQuery *q, char const *password)
{
char const *password = "PASSWORD";
g_return_val_if_fail (q->opcode == BIFF_FILEPASS, FALSE);
g_return_val_if_fail (q->length == sizeof_BIFF_FILEPASS, FALSE);
if (password == NULL)
return FALSE;
if (!verify_password (password, q->data + 6,
q->data + 22, q->data + 38, &q->md5_ctxt))
return FALSE;
......@@ -337,9 +338,9 @@ ms_biff_query_next (BiffQuery *q)
} else
q->non_decrypted_data = q->data;
#if BIFF_DEBUG > 2
printf ("Biff read code 0x%x, length %d\n", q->opcode, q->length);
dump_biff (q);
#if BIFF_DEBUG > 2
#endif
if (!q->length) {
q->data = 0;
......
......@@ -42,7 +42,7 @@ typedef struct {
/* Sets up a query on a stream */
BiffQuery *ms_biff_query_new (MsOleStream *);
gboolean ms_biff_query_set_decrypt (BiffQuery *q);
gboolean ms_biff_query_set_decrypt (BiffQuery *q, char const *password);
/* Updates the BiffQuery structure with the next BIFF record
* returns: 1 for succes, and 0 for EOS(tream) */
......
......@@ -4678,10 +4678,19 @@ ms_excel_read_workbook (IOContext *context, WorkbookView *wb_view,
case BIFF_PASSWORD:
break;
case BIFF_FILEPASS:
/* All records after this are encrypted */
if (!ms_biff_query_set_decrypt (q))
problem_loading = g_strdup (_("Invalid password"));
case BIFF_FILEPASS: /* All records after this are encrypted */
do {
char *passwd = gnm_io_get_password (context,
_("This file is encrypted"));
if (!ms_biff_query_set_decrypt (q, passwd))
problem_loading = _("Invalid password");
if (passwd == NULL)
break;
g_free (passwd);
if (problem_loading == NULL)
break;
problem_loading = NULL;
} while (TRUE);
break;
case BIFF_STYLE:
......@@ -4792,9 +4801,8 @@ ms_excel_read_workbook (IOContext *context, WorkbookView *wb_view,
ms_excel_workbook_destroy (wb);
/* If we were forced to stop then the load failed */
if (problem_loading != NULL) {
if (problem_loading != NULL)
gnumeric_io_error_read (context, problem_loading);
}
return;
}
......
......@@ -11,16 +11,17 @@ struct _CommandContext {
typedef struct {
GObjectClass g_object_class;
void (*progress_set) (CommandContext *context, gfloat val);
void (*progress_message_set) (CommandContext *context, gchar const *msg);
char * (*get_password) (CommandContext *cc, char const *msg);
void (*progress_set) (CommandContext *cc, gfloat val);
void (*progress_message_set) (CommandContext *cc, gchar const *msg);
struct {
void (*system) (CommandContext *ctxt, char const *msg);
void (*plugin) (CommandContext *ctxt, char const *msg);
void (*read) (CommandContext *ctxt, char const *msg);
void (*save) (CommandContext *ctxt, char const *msg);
void (*splits_array) (CommandContext *ctxt,
void (*system) (CommandContext *cc, char const *msg);
void (*plugin) (CommandContext *cc, char const *msg);
void (*read) (CommandContext *cc, char const *msg);
void (*save) (CommandContext *cc, char const *msg);
void (*splits_array) (CommandContext *cc,
char const *cmd, Range const *array);
void (*invalid) (CommandContext *ctxt,
void (*invalid) (CommandContext *cc,
char const *msg, char const *val);
void (*error_info) (CommandContext *ctxt, ErrorInfo *error);
} error;
......
......@@ -121,6 +121,14 @@ gnumeric_progress_message_set (CommandContext *context, gchar const *msg)
CC_CLASS (context)->progress_message_set (context, msg);
}
char *
cmd_context_get_password (CommandContext *cc, char const *msg)
{
g_return_val_if_fail (IS_COMMAND_CONTEXT (cc), NULL);
return CC_CLASS (cc)->get_password (cc, msg);
}
/**
* command_context_push_template
* @template: printf template to display message
......
......@@ -16,17 +16,18 @@ GType command_context_get_type (void);
* NOTE : The selection is quite limited by IDL's intentional non-support for
* inheritance (single or multiple).
*/
void gnumeric_error_system (CommandContext *context, char const *msg);
void gnumeric_error_read (CommandContext *context, char const *msg);
void gnumeric_error_save (CommandContext *context, char const *msg);
void gnumeric_error_plugin (CommandContext *context, char const *msg);
void gnumeric_error_invalid (CommandContext *context,
char const *msg, char const *val);
void gnumeric_error_splits_array (CommandContext *context,
char const *cmd, Range const *array);
void gnumeric_error_error_info (CommandContext *context, ErrorInfo *error);
void gnumeric_progress_set (CommandContext *context, gfloat f);
void gnumeric_progress_message_set (CommandContext *context, gchar const *msg);
void gnumeric_error_system (CommandContext *cc, char const *msg);
void gnumeric_error_read (CommandContext *cc, char const *msg);
void gnumeric_error_save (CommandContext *cc, char const *msg);
void gnumeric_error_plugin (CommandContext *cc, char const *msg);
void gnumeric_error_invalid (CommandContext *cc, char const *msg,
char const *val);
void gnumeric_error_splits_array (CommandContext *cc, char const *cmd,
Range const *array);
void gnumeric_error_error_info (CommandContext *cc, ErrorInfo *error);
void gnumeric_progress_set (CommandContext *cc, gfloat f);
void gnumeric_progress_message_set (CommandContext *cc, char const *msg);
char *cmd_context_get_password (CommandContext *cc, char const *msg);
/* Push a printf template to the list. The template is used to provide
* context for error messages. E.g.: "Could not read file: %s". */
......
......@@ -436,7 +436,7 @@ gnm_canvas_key_release (GtkWidget *widget, GdkEventKey *event)
wb_view_selection_desc (wb_control_view (
sc->wbc), TRUE, NULL);
return (*GTK_WIDGET_CLASS (gcanvas_parent_class)->key_release_event)(widget, event);
return (*GTK_WIDGET_CLASS (gcanvas_parent_class)->key_release_event) (widget, event);
}
/* Focus in handler for the canvas */
......@@ -449,7 +449,7 @@ gnm_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event)
if (gcanvas->ic)
gdk_im_begin (gcanvas->ic, gcanvas->simple.canvas.layout.bin_window);
#endif
return (*GTK_WIDGET_CLASS (gcanvas_parent_class)->focus_in_event)(widget, event);
return (*GTK_WIDGET_CLASS (gcanvas_parent_class)->focus_in_event) (widget, event);
}
/* Focus out handler for the canvas */
......@@ -460,7 +460,7 @@ gnm_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event)
#if 0
gdk_im_end ();
#endif
return (*GTK_WIDGET_CLASS (gcanvas_parent_class)->focus_out_event)(widget, event);
return (*GTK_WIDGET_CLASS (gcanvas_parent_class)->focus_out_event) (widget, event);
}
static void
......@@ -657,7 +657,7 @@ gnm_canvas_class_init (GnumericCanvasClass *Class)
widget_class = (GtkWidgetClass *) Class;
canvas_class = (GnomeCanvasClass *) Class;
gcanvas_parent_class = gtk_type_class (gnome_canvas_get_type ());
gcanvas_parent_class = gtk_type_class (GNM_SIMPLE_CANVAS_TYPE);
widget_class->realize = gnm_canvas_realize;
widget_class->unrealize = gnm_canvas_unrealize;
......@@ -717,6 +717,7 @@ gnumeric_canvas_new (SheetControlGUI *scg, GnumericPane *pane)
gcanvas->pane = pane;
/* FIXME: figure out some real size for the canvas scrolling region */
gnome_canvas_set_center_scroll_region (GNOME_CANVAS (gcanvas), FALSE);
gnome_canvas_set_scroll_region (GNOME_CANVAS (gcanvas), 0, 0,
GNUMERIC_CANVAS_FACTOR_X, GNUMERIC_CANVAS_FACTOR_Y);
......
......@@ -455,25 +455,41 @@ io_progress_unset (IOContext *io_context)
io_context->helper.helper_type = GNUM_PROGRESS_HELPER_NONE;
}
/**
* gnm_io_get_password :
* @context :
* @msg : optionally NULL
*
*/
char *
gnm_io_get_password (IOContext *context, char const *msg)
{
g_return_val_if_fail (IS_IO_CONTEXT (context), NULL);
return cmd_context_get_password (context->impl, msg);
}
#warning Good Project implement these
void
gnm_io_warning (IOContext *context, char const *msg)
{
g_return_if_fail (IS_IO_CONTEXT (context));
}
void
gnm_io_warning_unknown_font (IOContext *context, char const *font_name)
{
g_return_if_fail (IS_IO_CONTEXT (context));
}
void
gnm_io_warning_unknown_function (IOContext *context, char const *funct_name)
{
g_return_if_fail (IS_IO_CONTEXT (context));
}
void
gnm_io_warning_unsupported_feature (IOContext *context, char const *feature)
{
g_return_if_fail (IS_IO_CONTEXT (context));
g_warning ("%s : are not supported yet", feature);
}
......@@ -41,6 +41,7 @@ void gnumeric_io_error_display (IOContext *context);
void gnumeric_io_clear_error (IOContext *context);
gboolean gnumeric_io_error_occurred (IOContext *context);
gboolean gnumeric_io_error_occurred (IOContext *context);
void io_progress_message (IOContext *io_context, const gchar *msg);
void io_progress_update (IOContext *io_context, gdouble f);
......@@ -65,9 +66,10 @@ void workbook_io_progress_update (IOContext *io_context, gint inc);
void io_progress_unset (IOContext *io_context);
void gnm_io_warning (IOContext *context, char const *msg);
void gnm_io_warning_unknown_font (IOContext *context, char const *font_name);
void gnm_io_warning_unknown_function (IOContext *context, char const *funct_name);
void gnm_io_warning_unsupported_feature (IOContext *context, char const *feature);
char *gnm_io_get_password (IOContext *context, char const *msg);
void gnm_io_warning (IOContext *context, char const *msg);
void gnm_io_warning_unknown_font (IOContext *context, char const *font_name);
void gnm_io_warning_unknown_function (IOContext *context, char const *funct_name);
void gnm_io_warning_unsupported_feature (IOContext *context, char const *feature);
#endif /* GNUMERIC_IO_CONTEXT_H */
......@@ -27,7 +27,6 @@
#include "value.h"
#include "str.h"
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
......@@ -200,9 +199,9 @@ typedef struct {
ParsePos const *pos;
/* Locale info. */
char decimal_point;
char separator;
char array_col_separator;
gunichar decimal_point;
gunichar separator;
gunichar array_col_separator;
/* flags */
gboolean use_excel_reference_conventions;
......@@ -383,17 +382,17 @@ int yyparse (void);
%}
%union {
GnmExpr *tree;
CellRef *cell;
GnmExprList *list;
Sheet *sheet;
GnmExpr *expr;
Value *value;
CellRef *cell;
GnmExprList *list;
Sheet *sheet;
}
%type <list> opt_exp arg_list array_row, array_cols
%type <tree> exp array_exp string_opt_quote
%token <tree> STRING QUOTED_STRING CONSTANT CELLREF GTE LTE NE AND OR NOT
%token SEPARATOR INVALID_TOKEN
%type <tree> cellref
%type <sheet> sheetref opt_sheetref
%type <list> opt_exp arg_list array_row, array_cols
%type <expr> exp array_exp string_opt_quote cellref
%token <expr> STRING QUOTED_STRING CONSTANT CELLREF GTE LTE NE AND OR NOT
%token SEPARATOR INVALID_TOKEN
%type <sheet> sheetref opt_sheetref
%left '&'
%left '<' '>' '=' GTE LTE NE
......@@ -742,12 +741,12 @@ parse_ref_or_string (char const *string)
ref.row += state->pos->eval.row;
ref.row_relative = FALSE;
}
yylval.tree = register_expr_allocation (gnm_expr_new_cellref (&ref));
yylval.expr = register_expr_allocation (gnm_expr_new_cellref (&ref));
return CELLREF;
}
v = value_new_string (string);
yylval.tree = register_expr_allocation (gnm_expr_new_constant (v));
yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
return STRING;
}
......@@ -762,16 +761,16 @@ parse_ref_or_string (char const *string)
static char const *
find_char (char const *str, char c)
{
for (; *str && *str != c; str++)
for (; *str && *str != c; str = g_utf8_next_char (str))
if (*str == '\\' && str[1])
str++;
str = g_utf8_next_char (str);
return str;
}
static char const *
find_matching_close (char const *str, char const **res)
{
for (; *str; str++) {
for (; *str; str = g_utf8_next_char (str)) {
if (*str == '(') {
char const *tmp = str;
str = find_matching_close (str + 1, res);
......@@ -791,15 +790,16 @@ find_matching_close (char const *str, char const **res)
int
yylex (void)
{
int c;
gunichar c;
char const *start;
gboolean is_number = FALSE;
while (isspace ((unsigned char)*state->expr_text))
state->expr_text++;
while (g_unichar_isspace (g_utf8_get_char (state->expr_text)))
state->expr_text = g_utf8_next_char (state->expr_text);
start = state->expr_text;
c = (unsigned char) (*state->expr_text++);
c = g_utf8_get_char (start);
state->expr_text = g_utf8_next_char (state->expr_text);
if (c == '(' || c == ')')
return c;
......@@ -838,19 +838,21 @@ yylex (void)
if (c == state->decimal_point) {
/* Could be a number or a stand alone */
if (!isdigit ((unsigned char)(*state->expr_text)))
if (!g_unichar_isdigit (g_utf8_get_char (state->expr_text)))
return c;
is_number = TRUE;
} else if (isdigit (c)) {
while (isdigit ((c = (unsigned char)(*state->expr_text++))))
;
} else if (g_unichar_isdigit (c)) {
do {
c = g_utf8_get_char (state->expr_text);
state->expr_text = g_utf8_next_char (state->expr_text);
} while (g_unichar_isdigit (c));
is_number = TRUE;
}
if (is_number) {
Value *v = NULL;
if (c == state->decimal_point || tolower (c) == 'e') {
if (c == state->decimal_point || c == 'e' || c == 'E') {
/* This is float */
char *end;
gnum_float d;
......@@ -862,7 +864,7 @@ yylex (void)
} else if (errno != ERANGE) {
v = value_new_float (d);
state->expr_text = end;
} else if (tolower (c) != 'e') {
} else if (c != 'e' && c != 'E') {
gnumeric_parse_error (
state, PERR_OUT_OF_RANGE,
g_strdup (_("The number is out of range")),
......@@ -919,7 +921,7 @@ yylex (void)
if (v == NULL)
return c;
yylval.tree = register_expr_allocation (gnm_expr_new_constant (v));
yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
return CONSTANT;
}
......@@ -942,8 +944,9 @@ yylex (void)
}
s = string = (char *) alloca (1 + state->expr_text - p);
while (p != state->expr_text){
if (*p== '\\'){
/* this is safe for utf8 */
while (p != state->expr_text) {
if (*p == '\\'){
p++;
*s++ = *p++;
} else
......@@ -953,20 +956,21 @@ yylex (void)
state->expr_text++;
v = value_new_string (string);
yylval.tree = register_expr_allocation (gnm_expr_new_constant (v));
yylval.expr = register_expr_allocation (gnm_expr_new_constant (v));
return QUOTED_STRING;
}
}
if (isalpha ((unsigned char)c) || c == '_' || c == '$'){
if (g_unichar_isalpha (c) || c == '_' || c == '$'){
char const *start = state->expr_text - 1;
char *str;
int len;
gunichar tmp;
while (isalnum ((unsigned char)*state->expr_text) || *state->expr_text == '_' ||
*state->expr_text == '$' ||
(state->use_excel_reference_conventions && *state->expr_text == '.'))
state->expr_text++;
while ((tmp = g_utf8_get_char (state->expr_text)) != 0 &&
(g_unichar_isalnum (tmp) || tmp == '_' || tmp == '$' ||
(state->use_excel_reference_conventions && tmp == '.')))
state->expr_text = g_utf8_next_char (state->expr_text);
len = state->expr_text - start;
str = alloca (len + 1);
......
......@@ -3,12 +3,11 @@
/*
* sheet-merge.c: merged cell support
*
* Copyright (C) 2000, 2001 Jody Goldberg (jody@gnome.org)
* Copyright (C) 2000-2002 Jody Goldberg (jody@gnome.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
......
......@@ -1089,6 +1089,44 @@ wbcg_claim_selection (WorkbookControl *wbc)
GDK_CURRENT_TIME);
}
static void
cb_accept_password (GtkWidget *IGNORED, GtkDialog *d)
{
gtk_dialog_response (d, GTK_RESPONSE_ACCEPT);
}
static char *
wbcg_get_password (CommandContext *cc, char const* msg)
{
char *res = NULL;
WorkbookControlGUI *wbcg = WORKBOOK_CONTROL_GUI (cc);
GtkWidget *d = gtk_message_dialog_new (wbcg_toplevel (wbcg),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_CANCEL,
msg);
GtkWidget *box = gtk_hbox_new (FALSE, 5);
GtkWidget *entry = g_object_new (GTK_TYPE_ENTRY,
"visibility", FALSE,
NULL);
gtk_box_pack_start_defaults (GTK_BOX (box), gtk_label_new (_("Password :")));
gtk_box_pack_start_defaults (GTK_BOX (box), entry);
gtk_widget_show_all (entry);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox), box,
FALSE, TRUE, 0);
gtk_widget_show_all (d);
g_signal_connect (G_OBJECT (entry),
"activate",
G_CALLBACK (cb_accept_password), d);
gtk_dialog_set_has_separator (GTK_DIALOG (d), TRUE);
gnumeric_set_transient (wbcg, GTK_WINDOW (d));
if (gtk_dialog_run (GTK_DIALOG (d)) == GTK_RESPONSE_ACCEPT)
res = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
gtk_widget_destroy (d);
return res;
}
static void
wbcg_progress_set (CommandContext *cc, gfloat val)
{
......@@ -4417,6 +4455,7 @@ workbook_control_gui_ctor_class (GObjectClass *object_class)
object_class->finalize = wbcg_finalize;
wbc_class->context_class.get_password = wbcg_get_password;
wbc_class->context_class.progress_set = wbcg_progress_set;
wbc_class->context_class.progress_message_set = wbcg_progress_message_set;
wbc_class->context_class.error.system = wbcg_error_system;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment