-add Networkbrowser and Mountmanager to easy browse network for networkdevices and...
[enigma2-plugins.git] / networkbrowser / src / lib / main.c
1 /*###########################################################################\r
2 #\r
3 # Copyright (C) 2007 - 2009 by\r
4 # nixkoenner <nixkoenner@newnigma2.to>\r
5 # License: GPL\r
6 #\r
7 # This program is free software; you can redistribute it and/or modify\r
8 # it under the terms of the GNU General Public License as published by\r
9 # the Free Software Foundation; either version 2 of the License, or\r
10 # (at your option) any later version.\r
11 #\r
12 # This program is distributed in the hope that it will be useful,\r
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
15 # GNU General Public License for more details.\r
16 #\r
17 # You should have received a copy of the GNU General Public License\r
18 # along with this program; if not, write to the Free Software\r
19 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
20 #\r
21 ###########################################################################*/\r
22 \r
23 #include <Python.h>\r
24 #include <stdio.h>\r
25 #include <stdlib.h>\r
26 \r
27 #include "nbtscan.h"\r
28 #include "smbinfo.h"\r
29 #include "showmount.h"\r
30 \r
31 static PyObject *error;\r
32 \r
33 PyObject *_netzInfo(PyObject *self, PyObject *args)\r
34 {\r
35         netinfo *nInfo;\r
36         char *s;\r
37         PyObject *plist, *name, *ip, *service, *mac, *result, *domain, *host;\r
38         int i;\r
39 \r
40         if(!PyArg_ParseTuple(args, "s", &s)) {\r
41                 PyErr_SetString(error, "netzInfo(ip/24)");\r
42                 return NULL;\r
43         }\r
44 \r
45         if(!(plist= PyList_New(0)))  return NULL;\r
46         if(!(result= PyList_New(0)))  return NULL;\r
47         nInfo = newNetInfo();\r
48         netzInfo(s, nInfo);\r
49         for (i=0; i<256; i++) \r
50         { \r
51                 if(nInfo[i].ip[0] == '\0') {\r
52                         break;\r
53                 }\r
54                 else\r
55                 {\r
56                         host = Py_BuildValue("s", "host");\r
57                         service = Py_BuildValue("s", nInfo[i].service);\r
58                         domain = Py_BuildValue("s", nInfo[i].domain);\r
59                         ip = Py_BuildValue("s", nInfo[i].ip);\r
60                         name = Py_BuildValue("s", nInfo[i].name); \r
61                         mac = Py_BuildValue("s", nInfo[i].mac);\r
62                         PyList_Append(plist, host);\r
63                         PyList_Append(plist, name);\r
64                         PyList_Append(plist, ip);\r
65                         PyList_Append(plist, mac);\r
66                         PyList_Append(plist, domain);\r
67                         PyList_Append(plist, service);\r
68                         PyList_Append(result, plist);\r
69                         if(!(plist= PyList_New(0)))  return NULL;\r
70                         \r
71                 }\r
72         } \r
73         freeNetInfo(nInfo);\r
74         return result;\r
75         //return Py_BuildValue("s", nInfo[0].name);\r
76 }\r
77 \r
78 PyObject *_nfsShare(PyObject *self, PyObject *args)\r
79 {\r
80         nfsinfo *nfsInfo;\r
81         char *s;\r
82         char *r;\r
83         PyObject *plist, *result, *share, *ip, *nfsShare, *rech, *rechip, *leer;\r
84         int i = 0;\r
85         int err = 0;\r
86 \r
87         if(!PyArg_ParseTuple(args, "ss", &s, &r)) {\r
88                 PyErr_SetString(error, "nfsShare(ip,rechnername)");\r
89                 return NULL;\r
90         }\r
91 \r
92         if(!(plist= PyList_New(0)))  return NULL;\r
93         if(!(result= PyList_New(0)))  return NULL;\r
94 \r
95         nfsInfo = newNfsInfo();\r
96         err = showNfsShare(s, nfsInfo);\r
97         if (err == 0)\r
98         {\r
99                 for (i=0; i<256; i++) \r
100                 { \r
101                         if(nfsInfo[i].ip[0] == '\0') {\r
102                                 break;\r
103                         }\r
104                         else\r
105                         {\r
106                                 ip = Py_BuildValue("s", nfsInfo[i].ip);\r
107                                 share = Py_BuildValue("s", nfsInfo[i].share);\r
108                                 nfsShare = Py_BuildValue("s", "nfsShare");\r
109                                 rech = Py_BuildValue("s",r);\r
110                                 rechip = Py_BuildValue("s",s);\r
111                                 leer = Py_BuildValue("s","");\r
112                                 PyList_Append(plist, nfsShare);\r
113                                 PyList_Append(plist, rech);\r
114                                 PyList_Append(plist, rechip);\r
115                                 PyList_Append(plist, ip);\r
116                                 PyList_Append(plist, share);\r
117                                 PyList_Append(plist, leer);\r
118                                 PyList_Append(result, plist);\r
119                                 if(!(plist= PyList_New(0)))  return NULL;               \r
120                         }\r
121                 }\r
122         }\r
123         else\r
124         {\r
125                 share = Py_BuildValue("s", nfsInfo[0].share);\r
126                 PyList_Append(plist, share);\r
127                 PyList_Append(result, plist);\r
128                 if(!(plist= PyList_New(0)))  return NULL;\r
129         }\r
130         freeNfsInfo(nfsInfo);   \r
131         return result;\r
132 }\r
133 \r
134 PyObject *_smbShare(PyObject *self, PyObject *args)\r
135 {\r
136         int i = 0;\r
137         char *s;\r
138         char *r;\r
139         char *u;\r
140         char *p;\r
141         shareinfo *sInfo;\r
142         PyObject *plist, *name, *typ, *comment, *result, *smbShare, *rech, *rechip;\r
143 \r
144         \r
145         if(!PyArg_ParseTuple(args, "ssss", &s,&r,&u,&p)) {\r
146                 PyErr_SetString(error, "getInfo(ip, rechnername, username, passwort)");\r
147                 return NULL;\r
148         }\r
149         if(!(plist= PyList_New(0)))  return NULL;\r
150         if(!(result= PyList_New(0)))  return NULL;\r
151 \r
152         sInfo = newShareInfo();\r
153         smbInfo(s,r,u,p,sInfo);\r
154         for (i=0; i<128; i++) \r
155         { \r
156                 if(sInfo[i].sharename[0] == '\0') {\r
157                         break;\r
158                 }\r
159                 else\r
160                 {\r
161                         name = Py_BuildValue("s", sInfo[i].sharename);\r
162                         typ = Py_BuildValue("s", sInfo[i].typ);\r
163                         comment = Py_BuildValue("s", sInfo[i].comment);\r
164                         smbShare = Py_BuildValue("s", "smbShare");\r
165                         rech = Py_BuildValue("s",r);\r
166                         rechip = Py_BuildValue("s",s);\r
167                         PyList_Append(plist, smbShare);\r
168                         PyList_Append(plist, rech);\r
169                         PyList_Append(plist, rechip);\r
170                         PyList_Append(plist, name);\r
171                         PyList_Append(plist, typ);\r
172                         PyList_Append(plist, comment);\r
173                         PyList_Append(result, plist);\r
174                         if(!(plist= PyList_New(0)))  return NULL;\r
175                 }\r
176         }\r
177         freeShareInfo(sInfo);\r
178         return result;\r
179         //return Py_BuildValue("s",s);\r
180 }\r
181 \r
182 static PyMethodDef netscanmethods[] = {\r
183         {"netzInfo", _netzInfo, METH_VARARGS},\r
184         {"smbShare", _smbShare, METH_VARARGS},\r
185         {"nfsShare", _nfsShare, METH_VARARGS},\r
186         {NULL, NULL}\r
187 };\r
188 \r
189 void initnetscan(void)\r
190 {\r
191         Py_InitModule("netscan", netscanmethods);\r
192 }\r
193 \r