Annotation of freem/src/ssvn_lock.c, revision 1.4

1.1       snw         1: /*
1.4     ! snw         2:  *   $Id$
        !             3:  *    ^$LOCK ssvn
1.1       snw         4:  *
                      5:  *  
1.3       snw         6:  *   Author: Serena Willis <snw@coherent-logic.com>
1.1       snw         7:  *    Copyright (C) 1998 MUG Deutschland
1.4     ! snw         8:  *    Copyright (C) 2020, 2025 Coherent Logic Development LLC
1.1       snw         9:  *
                     10:  *
                     11:  *   This file is part of FreeM.
                     12:  *
                     13:  *   FreeM is free software: you can redistribute it and/or modify
                     14:  *   it under the terms of the GNU Affero Public License as published by
                     15:  *   the Free Software Foundation, either version 3 of the License, or
                     16:  *   (at your option) any later version.
                     17:  *
                     18:  *   FreeM is distributed in the hope that it will be useful,
                     19:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
                     20:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     21:  *   GNU Affero Public License for more details.
                     22:  *
                     23:  *   You should have received a copy of the GNU Affero Public License
                     24:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
                     25:  *
1.4     ! snw        26:  *   $Log$
        !            27:  *
        !            28:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
        !            29:  * SPDX-License-Identifier: AGPL-3.0-or-later
1.1       snw        30:  **/
                     31: 
                     32: #include <stdio.h>
                     33: #include <stdlib.h>
                     34: #include <string.h>
                     35: 
                     36: #include "mpsdef.h"
                     37: #include "mref.h"
                     38: 
                     39: void ssvn_lock_add(char *key, pid_t owner_job, int count)
                     40: {
                     41:     register int i;
                     42: 
                     43:     char *t_buf;
                     44:     char *k_buf;
                     45:     char *d_buf;
                     46:     freem_ref_t *r;
                     47:     
                     48:     t_buf = (char *) malloc (STRLEN * sizeof (char));
                     49:     NULLPTRCHK(t_buf,"ssvn_lock_add");
                     50:     
                     51:     k_buf = (char *) malloc (STRLEN * sizeof (char));
                     52:     NULLPTRCHK(k_buf,"ssvn_lock_add");
                     53: 
                     54:     d_buf = (char *) malloc (STRLEN * sizeof (char));
                     55:     NULLPTRCHK(d_buf,"ssvn_lock_add");
                     56:     
                     57:     r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
                     58:     NULLPTRCHK(r,"ssvn_lock_add");
                     59: 
                     60:     mref_init (r, MREF_RT_GLOBAL, "");
                     61:     internal_to_mref (r, key);
                     62:     mref_to_external (r, t_buf);
                     63: 
                     64:     //printf ("key = '%s'\r\n", key);
                     65:     //printf ("r = '%s'\r\n", t_buf);
                     66:     
                     67:     for (i = 0; i < strlen (t_buf); i++) {
                     68: 
                     69:         if (t_buf[i] == '\001') {
                     70:             t_buf[i] = '\0';
                     71:             break;
                     72:         }
                     73: 
                     74:     }
                     75:     
                     76:     snprintf (k_buf, STRLEN - 1, "^$LOCK\202%s\201", t_buf);
1.2       snw        77:     snprintf (d_buf, STRLEN - 1, "%ld,%d\201\0", (long) owner_job, count);
1.1       snw        78: 
                     79:     symtab_shm (set_sym, k_buf, d_buf);
                     80: 
                     81:     free (t_buf);
                     82:     free (k_buf);
                     83:     free (d_buf);
                     84:     free (r);
                     85:     
                     86: }
                     87: 
                     88: void ssvn_lock_remove(char *key)
                     89: {
                     90:     register int i;
                     91: 
                     92:     char *t_buf;
                     93:     char *k_buf;
                     94:     char *d_buf;
                     95:     freem_ref_t *r;
                     96:     
                     97:     t_buf = (char *) malloc (STRLEN * sizeof (freem_ref_t));
                     98:     NULLPTRCHK(t_buf,"ssvn_lock_add");
                     99:     
                    100:     k_buf = (char *) malloc (STRLEN * sizeof (freem_ref_t));
                    101:     NULLPTRCHK(k_buf,"ssvn_lock_add");
                    102: 
                    103:     d_buf = (char *) malloc (STRLEN * sizeof (freem_ref_t));
                    104:     NULLPTRCHK(d_buf,"ssvn_lock_add");
                    105:     
                    106:     r = (freem_ref_t *) malloc (sizeof (freem_ref_t));
                    107:     NULLPTRCHK(r,"ssvn_lock_add");
                    108: 
                    109:     mref_init (r, MREF_RT_GLOBAL, "");
                    110:     internal_to_mref (r, key);
                    111:     mref_to_external (r, t_buf);
                    112: 
                    113:     for (i = 0; i < strlen (t_buf); i++) {
                    114: 
                    115:         if (t_buf[i] == '\001') {
                    116:             t_buf[i] = '\0';
                    117:             break;
                    118:         }
                    119: 
                    120:     }
                    121:     
                    122:     snprintf (k_buf, STRLEN - 1, "^$LOCK\202%s\201", t_buf);
                    123:     snprintf (d_buf, STRLEN - 1, " \201");
                    124: 
                    125:     symtab_shm (kill_sym, k_buf, d_buf);
                    126:     
                    127: }
                    128: 
                    129: void ssvn_lock(short action, char *key, char *data)
                    130: {
                    131: 
                    132:     switch (action) {
                    133: 
                    134:         case set_sym:       
                    135:         case kill_sym:
                    136:             //TODO: remove lock            
                    137:             merr_raise (M29);
                    138:             return;
                    139:             
                    140:         default:
                    141:             symtab_shm (action, key, data);
                    142:             break;
                    143: 
                    144:     }
                    145:     
                    146:     return;
                    147: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>