]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/ua_select.c
Fix DATE problem and minor compile stuff
[bacula/bacula] / bacula / src / dird / ua_select.c
1 /*
2  *
3  *   Bacula Director -- User Agent Prompt and Selection code
4  *
5  *     Kern Sibbald, October MMI
6  *
7  *   Version  $Id$
8  */
9
10 /*
11    Copyright (C) 2000-2003 Kern Sibbald and John Walker
12
13    This program is free software; you can redistribute it and/or
14    modify it under the terms of the GNU General Public License as
15    published by the Free Software Foundation; either version 2 of
16    the License, or (at your option) any later version.
17
18    This program is distributed in the hope that it will be useful,
19    but WITHOUT ANY WARRANTY; without even the implied warranty of
20    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21    General Public License for more details.
22
23    You should have received a copy of the GNU General Public
24    License along with this program; if not, write to the Free
25    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
26    MA 02111-1307, USA.
27
28  */
29
30 #include "bacula.h"
31 #include "dird.h"
32 #include "ua.h"
33
34
35 /* Imported variables */
36
37
38 /*
39  * Confirm a retention period
40  */
41 int confirm_retention(UAContext *ua, utime_t *ret, char *msg)
42 {
43    char ed1[30];
44
45    for ( ;; ) {
46        bsendmsg(ua, _("The current %s retention period is: %s\n"), 
47           msg, edit_utime(*ret, ed1));
48        if (!get_cmd(ua, _("Continue? (yes/mod/no): "))) {
49           return 0;
50        }
51        if (strcasecmp(ua->cmd, _("mod")) == 0) {
52           if (!get_cmd(ua, _("Enter new retention period: "))) {
53              return 0;
54           }
55           if (!duration_to_utime(ua->cmd, ret)) {
56              bsendmsg(ua, _("Invalid period.\n"));
57              continue;
58           }
59           continue;
60        }
61        if (strcasecmp(ua->cmd, _("yes")) == 0) {
62           break;
63        }
64     }
65     return 1;
66 }
67
68 /* 
69  * Given a list of keywords, find the first one
70  *  that is in the argument list.
71  * Returns: -1 if not found
72  *          index into list (base 0) on success
73  */
74 int find_arg_keyword(UAContext *ua, char **list)
75 {
76    int i, j;
77    for (i=1; i<ua->argc; i++) {
78       for(j=0; list[j]; j++) {
79          if (strcasecmp(_(list[j]), ua->argk[i]) == 0) {
80             return j;
81          }
82       }
83    }
84    return -1;
85 }
86
87 /* 
88  * Given a list of keywords, prompt the user 
89  * to choose one.
90  *
91  * Returns: -1 on failure
92  *          index into list (base 0) on success
93  */
94 int do_keyword_prompt(UAContext *ua, char *msg, char **list)
95 {
96    int i;
97    start_prompt(ua, _("You have the following choices:\n"));
98    for (i=0; list[i]; i++) {
99       add_prompt(ua, list[i]);
100    }
101    return do_prompt(ua, msg, NULL, 0);
102 }
103
104
105 /* 
106  * Select a Storage resource from prompt list
107  */
108 STORE *select_storage_resource(UAContext *ua)
109 {
110    char name[MAX_NAME_LENGTH];    
111    STORE *store = NULL;
112
113    start_prompt(ua, _("The defined Storage resources are:\n"));
114    LockRes();
115    while ((store = (STORE *)GetNextRes(R_STORAGE, (RES *)store))) {
116       add_prompt(ua, store->hdr.name);
117    }
118    UnlockRes();
119    do_prompt(ua, _("Select Storage resource"), name, sizeof(name));
120    store = (STORE *)GetResWithName(R_STORAGE, name);
121    return store;
122 }
123
124 /* 
125  * Select a FileSet resource from prompt list
126  */
127 FILESET *select_fileset_resource(UAContext *ua)
128 {
129    char name[MAX_NAME_LENGTH];    
130    FILESET *fs = NULL;
131
132    start_prompt(ua, _("The defined FileSet resources are:\n"));
133    LockRes();
134    while ((fs = (FILESET *)GetNextRes(R_FILESET, (RES *)fs))) {
135       add_prompt(ua, fs->hdr.name);
136    }
137    UnlockRes();
138    do_prompt(ua, _("Select FileSet resource"), name, sizeof(name));
139    fs = (FILESET *)GetResWithName(R_FILESET, name);
140    return fs;
141 }
142
143
144 /* 
145  * Get a catalog resource from prompt list
146  */
147 CAT *get_catalog_resource(UAContext *ua)
148 {
149    char name[MAX_NAME_LENGTH];    
150    CAT *catalog = NULL;
151    int i;
152
153    for (i=1; i<ua->argc; i++) {
154       if (strcasecmp(ua->argk[i], _("catalog")) == 0 && ua->argv[i]) {
155          catalog = (CAT *)GetResWithName(R_CATALOG, ua->argv[i]);
156          break;
157       }
158    }
159    if (!catalog) {
160       start_prompt(ua, _("The defined Catalog resources are:\n"));
161       LockRes();
162       while ((catalog = (CAT *)GetNextRes(R_CATALOG, (RES *)catalog))) {
163          add_prompt(ua, catalog->hdr.name);
164       }
165       UnlockRes();
166       do_prompt(ua, _("Select Catalog resource"), name, sizeof(name));
167       catalog = (CAT *)GetResWithName(R_CATALOG, name);
168    }
169    return catalog;
170 }
171
172
173 /* 
174  * Select a Job resource from prompt list
175  */
176 JOB *select_job_resource(UAContext *ua)
177 {
178    char name[MAX_NAME_LENGTH];    
179    JOB *job = NULL;
180
181    start_prompt(ua, _("The defined Job resources are:\n"));
182    LockRes();
183    while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) {
184       add_prompt(ua, job->hdr.name);
185    }
186    UnlockRes();
187    do_prompt(ua, _("Select Job resource"), name, sizeof(name));
188    job = (JOB *)GetResWithName(R_JOB, name);
189    return job;
190 }
191
192 /* 
193  * Select a Restore Job resource from prompt list
194  */
195 JOB *select_restore_job_resource(UAContext *ua)
196 {
197    char name[MAX_NAME_LENGTH];    
198    JOB *job = NULL;
199
200    start_prompt(ua, _("The defined Restore Job resources are:\n"));
201    LockRes();
202    while ( (job = (JOB *)GetNextRes(R_JOB, (RES *)job)) ) {
203       if (job->JobType == JT_RESTORE) {
204          add_prompt(ua, job->hdr.name);
205       }
206    }
207    UnlockRes();
208    do_prompt(ua, _("Select Restore Job"), name, sizeof(name));
209    job = (JOB *)GetResWithName(R_JOB, name);
210    return job;
211 }
212
213
214
215 /* 
216  * Select a client resource from prompt list
217  */
218 CLIENT *select_client_resource(UAContext *ua)
219 {
220    char name[MAX_NAME_LENGTH];    
221    CLIENT *client = NULL;
222
223    start_prompt(ua, _("The defined Client resources are:\n"));
224    LockRes();
225    while ( (client = (CLIENT *)GetNextRes(R_CLIENT, (RES *)client)) ) {
226       add_prompt(ua, client->hdr.name);
227    }
228    UnlockRes();
229    do_prompt(ua, _("Select Client (File daemon) resource"), name, sizeof(name));
230    client = (CLIENT *)GetResWithName(R_CLIENT, name);
231    return client;
232 }
233
234 /*
235  *  Get client resource, start by looking for
236  *   client=<client-name>
237  *  if we don't find the keyword, we prompt the user.
238  */
239 CLIENT *get_client_resource(UAContext *ua)
240 {
241    CLIENT *client = NULL;
242    int i;
243    
244    for (i=1; i<ua->argc; i++) {
245       if (strcasecmp(ua->argk[i], _("client")) == 0 && ua->argv[i]) {
246          client = (CLIENT *)GetResWithName(R_CLIENT, ua->argv[i]);
247          if (client) {
248             return client;
249          }
250          bsendmsg(ua, _("Error: Client resource %s does not exist.\n"), ua->argv[i]);
251          break;
252       }
253    }
254    return select_client_resource(ua);
255 }
256
257 /* Scan what the user has entered looking for:
258  * 
259  *  client=<client-name>
260  *
261  *  if error or not found, put up a list of client DBRs
262  *  to choose from.
263  *
264  *   returns: 0 on error
265  *            1 on success and fills in CLIENT_DBR
266  */
267 int get_client_dbr(UAContext *ua, CLIENT_DBR *cr)
268 {
269    int i;
270
271    if (cr->Name[0]) {                 /* If name already supplied */
272       if (db_get_client_record(ua->jcr, ua->db, cr)) {
273          return 1;
274       }
275       bsendmsg(ua, _("Could not find Client %s: ERR=%s"), cr->Name, db_strerror(ua->db));
276    }
277    for (i=1; i<ua->argc; i++) {
278       if (strcasecmp(ua->argk[i], _("client")) == 0 && ua->argv[i]) {
279          bstrncpy(cr->Name, ua->argv[i], sizeof(cr->Name));
280          if (!db_get_client_record(ua->jcr, ua->db, cr)) {
281             bsendmsg(ua, _("Could not find Client %s: ERR=%s"), ua->argv[i],
282                      db_strerror(ua->db));
283             cr->ClientId = 0;
284             break;
285          }
286          return 1;
287       }
288    }
289    if (!select_client_dbr(ua, cr)) {  /* try once more by proposing a list */
290       return 0;
291    }
292    return 1;
293 }
294
295 /*
296  * Select a Client record from the catalog
297  *  Returns 1 on success
298  *          0 on failure
299  */
300 int select_client_dbr(UAContext *ua, CLIENT_DBR *cr)
301 {
302    CLIENT_DBR ocr;
303    char name[MAX_NAME_LENGTH];
304    int num_clients, i;
305    uint32_t *ids; 
306
307
308    cr->ClientId = 0;
309    if (!db_get_client_ids(ua->jcr, ua->db, &num_clients, &ids)) {
310       bsendmsg(ua, _("Error obtaining client ids. ERR=%s\n"), db_strerror(ua->db));
311       return 0;
312    }
313    if (num_clients <= 0) {
314       bsendmsg(ua, _("No clients defined. Run a job to create one.\n"));
315       return 0;
316    }
317      
318    start_prompt(ua, _("Defined Clients:\n"));
319    for (i=0; i < num_clients; i++) {
320       ocr.ClientId = ids[i];
321       if (!db_get_client_record(ua->jcr, ua->db, &ocr)) {
322          continue;
323       }
324       add_prompt(ua, ocr.Name);
325    }
326    free(ids);
327    if (do_prompt(ua, _("Select the Client"), name, sizeof(name)) < 0) {
328       return 0;
329    }
330    memset(&ocr, 0, sizeof(ocr));
331    bstrncpy(ocr.Name, name, sizeof(ocr.Name));
332
333    if (!db_get_client_record(ua->jcr, ua->db, &ocr)) {
334       bsendmsg(ua, _("Could not find Client %s: ERR=%s"), name, db_strerror(ua->db));
335       return 0;
336    }
337    memcpy(cr, &ocr, sizeof(ocr));
338    return 1;
339 }
340
341
342
343 /* Scan what the user has entered looking for:
344  * 
345  *  pool=<pool-name>   
346  *
347  *  if error or not found, put up a list of pool DBRs
348  *  to choose from.
349  *
350  *   returns: 0 on error
351  *            1 on success and fills in POOL_DBR
352  */
353 int get_pool_dbr(UAContext *ua, POOL_DBR *pr)
354 {
355    int i;
356
357    if (pr->Name[0]) {                 /* If name already supplied */
358       if (db_get_pool_record(ua->jcr, ua->db, pr)) {
359          return pr->PoolId;
360       }
361       bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), pr->Name, db_strerror(ua->db));
362    }
363    for (i=1; i<ua->argc; i++) {
364       if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i]) {
365          bstrncpy(pr->Name, ua->argv[i], sizeof(pr->Name));
366          if (!db_get_pool_record(ua->jcr, ua->db, pr)) {
367             bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), ua->argv[i],
368                      db_strerror(ua->db));
369             pr->PoolId = 0;
370             break;
371          }
372          return pr->PoolId;
373       }
374    }
375    if (!select_pool_dbr(ua, pr)) {  /* try once more */
376       return 0;
377    }
378    return 1;
379 }
380
381 /*
382  * Select a Pool record from the catalog
383  */
384 int select_pool_dbr(UAContext *ua, POOL_DBR *pr)
385 {
386    POOL_DBR opr;
387    char name[MAX_NAME_LENGTH];
388    int num_pools, i;
389    uint32_t *ids; 
390
391
392    pr->PoolId = 0;
393    if (!db_get_pool_ids(ua->jcr, ua->db, &num_pools, &ids)) {
394       bsendmsg(ua, _("Error obtaining pool ids. ERR=%s\n"), db_strerror(ua->db));
395       return 0;
396    }
397    if (num_pools <= 0) {
398       bsendmsg(ua, _("No pools defined. Use the \"create\" command to create one.\n"));
399       return 0;
400    }
401      
402    start_prompt(ua, _("Defined Pools:\n"));
403    for (i=0; i < num_pools; i++) {
404       opr.PoolId = ids[i];
405       if (!db_get_pool_record(ua->jcr, ua->db, &opr)) {
406          continue;
407       }
408       add_prompt(ua, opr.Name);
409    }
410    free(ids);
411    if (do_prompt(ua, _("Select the Pool"), name, sizeof(name)) < 0) {
412       return 0;
413    }
414    memset(&opr, 0, sizeof(opr));
415    bstrncpy(opr.Name, name, sizeof(opr.Name));
416
417    if (!db_get_pool_record(ua->jcr, ua->db, &opr)) {
418       bsendmsg(ua, _("Could not find Pool %s: ERR=%s"), name, db_strerror(ua->db));
419       return 0;
420    }
421    memcpy(pr, &opr, sizeof(opr));
422    return 1;
423 }
424
425 /*
426  * Select a Pool and a Media (Volume) record from the database
427  */
428 int select_pool_and_media_dbr(UAContext *ua, POOL_DBR *pr, MEDIA_DBR *mr)
429 {
430    int i;
431    static char *kw[] = {
432       N_("volume"),
433       NULL};
434
435    memset(pr, 0, sizeof(POOL_DBR));
436    memset(mr, 0, sizeof(MEDIA_DBR));
437
438    /* Get the pool, possibly from pool=<pool-name> */
439    if (!get_pool_dbr(ua, pr)) {
440       return 0;
441    }
442    mr->PoolId = pr->PoolId;
443
444    i = find_arg_keyword(ua, kw);
445    if (i == 0 && ua->argv[i]) {
446       bstrncpy(mr->VolumeName, ua->argv[i], sizeof(mr->VolumeName));
447    }
448    if (mr->VolumeName[0] == 0) {
449       db_list_media_records(ua->jcr, ua->db, mr, prtit, ua);
450       if (!get_cmd(ua, _("Enter MediaId or Volume name: "))) {
451          return 0;
452       }
453       if (is_a_number(ua->cmd)) {
454          mr->MediaId = atoi(ua->cmd);
455       } else {
456          bstrncpy(mr->VolumeName, ua->cmd, sizeof(mr->VolumeName));
457       }
458    }
459
460    if (!db_get_media_record(ua->jcr, ua->db, mr)) {
461       bsendmsg(ua, "%s", db_strerror(ua->db));
462       return 0;
463    }
464    return 1;
465 }
466
467
468 /* 
469  * Select a pool resource from prompt list
470  */
471 POOL *select_pool_resource(UAContext *ua)
472 {
473    char name[MAX_NAME_LENGTH];    
474    POOL *pool = NULL;
475
476    start_prompt(ua, _("The defined Pool resources are:\n"));
477    LockRes();
478    while ((pool = (POOL *)GetNextRes(R_POOL, (RES *)pool))) {
479       add_prompt(ua, pool->hdr.name);
480    }
481    UnlockRes();
482    do_prompt(ua, _("Select Pool resource"), name, sizeof(name));
483    pool = (POOL *)GetResWithName(R_POOL, name);
484    return pool;
485 }
486
487
488 /*
489  *  If you are thinking about using it, you
490  *  probably want to use select_pool_dbr() 
491  *  or get_pool_dbr() above.
492  */
493 POOL *get_pool_resource(UAContext *ua)
494 {
495    POOL *pool = NULL;
496    int i;
497    
498    for (i=1; i<ua->argc; i++) {
499       if (strcasecmp(ua->argk[i], _("pool")) == 0 && ua->argv[i]) {
500          pool = (POOL *)GetResWithName(R_POOL, ua->argv[i]);
501          if (pool) {
502             return pool;
503          }
504          bsendmsg(ua, _("Error: Pool resource %s does not exist.\n"), ua->argv[i]);
505          break;
506       }
507    }
508    return select_pool_resource(ua);
509 }
510
511 /*
512  * List all jobs and ask user to select one
513  */
514 int select_job_dbr(UAContext *ua, JOB_DBR *jr)
515 {
516    db_list_job_records(ua->jcr, ua->db, jr, prtit, ua);
517    if (!get_cmd(ua, _("Enter the JobId to select: "))) {
518       return 0;
519    }
520    jr->JobId = atoi(ua->cmd);
521    if (!db_get_job_record(ua->jcr, ua->db, jr)) {
522       bsendmsg(ua, "%s", db_strerror(ua->db));
523       return 0;
524    }
525    return jr->JobId;
526
527 }
528
529
530 /* Scan what the user has entered looking for:
531  * 
532  *  jobid=nn
533  *
534  *  if error or not found, put up a list of Jobs
535  *  to choose from.
536  *
537  *   returns: 0 on error
538  *            JobId on success and fills in JOB_DBR
539  */
540 int get_job_dbr(UAContext *ua, JOB_DBR *jr)
541 {
542    int i;
543
544    for (i=1; i<ua->argc; i++) {
545       if (strcasecmp(ua->argk[i], _("job")) == 0 && ua->argv[i]) {
546          jr->JobId = 0;
547          bstrncpy(jr->Job, ua->argv[i], sizeof(jr->Job));
548       } else if (strcasecmp(ua->argk[i], _("jobid")) == 0 && ua->argv[i]) {
549          jr->JobId = atoi(ua->argv[i]);
550       } else {
551          continue;
552       }
553       if (!db_get_job_record(ua->jcr, ua->db, jr)) {
554          bsendmsg(ua, _("Could not find Job %s: ERR=%s"), ua->argv[i],
555                   db_strerror(ua->db));
556          jr->JobId = 0;
557          break;
558       }
559       return jr->JobId;
560    }
561
562    if (!select_job_dbr(ua, jr)) {  /* try once more */
563       return 0;
564    }
565    return jr->JobId;
566 }
567
568 /*
569  * Implement unique set of prompts 
570  */
571 void start_prompt(UAContext *ua, char *msg)
572 {
573   if (ua->max_prompts == 0) {
574      ua->max_prompts = 10;
575      ua->prompt = (char **)bmalloc(sizeof(char *) * ua->max_prompts);
576   }
577   ua->num_prompts = 1;
578   ua->prompt[0] = bstrdup(msg);
579 }
580
581 /*
582  * Add to prompts -- keeping them unique 
583  */
584 void add_prompt(UAContext *ua, char *prompt)
585 {
586    int i;
587    if (ua->num_prompts == ua->max_prompts) {
588       ua->max_prompts *= 2;
589       ua->prompt = (char **)brealloc(ua->prompt, sizeof(char *) *
590          ua->max_prompts);
591     }
592     for (i=1; i < ua->num_prompts; i++) {
593        if (strcmp(ua->prompt[i], prompt) == 0) {
594           return;
595        }
596     }
597     ua->prompt[ua->num_prompts++] = bstrdup(prompt);
598 }
599
600 /*
601  * Display prompts and get user's choice
602  *
603  *  Returns: -1 on error
604  *            index base 0 on success, and choice
605  *               is copied to prompt if not NULL
606  */
607 int do_prompt(UAContext *ua, char *msg, char *prompt, int max_prompt)
608 {
609    int i, item;
610    char pmsg[MAXSTRING];
611
612    bsendmsg(ua, ua->prompt[0]);
613    for (i=1; i < ua->num_prompts; i++) {
614       bsendmsg(ua, "%6d: %s\n", i, ua->prompt[i]);
615    }
616
617    if (prompt) {
618       *prompt = 0;
619    }
620
621    for ( ;; ) {
622       /* First item is the prompt string, not the items */
623       if (ua->num_prompts == 1) { 
624          item = 0;                    /* list is empty ! */
625          break;
626       }
627       if (ua->num_prompts == 2) {
628          item = 1;
629          bsendmsg(ua, _("Item 1 selected automatically.\n"));
630          if (prompt) {
631             bstrncpy(prompt, ua->prompt[1], max_prompt);
632          }
633          break;
634       } else {
635          sprintf(pmsg, "%s (1-%d): ", msg, ua->num_prompts-1);
636       }
637       /* Either a . or an @ will get you out of the loop */
638       if (!get_cmd(ua, pmsg) || *ua->cmd == '.' || *ua->cmd == '@') {
639          item = -1;                   /* error */
640          bsendmsg(ua, _("Selection aborted, nothing done.\n"));
641          break;
642       }
643       item = atoi(ua->cmd);
644       if (item < 1 || item >= ua->num_prompts) {
645          bsendmsg(ua, _("Please enter a number between 1 and %d\n"), ua->num_prompts-1);
646          continue;
647       }
648       if (prompt) {
649          bstrncpy(prompt, ua->prompt[item], max_prompt);
650       }
651       break;
652    }
653                               
654    for (i=0; i < ua->num_prompts; i++) {
655       free(ua->prompt[i]);
656    }
657    ua->num_prompts = 0;
658    return item - 1;
659 }
660
661
662 /*
663  * We scan what the user has entered looking for
664  *    <storage-resource>
665  *    device=<device-name>      ???? does this work ????
666  *    storage=<storage-resource>
667  *    job=<job_name>
668  *    jobid=<jobid>
669  *    ?              (prompt him with storage list)
670  *    <some-error>   (prompt him with storage list)
671  */
672 STORE *get_storage_resource(UAContext *ua, char *cmd)
673 {
674    char *store_name, *device_name;
675    STORE *store;
676    int jobid;
677    JCR *jcr;
678    int i;
679       
680    if (ua->argc == 1) {
681       return select_storage_resource(ua);
682    }
683    
684    device_name = NULL;
685    store_name = NULL;
686
687    for (i=1; i<ua->argc; i++) {
688       if (!ua->argv[i]) {
689          /* Default argument is storage */
690          if (store_name) {
691             bsendmsg(ua, _("Storage name given twice.\n"));
692             return NULL;
693          }
694          store_name = ua->argk[i];
695          if (*store_name == '?') {
696             return select_storage_resource(ua);
697          }
698       } else {
699          if (strcasecmp(ua->argk[i], _("device")) == 0) {
700             device_name = ua->argv[i];
701
702          } else if (strcasecmp(ua->argk[i], _("storage")) == 0) {
703             store_name = ua->argv[i];
704
705          } else if (strcasecmp(ua->argk[i], _("jobid")) == 0) {
706             jobid = atoi(ua->argv[i]);
707             if (jobid <= 0) {
708                bsendmsg(ua, _("Expecting jobid=nn command, got: %s\n"), ua->argk[i]);
709                return NULL;
710             }
711             if (!(jcr=get_jcr_by_id(jobid))) {
712                bsendmsg(ua, _("JobId %d is not running.\n"), jobid);
713                return NULL;
714             }
715             store = jcr->store;
716             free_jcr(jcr);
717             return store;
718
719          } else if (strcasecmp(ua->argk[i], _("job")) == 0) {
720             if (!(jcr=get_jcr_by_partial_name(ua->argv[i]))) {
721                bsendmsg(ua, _("Job %s is not running.\n"), ua->argv[i]);
722                return NULL;
723             }
724             store = jcr->store;
725             free_jcr(jcr);
726             return store;
727
728          } else {
729             bsendmsg(ua, _("Unknown keyword: %s\n"), ua->argk[i]);
730             return NULL;
731          }
732       }
733    }
734
735    if (!store_name) {
736      bsendmsg(ua, _("A storage device name must be given.\n"));
737      store = NULL;
738    } else {
739       store = (STORE *)GetResWithName(R_STORAGE, store_name);
740       if (!store) {
741          bsendmsg(ua, "Storage resource %s: not found\n", store_name);
742       }
743    }
744    if (!store) {
745       store = select_storage_resource(ua);
746    }
747    return store;
748 }
749
750
751 /*
752  * Scan looking for mediatype= 
753  *
754  *  if not found or error, put up selection list
755  *
756  *  Returns: 0 on error
757  *           1 on success, MediaType is set
758  */
759 int get_media_type(UAContext *ua, char *MediaType, int max_media)
760 {
761    STORE *store;
762    int i;
763    static char *keyword[] = {
764       "mediatype",
765       NULL};
766
767    i = find_arg_keyword(ua, keyword);
768    if (i >= 0 && ua->argv[i]) {
769       bstrncpy(MediaType, ua->argv[i], max_media);
770       return 1;
771    }
772
773    start_prompt(ua, _("Media Types defined in conf file:\n"));
774    LockRes();
775    for (store = NULL; (store = (STORE *)GetNextRes(R_STORAGE, (RES *)store)); ) {
776       add_prompt(ua, store->media_type);
777    }
778    UnlockRes();
779    return (do_prompt(ua, _("Select the Media Type"), MediaType, max_media) < 0) ? 0 : 1;
780 }