source: trunk/server/examples/libsmbclient/testbrowse2.c@ 620

Last change on this file since 620 was 414, checked in by Herwig Bauernfeind, 16 years ago

Samba 3.5.0: Initial import

File size: 5.0 KB
Line 
1/*
2 * Alternate testbrowse utility provided by Mikhail Kshevetskiy.
3 * This version tests use of multiple contexts.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <malloc.h>
9#include <string.h>
10#include <libsmbclient.h>
11
12int debuglevel = 0;
13char *workgroup = "NT";
14char *username = "guest";
15char *password = "";
16
17typedef struct smbitem smbitem;
18typedef int(*qsort_cmp)(const void *, const void *);
19
20struct smbitem{
21 smbitem *next;
22 int type;
23 char name[1];
24};
25
26int smbitem_cmp(smbitem *elem1, smbitem *elem2){
27 return strcmp(elem1->name, elem2->name);
28}
29
30int smbitem_list_count(smbitem *list){
31 int count = 0;
32
33 while(list != NULL){
34 list = list->next;
35 count++;
36 }
37 return count;
38}
39
40void smbitem_list_delete(smbitem *list){
41 smbitem *elem;
42
43 while(list != NULL){
44 elem = list;
45 list = list->next;
46 free(elem);
47 }
48}
49
50smbitem* smbitem_list_sort(smbitem *list){
51 smbitem *item, **array;
52 int count, i;
53
54 if ((count = smbitem_list_count(list)) == 0) return NULL;
55 if ((array = malloc(count * sizeof(smbitem*))) == NULL){
56 smbitem_list_delete(list);
57 return NULL;
58 }
59
60 for(i = 0; i < count; i++){
61 array[i] = list;
62 list = list->next;
63 }
64 qsort(array, count, sizeof(smbitem*), (qsort_cmp)smbitem_cmp);
65
66 for(i = 0; i < count - 1; i++) array[i]->next = array[i + 1];
67 array[count - 1]->next = NULL;
68
69 list = array[0];
70 free(array);
71 return list;
72}
73
74void smbc_auth_fn(
75 const char *server,