File: main.c

package info (click to toggle)
linneighborhood 0.6.5-3.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,312 kB
  • ctags: 2,315
  • sloc: ansic: 21,717; sh: 2,984; yacc: 318; makefile: 312
file content (310 lines) | stat: -rw-r--r-- 7,679 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/* LinNeighborhood
 * Copyright (c) 1999-2002 Richard Stemmer and Hans Schmid
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "guiwrap.h"
#include "preferences.h"
#include "data.h"
#include "browsewrap.h"
#include "utility.h"
#include "io.h"
#include "smbif.h"
#include "libsmb.h"


/* ------------------------------------------------------------------------------- */

/* realtime timer handler for periodic updates */

static void timer_interval_handler (gpointer data)
{
  /* do an update for the mounted share list */
  if ( pref.v.mount_retrigger_enable )
#ifndef NO_SMBMOUNT
    mount_list_retrigger();
#else
    ;
#endif
}

/* ------------------------------------------------------------------------------- */

static void print_help (void)
{
  fprintf(stdout, "\nLinNeighborhood version "VERSION"\n");
  fprintf(stdout, "This free software distributed under under the terms of the\n"
                  "GNU General Public License\n\n");
  fprintf(stdout, "Optional Parameters:\n");
  fprintf(stdout, " -h --help                = print this help text\n");
  fprintf(stdout, " -v --version             = print program version\n");
#ifndef NO_SMBMOUNT
  fprintf(stdout, " -m --mountshares         = mount memorized shares without starting the GUI\n"); /*74*/
#endif
  fprintf(stdout, " -i --iconify             = start program iconified\n");
  /*fprintf(stdout, " -n --networkimage [file] = does an entire network scan, writing the image\n"
                  "                            to a file ( no GUI )\n");*/
  fprintf(stdout, " -u --user [username]     = does the network scan as user\n");
  fprintf(stdout, " -p --password [userpswd] = does the user network scan with password\n");
  fprintf(stdout, " -j --job [number]        = number of max simultaneous browse jobs\n");
  fprintf(stdout, "\n");
}

/* ------------------------------------------------------------------------------- */

static void cleanup ()
{
  gui_share_window_clean();
  browse_clean();
  data_clean();
}

static void save_exit (int exitcode)
{
  cleanup();

#ifndef NO_LIBSMB
  /* unload libsmbclient.so */
  lib_smb_close();
#endif
  
  exit(exitcode);
}

/* ------------------------------------------------------------------------------- */

/*static unsigned char browse_network_ready;*/

#ifndef NO_SMBMOUNT

static void restore_mounts (void)
{
  GSList *mplist, *templist;
  mem_mount_struct *mount;
  
  mplist = mountpoint_load();
  if ( mplist != NULL )
  {
    /* do mount action */
    templist = mplist;
    while ( templist != NULL )
    {
      mount = (mem_mount_struct*)(templist->data);
      if ( mount != NULL )
      {
        utility_do_mount(mount);
        if ( mount->arglist != NULL )
        {
          slist_free_with_data(&(mount->arglist));
        }
      }
      templist = templist->next;
    }
    
    /* delete list */
    slist_free_with_data(&mplist);
  }
}

#endif


/*static void browse_network_callback (void)
{
  if ( startup.b.netimage_file == YES )
  {
    network_image_export(startup.v.netimage_file);
  }
  else
  {
    network_image_export(SMBNETWORK_FILE);
  }
  browse_network_ready = 1;
}*/

static void execute_command_line ()
{
  unsigned char do_exit;
  /*BROWSE_MODE mode;
  unsigned int maxsleep;*/
  
  do_exit = 0;
  
  /* print help output */
  if ( startup.v.show_help )
  {
    print_help();
    do_exit = 1;
  }
  
  /* print program version */
  if ( startup.v.print_version )
  {
    fprintf(stdout, VERSION"\n");
    do_exit = 1;
  }
  
#ifndef NO_SMBMOUNT

  /* restore memorized shares */
  if ( startup.v.restore_shares )
  {
    restore_mounts();
    do_exit = 1;
  }

#endif
  
  /* do a complete network scan */
  if ( startup.v.network_image )
  {
    /*mode = BROWSE_MODE_NO_GUI;
    if ( startup.v.is_user )
      mode |= BROWSE_MODE_USER;
    browse_network_ready = 0;
    browse_network(mode);
    browse_network_wait_done(browse_network_callback);
    while ( 1 )
    {
      sleep(1);
      if ( browse_network_ready )
        break;
    }
    do_exit = 1;*/
  }
  
  /* store predefined username */
  if ( startup.v.is_user )
  {
    string_ncopy(globals.browse_user, startup.v.user, USER_LEN);
  }
  
  /* store predefined password */
  if ( startup.v.is_password )
  {
    string_ncopy(globals.browse_password, startup.v.password, PASSWORD_LEN);
  }
  
  if ( do_exit )
  {
    save_exit(0);
  }
}

/* ------------------------------------------------------------------------------- */

int main (int argc, char *argv[])
{
  BROWSE_MODE mode;

#ifndef NO_LIBSMB  
  /* initialize libsmbclient.so */
  lib_smb_init("libsmbclient.so");
#endif

  /* data initializations */
  data_init();                      /* browse data */
  browse_init();                    /* browse wrapper stuff */
  
  /* global variable initializations */
  globals_init();
  startup_parse_command_line(argc, argv, &startup);
  preferences_load(&pref);
#ifndef NO_SMBMOUNT
  init_smbmount();
#endif
  
  /* other stored information */
  add_master_load();                /* load additional master browser */
  groupmaster_load();               /* load additional group masters */
  prefhost_load();                  /* load preferred hosts */
  password_load();                  /* load default password */
  
#ifndef NO_SMBMOUNT
  /* scan mtab for existing mounts */
  mount_list_retrigger();
#endif
  /* execute command line parameters */
  execute_command_line();

#ifndef NO_SMBMOUNT
  if ( pref.v.memorize_mounts )
  {
    restore_mounts();
  }
#endif

  /* -------------- */
  /* -- GUI part -- */
  /* -------------- */
  
  /* GUI internationalization */
  gui_set_locale();
  
  /* localization */
  bindtextdomain(PACKAGE, LOCALEDIR);
  textdomain(PACKAGE);
  
  /* --- GUI initialization --- */
  gui_init(argc, argv);
#ifndef NO_SMBMOUNT
  gui_mount_dialog_init();
#endif
	
  /* initial browse on startup */
  if ( pref.v.startup_browse == YES )
  {
    mode = BROWSE_MODE_NONE;
    if ( pref.v.quick_browse == YES )
      mode |= BROWSE_MODE_QUICK;
    if ( pref.v.groups_scan_user == YES )
      mode |= BROWSE_MODE_USER;
    gui_set_cursor(cursor_watch);
    browse_groups(mode | BROWSE_MODE_EXPAND);
  }
  
  /* --- handler for periodic timer intervall --- */
  gui_timer_start(TIMER_INTERVAL_UPDATE, timer_interval_handler, NULL);

  /* -- GUI main loop -- */
  gui_start ();
  gui_timer_stop();
  
  /* -------------------------- */
  /* -- end of GUI main loop -- */
  /* -------------------------- */
  
  /* save any informations */
#ifndef NO_SMBMOUNT
  if ( pref.v.memorize_mounts )
  {
    mountpoint_save();
  }
#endif
  password_save();                  /* save default password */
  prefhost_save();                  /* save preferred hosts */
  groupmaster_save();               /* save additional group masters */
  add_master_save();                /* save additional master browsers */
  
  /* data + memory cleanup */
  cleanup();
  
  save_exit(0);
  return 0;
}