Skip to content

Commit

Permalink
Some cleanups for #1843 and other
Browse files Browse the repository at this point in the history
This has some other cleanups to bring down warning message sizes too
  • Loading branch information
monkeyiq committed Oct 26, 2014
1 parent b47bae9 commit 9b18612
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 21 deletions.
13 changes: 7 additions & 6 deletions collab/zmq_kvmsg.c
Expand Up @@ -54,6 +54,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <glib.h>
#include <inttypes.h>
#include "inc/gnetwork.h"

#define DEBUG zclock_log

Expand Down Expand Up @@ -452,10 +453,11 @@ kvmsg_uuid (kvmsg_t *self)
{
assert (self);
if (self->present [FRAME_UUID]
&& zmq_msg_size (&self->frame [FRAME_UUID]) == 16)
return (byte *) zmq_msg_data (&self->frame [FRAME_UUID]);
else
return NULL;
&& zmq_msg_size (&self->frame [FRAME_UUID]) == FF_UUID_BINARY_SIZE )
{
return (byte *) zmq_msg_data (&self->frame [FRAME_UUID]);
}
return NULL;
}


Expand All @@ -468,7 +470,6 @@ kvmsg_set_uuid (kvmsg_t *self)
zmq_msg_t *msg = &self->frame [FRAME_UUID];
zuuid_t *uuid = zuuid_new ();
size_t sz = zuuid_size (uuid);
unsigned char *uuid_buf = NULL;
if (self->present [FRAME_UUID])
zmq_msg_close (msg);
zmq_msg_init_size (msg, sz);
Expand Down Expand Up @@ -646,7 +647,7 @@ void kvmap_visit( zhash_t* kvmap, int64_t minsequence,
args.q = q;
args.minsequence = minsequence;
int rc = zhash_foreach ( kvmap, kvmap_visit_buildq_foreach_fn, &args );
g_queue_foreach( q, callback, argument );
g_queue_foreach( q, (GFunc)callback, argument );
g_queue_free(q);
}

22 changes: 20 additions & 2 deletions fontforge/collabclientpriv.h
Expand Up @@ -55,7 +55,7 @@
extern int DEBUG_SHOW_SFD_CHUNKS; // defined in collabclient.c



// See beacon_announce_t for important detail.
#define beacon_announce_protocol_sz 20
#define beacon_announce_uuid_sz 33
#define beacon_announce_username_sz 50
Expand All @@ -75,6 +75,24 @@ extern int DEBUG_SHOW_SFD_CHUNKS; // defined in collabclient.c
#include "splinefont.h"


/**
* Note that these sizes form an explicit binary contract. If you
* change the length of any of these then you have made a new beacon
* version and will need to update the sending end of the beacon in
* fontforge-internal-collab-server.c to a new version and the
* receiving end of the beacon to handle that new version in addition
* to all the old versions that the FontForge collab session should
* still handle.
*
* Using a binary structure is a trade off; beacons are meant to be
* small and simple and used to discover the server so only things
* like the IP address, user, font etc are interesting because they
* let a user easily select a session. Note that you can more easily
* add to the end of beacon_announce_t because you are then backwards
* compatible in that you are only sending more information than an
* old client expects, and thus old clients will happily work with
* newer servers, sans code that takes advantage of the new field.
*/
typedef struct {
uint8_t protocol [beacon_announce_protocol_sz];
uint8_t version;
Expand Down Expand Up @@ -156,7 +174,7 @@ typedef struct {
// When we send off an SFD then we record the uuid of that file here
// so that we can know if we get a beacon back from the server with
// the same info or not.
char unacknowledged_beacon_uuid[ 40 ];
char unacknowledged_beacon_uuid[ FF_UUID_STRING_SIZE ];
time_t unacknowledged_beacon_sendTime;

// If the session is closing then we return false for 'inSession'
Expand Down
6 changes: 2 additions & 4 deletions fontforge/splinefont.h
Expand Up @@ -36,6 +36,7 @@
# include <gwwiconv.h>
#endif
#include "locale.h"
#include <gnetwork.h>

#ifdef FONTFORGE_CONFIG_USE_DOUBLE
# define real double
Expand Down Expand Up @@ -1933,10 +1934,7 @@ typedef struct splinefont {
/* ufo_descent is negative */

struct sfundoes *undoes;
enum {
collab_uuid_sz = 40
} SplineFontConstants;
char collab_uuid[ collab_uuid_sz ];
char collab_uuid[ FF_UUID_STRING_SIZE ];
int preferred_kerning; // 1 for U. F. O. native, 2 for feature file, 0 undefined. Input functions shall flag 2, I think. This shall be a temporary value absent from S. F. D. for now.
} SplineFont;

Expand Down
1 change: 1 addition & 0 deletions fontforge/views.h
Expand Up @@ -1405,6 +1405,7 @@ extern void Prefs_LoadDefaultPreferences( void );
extern CharView* CharViewFindActive();
extern FontViewBase* FontViewFindActive();
extern FontViewBase* FontViewFind( int (*testFunc)( FontViewBase*, void* ), void* udata );

extern int FontViewFind_byXUID( FontViewBase* fv, void* udata );
extern int FontViewFind_byXUIDConnected( FontViewBase* fv, void* udata );
extern int FontViewFind_byCollabPtr( FontViewBase* fv, void* udata );
Expand Down
2 changes: 1 addition & 1 deletion fontforgeexe/Makefile.am
Expand Up @@ -128,7 +128,7 @@ libfontforgeexe_la_SOURCES = alignment.c anchorsaway.c \
ttfinstrsui.c uiutil.c windowmenu.c justifydlg.c deltaui.c \
usermenu.c macobjective.h \
collabclientui.c collabclientui.h \
sfundo.c wordlistparser.c wordlistparser.h
sfundo.c wordlistparser.c wordlistparser.h fontforgeexe.h

else !GRAPHICAL_USER_INTERFACE

Expand Down
2 changes: 1 addition & 1 deletion fontforgeexe/collab/fontforge-internal-collab-server.c
Expand Up @@ -317,7 +317,7 @@ s_ping (zloop_t *loop, zmq_pollitem_t *poller, void *args)
/* } */

static int
s_flush_ttl (zloop_t *loop, zmq_pollitem_t *poller, void *args)
s_flush_ttl (zloop_t *loop, int unused, void *args)
{
// clonesrv_t *self = (clonesrv_t *) args;
// if (self->kvmap)
Expand Down
13 changes: 7 additions & 6 deletions fontforgeexe/collabclientui.c
Expand Up @@ -31,6 +31,7 @@
#include "uiinterface.h"
#include "sfundo.h"
#include "../fontforge/ffglib.h"
#include "fontforgeexe.h"

int collabclient_setHaveLocalServer( int v );

Expand Down Expand Up @@ -59,7 +60,7 @@ int Collab_getLastChangedCodePoint( void )
// client beacon for discovery
static zbeacon_t* client_beacon = 0;
static GHashTable* peers = 0;
static int client_beacon_timerID = 0;
static BackgroundTimer_t* client_beacon_timerID = 0;
#endif


Expand Down Expand Up @@ -102,7 +103,7 @@ static void zeromq_subscriber_process_update( cloneclient_t* cc, kvmsg_t *kvmsg,
byte* msgtype = kvmsg_get_prop (kvmsg, "type" );

printf("cc process_update() uuid:%s\n", uuid );
FontView* fv = FontViewFind( FontViewFind_byXUIDConnected, uuid );
FontView* fv = FontViewFindUI( FontViewFind_byXUIDConnected, uuid );
printf("fv:%p\n", fv );
if( fv )
{
Expand Down Expand Up @@ -402,7 +403,7 @@ static void collabclient_roundTripTimer( void* ccvp )
_("FontForge expected some input from the server by now.\nWould you like to try to reconnect to the collaboration session?"))==1 )
{
// break session
FontView* fv = FontViewFind( FontViewFind_byCollabPtr, cc );
FontView* fv = FontViewFindUI( FontViewFind_byCollabPtr, cc );
if( fv )
{
printf("fv:%p\n", fv );
Expand Down Expand Up @@ -662,7 +663,7 @@ void collabclient_free( void** ccvp )
zsocket_destroy( cc->ctx, cc->publisher );
BackgroundTimer_remove( cc->roundTripTimer );

FontView* fv = FontViewFind( FontViewFind_byCollabPtr, cc );
FontView* fv = FontViewFindUI( FontViewFind_byCollabPtr, cc );
if( fv )
{
fv->b.collabClient = 0;
Expand Down Expand Up @@ -960,7 +961,7 @@ void collabclient_sessionStart( void* ccvp, FontView *fv )

beacon_moon_bounce_timerID = BackgroundTimer_new( 3000, beacon_moon_bounce_timer_callback, cc );

collabclient_notifySessionJoining( cc, fv );
collabclient_notifySessionJoining( cc, (FontViewBase*)fv );
#endif
}

Expand Down Expand Up @@ -1107,7 +1108,7 @@ void collabclient_sessionReconnect( void* ccvp )
collabclient_remakeSockets( cc );
cc->publisher_sendseq = 1;

FontView* fv = FontViewFind( FontViewFind_byCollabPtr, cc );
FontView* fv = FontViewFindUI( FontViewFind_byCollabPtr, cc );
if( fv )
{
collabclient_sessionJoin( cc, fv );
Expand Down
38 changes: 38 additions & 0 deletions fontforgeexe/fontforgeexe.h
@@ -0,0 +1,38 @@
/* Copyright (C) 2000-2012 by George Williams */
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _FONTFORGEEXE_H
#define _FONTFORGEEXE_H

/**
* These are functions which can only be used on a build that has UI
* enabled.
*/


extern FontView* FontViewFindUI( int (*testFunc)( FontViewBase*, void* udata ), void* udata );

#endif /* _FONTFORGEEXE_H */
6 changes: 6 additions & 0 deletions fontforgeexe/fontview.c
Expand Up @@ -8195,6 +8195,12 @@ FontViewBase* FontViewFind( int (*testFunc)( FontViewBase*, void* udata ), void*
return 0;
}

FontView* FontViewFindUI( int (*testFunc)( FontViewBase*, void* udata ), void* udata )
{
return (FontView*)FontViewFind( testFunc, udata );
}


/****************************************/
/****************************************/
/****************************************/
Expand Down
12 changes: 11 additions & 1 deletion inc/gnetwork.h
Expand Up @@ -56,12 +56,22 @@ extern char* getNetworkAddress( char* outstring );
extern char* HostPortPack( char* hostname, int port );
extern char* HostPortUnpack( char* packed, int* port, int port_default );

/**
* This is ZUUID_LEN. Because that length is stable and to avoid bringing in
* the czmq header file it is redeclared from base form here.
*/
#define FF_UUID_BINARY_SIZE 16
/**
* min length of a buffer that will contain an ascii string serialiation of a uuid
*/
#define FF_UUID_STRING_SIZE 33

/**
* generate a new uuid and stringify it into the target area provided
* after the call target should contain something like
* 1b4e28ba-2fa1-11d2-883f-0016d3cca427
* with the trailing NUL. Before the call target needs to be at least
* UUID_LEN_STR + 1 bytes long.
* FF_UUID_STRING_SIZE bytes long.
* the 'target' is also the return value.
*/
char* ff_uuid_generate( char* target );
Expand Down

0 comments on commit 9b18612

Please sign in to comment.