summaryrefslogtreecommitdiff
path: root/ext/muscat/muscat_net.c
blob: c053951ddc4cf439ee1fbc3da9e3fac642b8ee02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
   +----------------------------------------------------------------------+
   | Muscat/Empower 1.5 Module for PHP version 4.0                        |
   +----------------------------------------------------------------------+
   | Copyright (c) 2000 Ananova Ltd                                       |
   | http://www.ananova.com                                               |
   | Ananova Ltd, PO Box 36, Leeds, LS11 5ZA, United Kingdom              |
   +----------------------------------------------------------------------+
   | This program is free software; you can redistribute it and/or        |
   | modify it under the terms of the GNU General Public License          |
   | as published by the Free Software Foundation; either version 2       |
   | of the License, or (at your option) any later version.               |
   |                                                                      |
   | This program is distributed in the hope that it will be useful,      |
   | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
   | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
   | GNU General Public License for more details.                         |
   |                                                                      |
   | You should have received a copy of the GNU General Public License    |
   | along with this program; if not, write to the Free Software          |
   | Foundation, Inc., 59 Temple Place - Suite 330, Boston,               |
   | MA  02111-1307, USA.                                                 |
   |                                                                      |
   | A copy is availble at http://www.gnu.org/copyleft/gpl.txt            |
   +----------------------------------------------------------------------+
   | Author: Sam Liddicott <sam@ananova.com>                              |
   +----------------------------------------------------------------------+
 */


#include "php.h"
#include "php_ini.h"
#include "php_muscat.h"

#if HAVE_MUSCAT
#include "muscat_net.h"

int _net_muscat_close(struct MuscatNet_handle *handle) {
  
}

int _net_muscat_give(struct MuscatNet_handle *handle, char* string) {
  Z_TYPE(handle->muscat_response)=' ';
  SOCK_WRITEL(string,strlen(string),handle->socketd);
  SOCK_WRITEL("\n",1,handle->socketd);
}

int _net_muscat_get(struct MuscatNet_handle * handle) {
  char *buf;
  char *end;
  size_t ammount;
  int clen;
  int rlen;

  if (Z_TYPE(handle->muscat_response) == 'P') return GIVING;

  // we can use bcom ourselves!!!
  // read in the 6 byte header...
  if (end=php_sock_fgets((char *)&(handle->muscat_response.bcom), 6, handle->socketd)==NULL) {
    ammount=(char *) end - (char *) (&(handle->muscat_response.bcom)) +1;
    return 1; // NEED TO RAISE ERROR HERE  
  }
  ammount=strlen((char *)&(handle->muscat_response.bcom));
  if (handle->muscat_response.bcom[5]!=' ') {
    printf("%s 5 was not space but [%d]\n",&handle->muscat_response.bcom,handle->muscat_response.bcom[5]);
    return 1; // NEED TO RAISE ERROR HERE  
  }
  handle->muscat_response.bcom[5]=0;
  Z_TYPE(handle->muscat_response)=handle->muscat_response.bcom[0];
  // now read bcom[1-4] and turn to an int
  clen=atoi(&(handle->muscat_response.bcom[1]))+1;

  // now read length bytes in!
  buf=emalloc(clen+1);
  memset(buf,0,clen+1);

  if (end=php_sock_fgets(buf, clen, handle->socketd)==NULL) {
    ammount=(char *) end - (char *) (&(handle->muscat_response.bcom)) +1;
  }
  handle->muscat_response.p=buf;
  handle->muscat_response.length=strlen(buf);
  return 0;
}

void _net_discard(struct MuscatNet_handle * handle) {
  while(Z_TYPE(handle->muscat_response)!='P') {
    if (0!=_net_muscat_get(handle)) break;
  }
}

#endif	/* HAVE_MUSCAT */