📄 fserve.c
字号:
/* $TOG: fserve.c /main/49 1997/06/10 11:23:56 barstow $ *//*Copyright (c) 1990 X ConsortiumPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEX CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER INAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR INCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.Except as contained in this notice, the name of the X Consortium shall not beused in advertising or otherwise to promote the sale, use or other dealingsin this Software without prior written authorization from the X Consortium.*//* $XFree86: xc/lib/font/fc/fserve.c,v 3.4.2.2 1997/06/11 12:08:41 dawes Exp $ *//* * Copyright 1990 Network Computing Devices * * Permission to use, copy, modify, distribute, and sell this software and * its documentation for any purpose is hereby granted without fee, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the names of Network Computing Devices, or Digital * not be used in advertising or publicity pertaining to distribution * of the software without specific, written prior permission. * * NETWORK COMPUTING DEVICES, AND DIGITAL AND DISCLAIM ALL WARRANTIES WITH * REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NETWORK COMPUTING DEVICES, * OR DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF * THIS SOFTWARE. * * Author: Dave Lemke, Network Computing Devices, Inc *//* * font server specific font access */#ifdef WIN32#define _WILLWINSOCK_#endif#include <X11/X.h>#include <X11/Xos.h>#include "X11/Xpoll.h"#include "FS.h"#include "FSproto.h"#include "fontmisc.h"#include "fontstruct.h"#include "fservestr.h"#include <errno.h>#if defined(X_NOT_STDC_ENV) && !defined(__EMX__)extern int errno;#define Time_t longextern Time_t time ();#else#include <time.h>#define Time_t time_t#endif#ifdef NCD#include <ncd/nvram.h>#endif#ifndef NULL#define NULL 0#endif#ifndef MIN#define MIN(a,b) ((a)<(b)?(a):(b))#endif#define NONZEROMETRICS(pci) ((pci)->leftSideBearing || \ (pci)->rightSideBearing || \ (pci)->ascent || \ (pci)->descent || \ (pci)->characterWidth)extern FontPtr find_old_font();extern int _fs_build_range();static int fs_read_glyphs();static int fs_read_list();static int fs_read_list_info();static int fs_font_type;extern fd_set _fs_fd_mask;static void fs_block_handler();static int fs_wakeup();static FSFpePtr awaiting_reconnect;void _fs_connection_died();static int _fs_restart_connection();static void _fs_try_reconnect();static int fs_send_query_info();static int fs_send_query_extents();static int fs_send_query_bitmaps();static int fs_send_close_font();static void fs_client_died();static void _fs_client_access();static void _fs_client_resolution();char _fs_glyph_undefined;char _fs_glyph_requested;char _fs_glyph_zero_length;/* * Font server access * * the basic idea for the non-blocking access is to have the function * called multiple times until the actual data is returned, instead * of ClientBlocked. * * the first call to the function will cause the request to be sent to * the font server, and a block record to be stored in the fpe's list * of outstanding requests. the FS block handler also sticks the * proper set of fd's into the select mask. when data is ready to be * read in, the FS wakup handler will be hit. this will read the * data off the wire into the proper block record, and then signal the * client that caused the block so that it can restart. it will then * call the access function again, which will realize that the data has * arrived and return it. *//* XXX this should probably be a macro once its fully debugged *//* ARGSUSED */static void_fs_add_req_log(conn, opcode) FSFpePtr conn; int opcode;{#ifdef DEBUG conn->reqbuffer[conn->reqindex++] = opcode; if (conn->reqindex == REQUEST_LOG_SIZE) conn->reqindex = 0;#endif conn->current_seq++;}static Boolfs_name_check(name) char *name;{#ifdef __EMX__ /* OS/2 uses D:/XFree86/.... as fontfile pathnames, so check that * there is not only a protocol/ prefix, but also that the first chars * are not a drive letter */ if (name && isalpha(*name) && name[1] == ':') return FALSE;#endif /* Just make sure there is a protocol/ prefix */ return (name && *name != '/' && strchr(name, '/'));}static void_fs_client_resolution(conn) FSFpePtr conn;{ fsSetResolutionReq srreq; int num_res; FontResolutionPtr res; res = GetClientResolutions(&num_res); if (num_res) { srreq.reqType = FS_SetResolution; srreq.num_resolutions = num_res; srreq.length = (SIZEOF(fsSetResolutionReq) + (num_res * SIZEOF(fsResolution)) + 3) >> 2; _fs_add_req_log(conn, FS_SetResolution); if (_fs_write(conn, (char *) &srreq, SIZEOF(fsSetResolutionReq)) != -1) (void)_fs_write_pad(conn, (char *) res, (num_res * SIZEOF(fsResolution))); }}/* * sends the stuff that's meaningful to a newly opened or reset FS */static intfs_send_init_packets(conn) FSFpePtr conn;{ fsSetResolutionReq srreq; fsSetCataloguesReq screq; fsListCataloguesReq lcreq; fsListCataloguesReply lcreply; int num_cats, clen, len; char *client_cat = (char *) 0, *cp, *sp, *end; int num_res; FontResolutionPtr res; int err = Successful;#define CATALOGUE_SEP '+' res = GetClientResolutions(&num_res); if (num_res) { srreq.reqType = FS_SetResolution; srreq.num_resolutions = num_res; srreq.length = (SIZEOF(fsSetResolutionReq) + (num_res * SIZEOF(fsResolution)) + 3) >> 2; _fs_add_req_log(conn, FS_SetResolution); if (_fs_write(conn, (char *) &srreq, SIZEOF(fsSetResolutionReq)) == -1) { err = BadFontPath; goto fail; } if (_fs_write_pad(conn, (char *) res, (num_res * SIZEOF(fsResolution))) == -1) { err = BadFontPath; goto fail; } } sp = strrchr(conn->servername, '/'); /* don't get tricked by a non-existant catalogue list */ if (sp == strchr(conn->servername, '/')) { /* * try original name -- this might be an alternate with no catalogues */ sp = strrchr(conn->requestedname, '/'); if (sp == strchr(conn->requestedname, '/')) sp = (char *) 0; } if (sp) { /* turn cats into counted list */ sp++; /* allocate more than enough room */ cp = client_cat = (char *) xalloc(strlen(conn->servername)); if (!cp) { err = BadAlloc; goto fail; } num_cats = 0; while (*sp) { end = strchr(sp, CATALOGUE_SEP); if (!end) end = sp + strlen(sp); *cp++ = len = end - sp; num_cats++; memmove(cp, sp, len); sp += len; if (*sp == CATALOGUE_SEP) sp++; cp += len; } clen = cp - client_cat; /* our list checked out, so send it */ screq.reqType = FS_SetCatalogues; screq.num_catalogues = num_cats; screq.length = (SIZEOF(fsSetCataloguesReq) + clen + 3) >> 2; _fs_add_req_log(conn, FS_SetCatalogues); if (_fs_write(conn, (char *) &screq, SIZEOF(fsSetCataloguesReq)) == -1) { err = BadFontPath; goto fail; } if (_fs_write_pad(conn, (char *) client_cat, clen) == -1) { err = BadFontPath; goto fail; } /* * now sync up with the font server, to see if an error was generated * by a bogus catalogue */ lcreq.reqType = FS_ListCatalogues; lcreq.length = (SIZEOF(fsListCataloguesReq)) >> 2; lcreq.maxNames = 0; lcreq.nbytes = 0; _fs_add_req_log(conn, FS_SetCatalogues); if (_fs_write(conn, (char *) &lcreq, SIZEOF(fsListCataloguesReq)) == -1) { err = BadFontPath; goto fail; } /* * next bit will either by the ListCats reply, or an error followed by * the reply */ if (_fs_read(conn, (char *) &lcreply, SIZEOF(fsGenericReply)) == -1) { err = BadFontPath; goto fail; } if (lcreply.type == FS_Error && ((fsError *) & lcreply)->major_opcode == FS_SetCatalogues) { _fs_eat_rest_of_error(conn, (fsError *) & lcreply); /* get ListCats response */ (void) _fs_read(conn, (char *) &lcreply, SIZEOF(fsListCataloguesReply)); err = BadFontPath; goto fail; } /* must be reply, swallow the rest of it */ _fs_eat_rest_of_error(conn, (fsError *) & lcreply); }fail: xfree(client_cat); return err;}/* * close font server and remove any state associated with * this connection - this includes any client records. */static voidfs_close_conn(conn) FSFpePtr conn;{ FSClientPtr client, nclient; /* XXX - hack. The right fix is to remember that the font server has gone away when we first discovered it. */ if (conn->trans_conn) (void) _FontTransClose (conn->trans_conn); if (conn->fs_fd != -1) FD_CLR(conn->fs_fd, &_fs_fd_mask); for (client = conn->clients; client; client = nclient) { nclient = client->next; xfree (client); } conn->clients = NULL;}/* * the wakeup handlers have to be set when the FPE is open, and not * removed until it is freed, in order to handle unexpected data, like * events *//* ARGSUSED */static intfs_init_fpe(fpe) FontPathElementPtr fpe;{ FSFpePtr conn; char *name; int err; /* open font server */ /* create FS specific fpe info */ errno = 0; name = fpe->name; /* hack for old style names */ if (*name == ':') name++; /* skip ':' */ conn = _fs_open_server(name); if (conn) { conn->requestedname = fpe->name; /* stash this for later init use */ fpe->private = (pointer) conn; err = fs_send_init_packets(conn); if (err != Successful) { fs_close_conn(conn); xfree(conn->servername); xfree(conn->alts); xfree(conn); return err; } if (init_fs_handlers(fpe, fs_block_handler) != Successful) return AllocError; FD_SET(conn->fs_fd, &_fs_fd_mask); conn->attemptReconnect = TRUE;#ifdef NCD if (configData.ExtendedFontDiags) printf("Connected to font server \"%s\"\n", name);#endif return err; }#ifdef DEBUG fprintf(stderr, "failed to connect to FS \"%s\"\n", name);#endif#ifdef NCD if (configData.ExtendedFontDiags) printf("Failed to connect to font server \"%s\"\n", name);#endif return (errno == ENOMEM) ? AllocError : BadFontPath;}static intfs_reset_fpe(fpe) FontPathElementPtr fpe;{ (void) fs_send_init_packets((FSFpePtr) fpe->private); return Successful;}/* * this shouldn't be called till all refs to the FPE are gone */static intfs_free_fpe(fpe) FontPathElementPtr fpe;{ FSFpePtr conn = (FSFpePtr) fpe->private; FSFpePtr recon, *prev; prev = &awaiting_reconnect; while (*prev) { recon = *prev; if (conn == recon) { *prev = recon->next_reconnect; break; } prev = &recon->next_reconnect; } fs_close_conn(conn); remove_fs_handlers(fpe, fs_block_handler, !XFD_ANYSET(&_fs_fd_mask) && !awaiting_reconnect); xfree(conn->alts); xfree(conn->servername); xfree(conn); fpe->private = (pointer) 0;#ifdef NCD if (configData.ExtendedFontDiags) printf("Disconnected from font server \"%s\"\n", fpe->name);#endif return Successful;}static FSBlockDataPtrfs_new_block_rec(fpe, client, type) FontPathElementPtr fpe; pointer client; int type;{ FSBlockDataPtr blockrec, br; FSFpePtr fsfpe = (FSFpePtr) fpe->private; int size; blockrec = (FSBlockDataPtr) xalloc(sizeof(FSBlockDataRec)); if (!blockrec) return (FSBlockDataPtr) 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -