Annotation of sbbs/src/sbbs3/js_client.c, revision 1.1

1.1     ! root        1: /* js_client.c */
        !             2: 
        !             3: /* Synchronet JavaScript "Client" Object */
        !             4: 
        !             5: /* $Id: js_client.c,v 1.15 2005/12/13 02:24:49 rswindell Exp $ */
        !             6: 
        !             7: /****************************************************************************
        !             8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
        !             9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
        !            10:  *                                                                                                                                                     *
        !            11:  * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html         *
        !            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                         *
        !            15:  * as published by the Free Software Foundation; either version 2                      *
        !            16:  * of the License, or (at your option) any later version.                                      *
        !            17:  * See the GNU General Public License for more details: gpl.txt or                     *
        !            18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
        !            19:  *                                                                                                                                                     *
        !            20:  * Anonymous FTP access to the most recent released source is available at     *
        !            21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
        !            22:  *                                                                                                                                                     *
        !            23:  * Anonymous CVS access to the development source and modification history     *
        !            24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
        !            25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
        !            26:  *     (just hit return, no password is necessary)                                                     *
        !            27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
        !            28:  *                                                                                                                                                     *
        !            29:  * For Synchronet coding style and modification guidelines, see                                *
        !            30:  * http://www.synchro.net/source.html                                                                          *
        !            31:  *                                                                                                                                                     *
        !            32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
        !            33:  * format) via e-mail to [email protected]                                                                      *
        !            34:  *                                                                                                                                                     *
        !            35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
        !            36:  ****************************************************************************/
        !            37: 
        !            38: #include "sbbs.h"
        !            39: 
        !            40: #ifdef JAVASCRIPT
        !            41: 
        !            42: /* Client Object Properites */
        !            43: enum {
        !            44:         CLIENT_PROP_ADDR               /* IP address */
        !            45:        ,CLIENT_PROP_HOST               /* host name */
        !            46:        ,CLIENT_PROP_PORT               /* TCP port number */
        !            47:        ,CLIENT_PROP_TIME               /* connect time */
        !            48:        ,CLIENT_PROP_PROTOCOL   /* protocol description */
        !            49:        ,CLIENT_PROP_USER               /* user name */
        !            50: };
        !            51: 
        !            52: #ifdef BUILD_JSDOCS
        !            53:        static char* client_prop_desc[] = {
        !            54:         "client's IP address (in dotted-decimal format)"
        !            55:        ,"client's host name (up to 64 characters)"
        !            56:        ,"client's TCP or UDP port number"
        !            57:        ,"date/time of initial connection (in time_t format)"
        !            58:        ,"protocol description (e.g. 'Telnet', 'FTP', etc.)"
        !            59:        ,"user's name/alias (if logged in)"
        !            60:        /* this next one must be last */
        !            61:        ,"instance of <a href=#Socket>Socket class</a> representing client's TCP/IP connection"
        !            62:        ,NULL
        !            63:        };
        !            64: #endif
        !            65: 
        !            66: static JSBool js_client_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
        !            67: {
        !            68:        return(JS_FALSE);
        !            69: }
        !            70: 
        !            71: static JSBool js_client_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
        !            72: {
        !            73:        char*           p=NULL;
        !            74:        ulong           val=0;
        !            75:     jsint       tiny;
        !            76:        JSString*       js_str;
        !            77:        client_t*       client;
        !            78: 
        !            79:        if((client=(client_t*)JS_GetPrivate(cx,obj))==NULL)
        !            80:                return(JS_FALSE);
        !            81: 
        !            82:     tiny = JSVAL_TO_INT(id);
        !            83: 
        !            84:        switch(tiny) {
        !            85:                case CLIENT_PROP_ADDR: 
        !            86:                        p=client->addr;
        !            87:                        break;
        !            88:                case CLIENT_PROP_HOST:
        !            89:                        p=client->host;
        !            90:                        break;
        !            91:                case CLIENT_PROP_PORT:
        !            92:                        val=client->port;
        !            93:                        break;
        !            94:                case CLIENT_PROP_TIME:
        !            95:                        val=client->time;
        !            96:                        break;
        !            97:                case CLIENT_PROP_PROTOCOL:
        !            98:                        p=(char*)client->protocol;
        !            99:                        break;
        !           100:                case CLIENT_PROP_USER:
        !           101:                        p=client->user;
        !           102:                        break;
        !           103:                default:
        !           104:                        return(JS_TRUE);
        !           105:        }
        !           106:        if(p!=NULL) {
        !           107:                if((js_str=JS_NewStringCopyZ(cx, p))==NULL)
        !           108:                        return(JS_FALSE);
        !           109:                *vp = STRING_TO_JSVAL(js_str);
        !           110:        } else
        !           111:                *vp = INT_TO_JSVAL(val);
        !           112: 
        !           113:        return(JS_TRUE);
        !           114: }
        !           115: 
        !           116: #define CLIENT_PROP_FLAGS JSPROP_ENUMERATE|JSPROP_READONLY
        !           117: 
        !           118: static jsSyncPropertySpec js_client_properties[] = {
        !           119: /*              name                           ,tinyid                                 ,flags,                                 ver     */
        !           120: 
        !           121:        {       "ip_address"            ,CLIENT_PROP_ADDR               ,CLIENT_PROP_FLAGS,             310},
        !           122:        {       "host_name"                     ,CLIENT_PROP_HOST               ,CLIENT_PROP_FLAGS,             310},
        !           123:        {       "port"                          ,CLIENT_PROP_PORT               ,CLIENT_PROP_FLAGS,             310},
        !           124:        {       "connect_time"          ,CLIENT_PROP_TIME               ,CLIENT_PROP_FLAGS,             310},
        !           125:        {       "protocol"                      ,CLIENT_PROP_PROTOCOL   ,CLIENT_PROP_FLAGS,             310},
        !           126:        {       "user_name"                     ,CLIENT_PROP_USER               ,CLIENT_PROP_FLAGS,             310},
        !           127:        {0}
        !           128: };
        !           129: 
        !           130: static JSClass js_client_class = {
        !           131:      "Client"                          /* name                 */
        !           132:     ,JSCLASS_HAS_PRIVATE       /* flags                */
        !           133:        ,JS_PropertyStub                /* addProperty  */
        !           134:        ,JS_PropertyStub                /* delProperty  */
        !           135:        ,js_client_get                  /* getProperty  */
        !           136:        ,js_client_set                  /* setProperty  */
        !           137:        ,JS_EnumerateStub               /* enumerate    */
        !           138:        ,JS_ResolveStub                 /* resolve              */
        !           139:        ,JS_ConvertStub                 /* convert              */
        !           140:        ,JS_FinalizeStub                /* finalize             */
        !           141: };
        !           142: 
        !           143: JSObject* DLLCALL js_CreateClientObject(JSContext* cx, JSObject* parent
        !           144:                                                                                ,char* name, client_t* client, SOCKET sock)
        !           145: {
        !           146:        JSObject*       obj;
        !           147: 
        !           148:        obj = JS_DefineObject(cx, parent, name, &js_client_class, NULL
        !           149:                ,JSPROP_ENUMERATE|JSPROP_READONLY);
        !           150: 
        !           151:        if(obj==NULL)
        !           152:                return(NULL);
        !           153: 
        !           154:        JS_SetPrivate(cx, obj, client); /* Store a pointer to client_t */
        !           155: 
        !           156:        js_DefineSyncProperties(cx, obj, js_client_properties);
        !           157: 
        !           158:        js_CreateSocketObject(cx, obj, "socket", sock);
        !           159: 
        !           160: #ifdef BUILD_JSDOCS
        !           161:        js_DescribeSyncObject(cx,obj,"Represents a TCP/IP client session",310);
        !           162:        js_CreateArrayOfStrings(cx, obj, "_property_desc_list", client_prop_desc, JSPROP_READONLY);
        !           163: #endif
        !           164: 
        !           165:        return(obj);
        !           166: }
        !           167: 
        !           168: #endif /* JAVSCRIPT */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.