(original) (raw)
diff -Naur Python-2.2.3/Modules/socketmodule.c Python-2.2.3-affix/Modules/socketmodule.c --- Python-2.2.3/Modules/socketmodule.c 2002-11-14 04:22:34.000000000 +0200 +++ Python-2.2.3-affix/Modules/socketmodule.c 2004-01-30 18:10:49.000000000 +0200 @@ -1,3 +1,21 @@ +/* + * Affix socket module + * Socket module for python based in the original socket module for python + * This code is a copy from socket.c source code from python2.2 with updates/modifications to support affix socket interface + * + * AAA FFFFFFF FFFFFFF IIIIIII X X + * A A F F I X X + * A A F F I X X + * AAAAAAA FFFF FFFF I X X + * A A F F I X X + * A A F F IIIIIII X X + * + * Any modifications of this sourcecode must keep this information !!!!! + * + * by Carlos Chinea + * (C) Nokia Research Center, 2004 +*/ + /* Socket module */ /* SSL support based on patches by Brian E Gallew and Laszlo Kovacs */ @@ -7,7 +25,7 @@ Limitations: -- only AF_INET, AF_INET6 and AF_UNIX address families are supported in a +- only PF_AFFIX,AF_INET, AF_INET6 and AF_UNIX address families are supported in a portable manner, though AF_PACKET is supported under Linux. - no read/write operations (use sendall/recv or makefile instead) - additional restrictions apply on Windows (compensated for by socket.py) @@ -77,6 +95,13 @@ #include "Python.h" +#ifdef __ALLOW_AFFIX_ + +#include "bluetooth.h" +#include "btcore.h" + +#endif /* __ALLOW_AFFIX_ */ + /* XXX This is a terrible mess of of platform-dependent preprocessor hacks. I hope some day someone can clean this up please... */ @@ -506,6 +531,9 @@ #ifdef HAVE_NETPACKET_PACKET_H struct sockaddr_ll ll; #endif +#ifdef __ALLOW_AFFIX_ + struct sockaddr_affix affix; +#endif /* __ALLOW_AFFIX_ */ } sock_addr; } PySocketSockObject; @@ -694,7 +722,7 @@ makeipaddr(struct sockaddr *addr, int addrlen) { char buf[NI_MAXHOST]; - int error; + int error = 0; error = getnameinfo(addr, addrlen, buf, sizeof(buf), NULL, 0, NI_NUMERICHOST); @@ -782,7 +810,27 @@ a->sll_addr, a->sll_halen); } #endif - +#ifdef __ALLOW_AFFIX_ + case PF_AFFIX: + { + struct sockaddr_affix *affix= (struct sockaddr_affix *)addr; + PyObject* btaddrobj = NULL; + PyObject* ret = NULL; + char *btaddr = NULL; + + btaddr = bda2str(&affix->bda); + btaddrobj = PyString_FromString(btaddr); + ret = Py_BuildValue("iiOi", + affix->family, + affix->devnum, + btaddrobj, + affix->port); + Py_DECREF(btaddrobj); + + return ret; + } +#endif /* __ALLOW_AFFIX_ */ + /* More cases here... */ default: @@ -909,6 +957,27 @@ return 1; } #endif +#ifdef __ALLOW_AFFIX_ + case PF_AFFIX: + { + struct sockaddr_affix* affix; + char *devicebtaddr; + int port; + int devnum; + affix=(struct sockaddr_affix*)&(s->sock_addr).affix; + if (!PyArg_ParseTuple(args, "isi",&devnum,&devicebtaddr, &port)) + return 0; + affix->family = PF_AFFIX; + affix->devnum = devnum; + str2bda(&(affix->bda),devicebtaddr); + affix->port = (uint16_t)port; + *addr_ret = (struct sockaddr *) affix; + *len_ret = sizeof *affix; + return 1; + + } +#endif /* __ALLOW_AFFIX_ */ + /* More cases here... */ @@ -958,6 +1027,14 @@ return 1; } #endif +#ifdef __ALLOW_AFFIX_ + case PF_AFFIX: + { + *len_ret = sizeof (struct sockaddr_affix); + return 1; + } +#endif /* __ALLOW_AFFIX_ */ + /* More cases here... */ @@ -1714,6 +1791,32 @@ of the socket (flag == 1), or both ends (flag == 2)."; +#ifdef __ALLOW_AFFIX_ +/* PF_AFFIX extra API */ +static PyObject * +PySocketSock_l2cap_ping(PySocketSockObject *s, PyObject *arg) +{ + int res = 0, size = 0; + char *data; + + if(!PyArg_ParseTuple(arg,"s#",&data,&size)) + return NULL; + + res = l2cap_ping(s->sock_fd,data,size); + + if (res <0) + return PySocket_Err(); + + Py_INCREF(Py_None); + return Py_None; +} + +static char l2cap_ping_doc[] = +"socket.l2cap_ping(data) data -> string with the data to ping.\n\ +\n\ +Sends a *ping* packet and wait for response."; +#endif /* __ALLOW_AFFIX_ */ + /* List of methods for socket objects */ static PyMethodDef PySocketSock_methods[] = { @@ -1767,6 +1870,11 @@ {"sleeptaskw", (PyCFunction)PySocketSock_sleeptaskw, METH_VARARGS, sleeptaskw_doc}, #endif +#ifdef __ALLOW_AFFIX_ + {"l2cap_ping", (PyCFunction)PySocketSock_l2cap_ping, METH_VARARGS, + l2cap_ping_doc}, +#endif /* __ALLOW_AFFIX_ */ + {NULL, NULL} /* sentinel */ }; @@ -1892,6 +2000,7 @@ setblocking() -- set or clear the blocking I/O flag\n\ setsockopt() -- set socket options\n\ shutdown() -- shut down traffic in one or both directions\n\ +l2cap_ping() -- AFFIX: Send a ping packet and wait for response\n\ \n\ (*) not available on all platforms!)"; @@ -3178,8 +3287,14 @@ "Implementation module for socket operations. See the socket module\n\ for documentation."; + +#ifdef __ALLOW_AFFIX_ +DL_EXPORT(void) +initaffixsocket(void) +#else DL_EXPORT(void) init_socket(void) +#endif /* __ALLOW_AFFIX_ */ { PyObject *m, *d; #ifdef RISCOS @@ -3205,18 +3320,37 @@ #ifdef USE_SSL PySSL_Type.ob_type = &PyType_Type; #endif +#ifdef __ALLOW_AFFIX_ + m = Py_InitModule3("affixsocket", PySocket_methods, module_doc); +#else m = Py_InitModule3("_socket", PySocket_methods, module_doc); +#endif /* __ALLOW_AFFIX_ */ d = PyModule_GetDict(m); + +#ifdef __ALLOW_AFFIX_ + PySocket_Error = PyErr_NewException("affixsocket.error", NULL, NULL); +#else PySocket_Error = PyErr_NewException("socket.error", NULL, NULL); +#endif /* __ALLOW_AFFIX_ */ if (PySocket_Error == NULL) return; PyDict_SetItemString(d, "error", PySocket_Error); +#ifdef __ALLOW_AFFIX_ + PyH_Error = PyErr_NewException("affixsocket.herror", PySocket_Error, NULL); +#else PyH_Error = PyErr_NewException("socket.herror", PySocket_Error, NULL); +#endif /* __ALLOW_AFFIX_ */ + if (PyH_Error == NULL) return; PyDict_SetItemString(d, "herror", PyH_Error); +#ifdef __ALLOW_AFFIX_ + PyGAI_Error = PyErr_NewException("affixsocket.gaierror", PySocket_Error, + NULL); +#else PyGAI_Error = PyErr_NewException("socket.gaierror", PySocket_Error, NULL); +#endif /* __ALLOW_AFFIX_ */ if (PyGAI_Error == NULL) return; PyDict_SetItemString(d, "gaierror", PyGAI_Error); @@ -3257,7 +3391,7 @@ if (PyDict_SetItemString(d, "socket", (PyObject *)&PySocketSock_Type) != 0) return; - + /* Address families (we only support AF_INET and AF_UNIX) */ #ifdef AF_UNSPEC insint(d, "AF_UNSPEC", AF_UNSPEC); @@ -3307,6 +3441,22 @@ insint(d, "PACKET_LOOPBACK", PACKET_LOOPBACK); insint(d, "PACKET_FASTROUTE", PACKET_FASTROUTE); #endif +#ifdef __ALLOW_AFFIX_ + insint(d,"PF_AFFIX",PF_AFFIX); + insint(d,"BTPROTO_HCISCO",BTPROTO_HCISCO); + insint(d,"BTPROTO_HCIACL",BTPROTO_HCIACL); + insint(d,"BTPROTO_L2CAP",BTPROTO_L2CAP); + insint(d,"BTPROTO_RFCOMM",BTPROTO_RFCOMM); + + insint(d,"SOL_AFFIX",SOL_AFFIX); + + insint(d,"BTSO_MTU",BTSO_MTU); + insint(d,"BTSO_SECURITY",BTSO_SECURITY); + insint(d,"BTSO_EVENT_MASK",BTSO_EVENT_MASK); + insint(d,"BTSO_PKT_MASK",BTSO_PKT_MASK); + insint(d,"BTSO_PROMISC",BTSO_PROMISC); + insint(d,"BTSO_TYPE",BTSO_TYPE); +#endif /* __ALLOW_AFFIX_ */ /* Socket types */ insint(d, "SOCK_STREAM", SOCK_STREAM); @@ -3857,3 +4007,5 @@ return NULL; } #endif + + diff -Naur Python-2.2.3/configure.in Python-2.2.3-affix/configure.in --- Python-2.2.3/configure.in 2003-03-30 00:25:17.000000000 +0200 +++ Python-2.2.3-affix/configure.in 2004-01-30 18:15:01.000000000 +0200 @@ -547,6 +547,8 @@ sys/un.h sys/utsname.h sys/wait.h pty.h term.h libutil.h \ ndbm.h db1/ndbm.h gdbm/ndbm.h sys/resource.h netpacket/packet.h) +AC_CHECK_HEADERS(affix/bluetooth.h,[AC_CHECK_HEADER(affix/btcore.h,[AC_DEFINE(__ALLOW_AFFIX_)])]) + if test "$GCC" = yes then CPPFLAGS=$CPPFLAGS_save