Annotation of sbbs/sbbs3/js_server.c, revision 1.1

1.1     ! root        1: /* js_server.c */
        !             2: 
        !             3: /* Synchronet JavaScript "server" Object */
        !             4: 
        !             5: /* $Id: js_server.c,v 1.2 2003/10/27 20:48:36 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 2003 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: /* System Object Properites */
        !            41: enum {
        !            42:         SERVER_PROP_VER
        !            43:        ,SERVER_PROP_VER_DETAIL
        !            44:        ,SERVER_PROP_INTERFACE
        !            45:        ,SERVER_PROP_OPTIONS
        !            46:        ,SERVER_PROP_CLIENTS
        !            47: };
        !            48: 
        !            49: static JSBool js_server_get(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
        !            50: {
        !            51:     jsint       tiny;
        !            52:        struct in_addr in_addr;
        !            53:        js_server_props_t*      p;
        !            54: 
        !            55:        if((p=(js_server_props_t*)JS_GetPrivate(cx,obj))==NULL)
        !            56:                return(JS_FALSE);
        !            57: 
        !            58:     tiny = JSVAL_TO_INT(id);
        !            59: 
        !            60:        switch(tiny) {
        !            61:                case SERVER_PROP_VER:
        !            62:                        *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,p->version));
        !            63:                        break;
        !            64:                case SERVER_PROP_VER_DETAIL:
        !            65:                        if(p->version_detail!=NULL)
        !            66:                                *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,p->version_detail));
        !            67:                        break;
        !            68:                case SERVER_PROP_INTERFACE:
        !            69:                        if(p->interface_addr!=NULL) {
        !            70:                                in_addr.s_addr=*(p->interface_addr);
        !            71:                                in_addr.s_addr=htonl(in_addr.s_addr);
        !            72:                                *vp = STRING_TO_JSVAL(JS_NewStringCopyZ(cx,inet_ntoa(in_addr)));
        !            73:                        }
        !            74:                        break;
        !            75:                case SERVER_PROP_OPTIONS:
        !            76:                        if(p->options!=NULL)
        !            77:                                JS_NewNumberValue(cx,*p->options,vp);
        !            78:                        break;
        !            79:                case SERVER_PROP_CLIENTS:
        !            80:                        if(p->clients!=NULL)
        !            81:                                JS_NewNumberValue(cx,*p->clients,vp);
        !            82:                        break;
        !            83:        }
        !            84: 
        !            85:        return(JS_TRUE);
        !            86: }
        !            87: 
        !            88: static JSBool js_server_set(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
        !            89: {
        !            90:     jsint                              tiny;
        !            91:        js_server_props_t*      p;
        !            92: 
        !            93:        if((p=(js_server_props_t*)JS_GetPrivate(cx,obj))==NULL)
        !            94:                return(JS_FALSE);
        !            95: 
        !            96:     tiny = JSVAL_TO_INT(id);
        !            97: 
        !            98:        switch(tiny) {
        !            99:                case SERVER_PROP_OPTIONS:
        !           100:                        if(p->options!=NULL)
        !           101:                                JS_ValueToInt32(cx, *vp, (int32*)p->options);
        !           102:                        break;
        !           103:        }
        !           104: 
        !           105:        return(TRUE);
        !           106: }
        !           107: 
        !           108: 
        !           109: #define PROP_FLAGS JSPROP_ENUMERATE|JSPROP_READONLY
        !           110: 
        !           111: static jsSyncPropertySpec js_server_properties[] = {
        !           112: /*              name,                                          tinyid,                                 flags,                  ver     */
        !           113: 
        !           114:        {       "version",                                      SERVER_PROP_VER,                PROP_FLAGS,                     310 },
        !           115:        {       "version_detail",                       SERVER_PROP_VER_DETAIL, PROP_FLAGS,                     310 },
        !           116:        {       "interface_ip_address",         SERVER_PROP_INTERFACE,  PROP_FLAGS,                     311 },
        !           117:        {       "options",                                      SERVER_PROP_OPTIONS,    JSPROP_ENUMERATE,       311 },
        !           118:        {       "clients",                                      SERVER_PROP_CLIENTS,    PROP_FLAGS,                     311 },
        !           119:        {0}
        !           120: };
        !           121: 
        !           122: #ifdef _DEBUG
        !           123: static char* server_prop_desc[] = {
        !           124: 
        !           125:         "server name and version number"
        !           126:        ,"detailed version/build information"
        !           127:        ,"IP address of bound network interface (<tt>0.0.0.0</tt> = <i>ANY</i>)"
        !           128:        ,"bit-field of server-specific startup options"
        !           129:        ,"number of active clients (if available)"
        !           130:        ,NULL
        !           131: };
        !           132: #endif
        !           133: 
        !           134: 
        !           135: static JSClass js_server_class = {
        !           136:      "Server"                          /* name                 */
        !           137:     ,JSCLASS_HAS_PRIVATE       /* flags                */
        !           138:        ,JS_PropertyStub                /* addProperty  */
        !           139:        ,JS_PropertyStub                /* delProperty  */
        !           140:        ,js_server_get                  /* getProperty  */
        !           141:        ,js_server_set                  /* setProperty  */
        !           142:        ,JS_EnumerateStub               /* enumerate    */
        !           143:        ,JS_ResolveStub                 /* resolve              */
        !           144:        ,JS_ConvertStub                 /* convert              */
        !           145:        ,JS_FinalizeStub                /* finalize             */
        !           146: };
        !           147: 
        !           148: JSObject* DLLCALL js_CreateServerObject(JSContext* cx, JSObject* parent
        !           149:                                                                                ,js_server_props_t* props)
        !           150: {
        !           151:        JSObject*       obj;
        !           152: 
        !           153:        if((obj = JS_DefineObject(cx, parent, "server", &js_server_class, NULL
        !           154:                ,JSPROP_ENUMERATE|JSPROP_READONLY))==NULL)
        !           155:                return(NULL);
        !           156: 
        !           157:        if(!JS_SetPrivate(cx, obj, props))
        !           158:                return(NULL);
        !           159: 
        !           160:        if(!js_DefineSyncProperties(cx, obj, js_server_properties))
        !           161:                return(NULL);
        !           162: 
        !           163: #ifdef _DEBUG
        !           164:        js_DescribeSyncObject(cx,obj,"Server-specifc properties",310);
        !           165:        js_CreateArrayOfStrings(cx,obj,"_property_desc_list", server_prop_desc, JSPROP_READONLY);
        !           166: #endif
        !           167: 
        !           168:        return(obj);
        !           169: }
        !           170: 

unix.superglobalmegacorp.com

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