[stsf-commit] stsf/STClientLibrary/src STSysCtl.c, 1.1.1.1, 1.2 libtest.c, 1.3, 1.4 serverconnection.c, 1.8, 1.9 sysctlvars.h, 1.1.1.1, 1.2

Alexander Gelfenbain stsf-commit at pdx.freedesktop.org
Sun May 30 16:07:20 PDT 2004


Committed by: adg


Index: STSysCtl.c
===================================================================
RCS file: /cvs/stsf/stsf/STClientLibrary/src/STSysCtl.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/STSysCtl.c	26 Mar 2004 19:19:55 -0000	1.1.1.1
+++ b/STSysCtl.c	30 May 2004 23:07:17 -0000	1.2
@@ -62,10 +62,50 @@
 
 /**
  * STSF Client Configuration Parameters 
- *
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  */
+SCStateEnum SCState = SC_INITIAL;
 
 uint32_t SCPayloadSize = 0;
+uint32_t SCAmountToChecksum = AMOUNT_TO_CHECKSUM;
+
+/*
+ */
+
+static STStatus varin(void *to, size_t to_size, void *from, size_t from_size)
+{
+    STStatus t = ST_OK;
+
+    if (from == NULL) {
+        return ST_OK;
+    }
+
+    if (from_size != to_size) {
+        t = ST_BUFSIZE;
+    } else {
+        memcpy(to, from, to_size);
+    }
+
+    return t;
+}
+
+static STStatus varout(void *to, size_t *tosize, void *from, size_t fromsize)
+{
+    STStatus t = ST_OK;
+
+    if (to == NULL || tosize == NULL) {
+        return ST_OK;
+    }
+    
+    if (*tosize >= fromsize) {
+        memcpy(to, from, fromsize);
+    } else {
+        t = ST_BUFSIZE;
+    }
+    
+    *tosize = fromsize;
+    return t;
+}
 
 
 /*
@@ -73,29 +113,39 @@
  * ~~~~~~~~~~~~~~~~
  */
 
-
 STStatus STSysCtlByName(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen)
 {
+    STStatus t = ST_OK;
+
     if (name == NULL || *name == '\0') {
         return ST_NULL_OR_EMPTY_STRING;
     }
     
-    if (!strcmp(name, "sharedcache.payloadsize")) {
-        if (oldlenp != NULL && oldp != NULL) {
-            if (*oldlenp >= sizeof(uint32_t)) {
-                memcpy(oldp, &SCPayloadSize, sizeof(uint32_t));
+    if (!strcmp(name, "sharedcache.payloadsize")) {             
+        // READ - always
+        if ((t = varout(oldp, oldlenp, &SCPayloadSize, sizeof SCPayloadSize)) != ST_OK) {
+            return t;
+        }
+        // WRITE - only prior to establishing a connection
+        if (newp != NULL) {
+            if (SCState == SC_INITIAL || SCState == SC_DISCONNECTED) {
+                t = varin(&SCPayloadSize, sizeof SCPayloadSize, newp, newlen);
             } else {
-                return ST_BUFSIZE;
+                t = ST_PROTECTION;
             }
+        } 
+    } else if (!strcmp(name, "fontenumerator.amounttochecksum")) {
+        // READ - always
+        if ((t = varout(oldp, oldlenp, &SCAmountToChecksum, sizeof SCAmountToChecksum)) != ST_OK) {
+            return t;
+        
         }
+        // WRITE - never
         if (newp != NULL) {
-            if (newlen != sizeof(uint32_t)) {
-                return ST_INVALID_ARGUMENT;
-            }
-            memcpy(&SCPayloadSize, newp, sizeof(uint32_t));
+            t = ST_PROTECTION;
         }
     }
-
-    return ST_OK;
+            
+    return t;
 }
 

Index: libtest.c
===================================================================
RCS file: /cvs/stsf/stsf/STClientLibrary/src/libtest.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- a/libtest.c	26 May 2004 02:58:50 -0000	1.3
+++ b/libtest.c	30 May 2004 23:07:17 -0000	1.4
@@ -435,7 +435,7 @@
     matrix.xx = 14;    matrix.xy = 0;  matrix.tx = 0;
     matrix.yx = 0;     matrix.yy = 14; matrix.ty = 0;
 
-    if ((s = STIntNewFontInstance(e, f, matrix, 72, 72, FS_RF_HINTS | FS_RF_BLACKANDWHITE, &instanceID)) != ST_OK) {
+    if ((s = STIntNewFontInstance(e, f, matrix, 72, 72, FS_RF_HINTS | FS_RF_GRAYSCALE, &instanceID)) != ST_OK) {
         printf("STIntNewFontInstance: %s.\n", ErrorCodeName(s));
         goto done;
     }
@@ -456,7 +456,7 @@
             continue;
         }
 
-        printglyph(buffer, metrics.width, metrics.height, metrics.bytesPerRow, 1, 1);
+        printglyph(buffer, metrics.width, metrics.height, metrics.bytesPerRow, 8, 256);
 
         STIntReleaseGlyphBuffer(e, buffersize, buffer);
         
@@ -1279,10 +1279,29 @@
     if ((ret = STTypeEnvCreateFonts(e, 1, &p, &l, &count, &fontarray)) != ST_OK) {
         printf("STTypeEnvCreateFonts: %s.\n", ErrorCodeName(ret));
     } else {
+        
         printf("STTypeEnvCreateFonts: %d fonts [", count);
         for (i=0; i<count; i++) printf("%d ", fontarray[i]);
         printf("]\n");
 
+        if (count == 1) {
+            const byte *rdata;
+            STSize bcount;
+            
+            printf("Created 1 font. Checking font data integrity...\n");
+            if ((ret = STFontGetData(e, fontarray[0], 0, &bcount, &rdata)) != ST_OK) {
+                printf("STFontGetData: %s.\n", ErrorCodeName(ret));
+            } else {
+                printf("bcount: %d, fi->len: %d >> ", bcount, fi->len);
+                if (fi->len == bcount && !memcmp(fi->ptr, rdata, bcount)) {
+                    printf(" OK!\n");
+                } else {
+                    printf(" ERROR!\n");
+                }
+                free(rdata);
+            }
+        }
+
         if ((ret = STTypeEnvDestroyFonts(e, count, fontarray)) != ST_OK) {
             printf("STTypeEnvDestroryFonts: %s.\n", ErrorCodeName(ret));
         }
@@ -1312,6 +1331,62 @@
     }
 }
 
+const char *fstr(const char *a)
+{
+    return a == NULL ? "(nil)" : a;
+}
+
+void FontInfoTest(void)
+{
+    STTypeEnv e;
+    const char *fname, *psname, *url;
+    STFontType ftype;
+    STFontInfoFlags flags;
+    int sbitcnt;
+    const int *sbitarray;
+    STFontMetrics fm;
+    STFont *fontarray;
+    STCount i, fontcnt;
+    STStatus t;
+
+    if ((t = STTypeEnvNew(&e)) != ST_OK) {
+        printf("STTypeEnvNew: %s", ErrorCodeName(t));
+    }
+
+    if ((t = STTypeEnvFindAllFonts(e, NULL, 0, 0, &fontcnt, &fontarray)) != ST_OK) {
+       printf("STTypeEnvFindAllFonts: %s", ErrorCodeName(t));
+    } 
+
+    for (i=0; i < fontcnt; i++) {
+
+        if ((t = STFontGetInfo(e, fontarray[i], &ftype, &fname, &psname, &flags, &sbitcnt, &sbitarray, &fm, &url)) != ST_OK) {
+            printf("STFontGetInfo: %s.", ErrorCodeName(t));
+        }
+
+        printf("font #%d, fontid: %d, type: %d, flags: %d, sbitcount: %d", i, fontarray[i], ftype, flags, sbitcnt);
+        if (sbitcnt != 0) {
+            printf(" [ ");
+            for (int j=0; j<sbitcnt; j++) {
+                printf("%d ", sbitarray[j]);
+            }
+            printf("]");
+        }
+        printf("\n\tfontname=[%s]\n\tpsname=[%s]\n\turl=[%s]", fstr(fname), fstr(psname), fstr(url));
+        printf("\n\tmetrics=[%g %g %g %g %g %g %g %g %g %g %g %d %d]\n\n",
+               fm.hAscent, fm.hDescent, fm.hLeading, fm.vAscent, fm.vDescent, fm.vLeading,
+               fm.italicAngle, fm.xMin, fm.yMin, fm.xMax, fm.yMax, fm.widthClass, fm.weightClass);
+
+        if (sbitarray != NULL) free((void *)sbitarray);
+        if (fname != NULL) free((void *)fname);
+        if (psname != NULL) free((void *)psname);
+        if (url != NULL) free((void *)url);
+    }
+
+    if (fontarray != NULL) free((void *)fontarray);
+
+    STTypeEnvDispose(e);
+}
+
     
 
 
@@ -1328,20 +1403,33 @@
 
 #define FONTNAME "Times New Roman"
 
+//#define TERMINATE_STFS
+
 int main(int ac, char **av)
 {
     uint32_t psize = 60;
+    uint32_t tmp;
+    size_t tsize = sizeof tmp;
+    STStatus t;
 #ifdef TERMINATE_STFS
     STTypeEnv e;
 #endif
     setlocale(LC_CTYPE, "");
 
-    STSysCtlByName("sharedcache.payloadsize", NULL, NULL, &psize, sizeof(uint32_t));
+    if ((t = STSysCtlByName("sharedcache.payloadsize", NULL, NULL, &psize, sizeof(uint32_t))) != ST_OK) {
+        printf("STSysCtlByName 1: %s\n", ErrorCodeName(t));
+    }
+    if ((t = STSysCtlByName("sharedcache.payloadsize", &tmp, &tsize, NULL, NULL)) != ST_OK) {
+        printf("STSysCtlByName 2: %s\n", ErrorCodeName(t));
+    }
+    printf("sharedcache.payloadsize: %d\n", tmp);
+    if ((t = STSysCtlByName("fontenumerator.amounttochecksum", &tmp, &tsize, NULL, NULL)) != ST_OK) {
+        printf("STSysCtlByName 3: %s\n", ErrorCodeName(t));
+    }
 
-    GlyphVectorTest();
-    GlyphVectorTest3();
+    printf("fontenumerator.amounttochecksum: %d\n", tmp);
 
-//    return 0;
+    FontInfoTest();
     
     FindFontTest(ac, av);
     TypeEnvTest1();
@@ -1362,10 +1450,12 @@
     LayoutTest();
     GlyphVectorTest();
     GlyphVectorTest2();
+
     SessionFontsTest();
 
 
 #ifdef TERMINATE_STFS
+terminate:
     if (STTypeEnvNew(&e) == ST_OK) {
         STIntTerminateFontServer(e);
         STTypeEnvDispose(e);

Index: serverconnection.c
===================================================================
RCS file: /cvs/stsf/stsf/STClientLibrary/src/serverconnection.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- a/serverconnection.c	28 May 2004 18:13:26 -0000	1.8
+++ b/serverconnection.c	30 May 2004 23:07:17 -0000	1.9
@@ -180,40 +180,21 @@
     return 0;
 }
 
-static int fsexchange3(STFSProtoOpcode opcode, int doorfd, char **buf, size_t *bufsize)
+static int fsexchange2(STFSProtoOpcode opcode, int doorfd, char **buf, size_t *bufsize, 
+                       door_desc_t **desc_ptr, uint_t *desc_num) 
 {
-    door_arg_t arg;
-    int ret;
-
     ((DoorRequestIn *) *buf)->state = PROTOCOL;
     ((DoorRequestIn *) *buf)->x.p.opcode = opcode;
 
-    arg.data_ptr = *buf;
-    arg.data_size = *bufsize;
-    arg.desc_ptr = NULL;
-    arg.desc_num = 0;
-
-    arg.rbuf = *buf;
-    arg.rsize = *bufsize;
-
-    sighold(SIGINT); sighold(SIGPIPE); sighold(SIGALRM); sighold(SIGPOLL);
-    ret = door_call(doorfd, &arg);
-    sigrelse(SIGINT); sigrelse(SIGPIPE); sigrelse(SIGALRM); sigrelse(SIGPOLL);
-
-    if (ret == -1) {
-        ErrorStr("%s: door_call error.", __func__);
-        perror("door_call");
-        return 1;
-    }
+    return fsexchange(doorfd, buf, bufsize, desc_ptr, desc_num);
+}
 
-    if (arg.rbuf != *buf) {
-       DebugStr(1, "door_call allocated rbuf");
-       munmap(*buf, *bufsize);
-       *buf = arg.rbuf;
-       *bufsize = arg.rsize;
-    }
+static int fsexchange3(STFSProtoOpcode opcode, int doorfd, char **buf, size_t *bufsize)
+{
+    ((DoorRequestIn *) *buf)->state = PROTOCOL;
+    ((DoorRequestIn *) *buf)->x.p.opcode = opcode;
 
-    return 0;
+    return fsexchange(doorfd, buf, bufsize, NULL, NULL);
 }
 
     
@@ -237,6 +218,9 @@
     if (ret != NULL) {
         *ret = ((DoorRequestOut *) s->doorbuf)->ret;
     }
+
+    DebugStr(8, "%s: ret: %s", __func__, ErrorCodeName(((DoorRequestOut *) s->doorbuf)->ret));
+    
     return fsc_copyout(opcode, s->protobuf, s->protobufsize);
 }
 
@@ -506,7 +490,7 @@
 
     if (ci_terminate_in(s->protobuf, s->protobufsize) != 0) return ST_PROTO_BUFF;
     SetProto(s->doorbuf, FS_TERMINATE_IN);
-    fsexchange3(FS_CLOSE_IN, s->fd, &s->doorbuf, &s->doorbufsize);
+    fsexchange3(FS_TERMINATE_IN, s->fd, &s->doorbuf, &s->doorbufsize);
     return ST_OK;
 }
 
@@ -643,7 +627,7 @@
     fsexchange3(FS_GETNAMESTRING_IN, s->fd, &s->doorbuf, &s->doorbufsize);
     if (ReceiveAndCheck(s, FS_GETNAMESTRING_OUT, &t)) return ST_PROTO_ERROR;
     q = (fsc_getnamestring_out *) s->protobuf;
-    if (q->count != 0 && q->str ) {
+    if (q->count != 0 && q->str != NULL) {
         if ((*str = calloc(q->count, sizeof(byte))) != NULL) {
             memcpy(*str, q->str, q->count * sizeof(byte));
         } else {
@@ -1223,7 +1207,7 @@
         if ((*oPSName = malloc(strlen(q->psname) + 1)) == NULL) {
             goto memory_exit2;
         } else {
-            strcpy(*oPSName, q->fontname);
+            strcpy(*oPSName, q->psname);
         }
     }
 
@@ -1553,10 +1537,14 @@
     STStatus t;
     STOpaqueServerSession *s = CheckSession(session);
     fsc_getfontdata_out *q;
+    door_desc_t desc, *pdesc = NULL;
+    uint_t desc_num = 0;
+
+    
     if (s == NULL) return ST_INTERNAL_ERROR;
 
     if (ci_getfontdata_in(s->protobuf, s->protobufsize, iFont, iTable)) return ST_PROTO_BUFF;
-    fsexchange3(FS_GETFONTDATA_IN, s->fd, &s->doorbuf, &s->doorbufsize);
+    fsexchange2(FS_GETFONTDATA_IN, s->fd, &s->doorbuf, &s->doorbufsize, &pdesc, &desc_num);
     if (ReceiveAndCheck(s, FS_GETFONTDATA_OUT, &t)) return ST_PROTO_ERROR;
     q = (fsc_getfontdata_out *) s->protobuf;
 
@@ -1566,7 +1554,22 @@
         if ((*oRawData = malloc(q->nbytes)) == NULL) {
             t = ST_MEMORY;
         } else {
-            memcpy(*oRawData, q->rawdata, q->nbytes);
+            if (desc_num != 1) {
+                t = ST_PROTO_ERROR;
+                free(*oRawData);
+                *oRawData = NULL;
+            } else {
+                int fd = pdesc->d_data.d_desc.d_descriptor;
+                char *dptr = mmap(NULL, q->nbytes, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+                if (dptr != MAP_FAILED) { 
+                    memcpy(*oRawData, dptr, q->nbytes);
+                } else {
+                    t = ST_FILEIO;
+                    free(*oRawData);
+                    *oRawData = NULL;
+                }
+                close(fd);
+            }
         }
     } else {
         *oRawData = NULL;
@@ -1686,14 +1689,52 @@
     STStatus t;
     byte *p, *totaldata = NULL;
     size_t totalsize = 0;
-    int i;
+    int i, shmfd;
     fsc_createfonts_out *q;
     STOpaqueServerSession *s = CheckSession(session);
+    char *dptr, *tmp_ptr;
+    door_desc_t desc, *pdesc;
+    uint_t desc_num = 1;
+    char *shmfname = "/tmp/XXXXXX";
+
+
     if (s == NULL) return ST_INTERNAL_ERROR;
 
+    for (i=0; i<iDataCount; i++) {
+        totalsize += iDataLength[i];
+    }
 
-    if (ci_createfonts_in(s->protobuf, s->protobufsize, s->cid, iDataCount, iDataLength, iData)) return ST_PROTO_BUFF;
-    fsexchange3(FS_CREATEFONTS_IN, s->fd, &s->doorbuf, &s->doorbufsize);
+    if ((shmfd = mkstemp(shmfname)) == -1) {
+        perror("mkstemp");
+        return ST_FILEIO;
+    }
+    unlink(shmfname);
+
+    if (ftruncate(shmfd, totalsize) == -1) {
+        perror("ftruncate");
+        close(shmfd);
+        return ST_FILEIO;
+    }
+    if ((dptr = mmap(NULL, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0)) == MAP_FAILED) {
+        perror("mmap");
+        close(shmfd);
+        return ST_FILEIO;
+    }
+    tmp_ptr = dptr;
+
+    for (i=0; i<iDataCount; i++) {
+        memcpy(tmp_ptr, iData[i], iDataLength[i]);
+        tmp_ptr += iDataLength[i];
+    }
+
+    munmap(dptr, totalsize);
+
+    desc.d_attributes = DOOR_DESCRIPTOR | DOOR_RELEASE;
+    desc.d_data.d_desc.d_descriptor = shmfd;
+    pdesc = &desc;
+
+    if (ci_createfonts_in(s->protobuf, s->protobufsize, s->cid, iDataCount, iDataLength, totalsize)) return ST_PROTO_BUFF;
+    fsexchange2(FS_CREATEFONTS_IN, s->fd, &s->doorbuf, &s->doorbufsize, &pdesc, &desc_num);
     if (ReceiveAndCheck(s, FS_CREATEFONTS_OUT, &t)) return ST_PROTO_ERROR;
     q = (fsc_createfonts_out*) s->protobuf;
 

Index: sysctlvars.h
===================================================================
RCS file: /cvs/stsf/stsf/STClientLibrary/src/sysctlvars.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- a/sysctlvars.h	26 Mar 2004 19:19:56 -0000	1.1.1.1
+++ b/sysctlvars.h	30 May 2004 23:07:17 -0000	1.2
@@ -49,6 +49,14 @@
 #ifndef __SYSCTL_H
 #define __SYSCTL_H
 
+typedef enum {
+    SC_INITIAL = 0,
+    SC_CONNECTED = 1,
+    SC_DISCONNECTED =2
+} SCStateEnum;
+
+extern SCStateEnum SCState;
+
 extern uint32_t SCPayloadSize;
 
 #endif /* __SYSCTL_H */




More information about the stsf-commit mailing list