88 *使用方法:
99 *make
1010 *make install
11- *client_httpsqs -q your_queue_name -t 20(每秒获取队列的次数)
11+ *httpsqs_client -q your_queue_name -t 20(每秒获取队列的次数)
12+ *
13+ 1214 */
1315#include <unistd.h>
14- #include <signal.h>
16+ #include <signal.h>
1517#include <sys/param.h>
1618#include <sys/types.h>
1719#include <sys/stat.h>
18- #include <stdio.h>
19- #include <stdlib.h>
20- #include <string.h>
21- #include <stdarg.h>
22- #include <sys/socket.h>
23- #include <netinet/in.h>
20+ #include <stdio.h>
21+ #include <stdlib.h>
22+ #include <string.h>
23+ #include <stdarg.h>
24+ #include <sys/socket.h>
25+ #include <netinet/in.h>
2426#include <netdb.h>
2527#include <time.h>
2628
@@ -81,27 +83,12 @@ int htsend(int sock,char *fmt,...)
8183 return send (sock , BUF , strlen (BUF ), 0 );
8284}
8385
84- char * getresult (char * data )
85- {
86- char * res ;
87- int i ;
88- res = (char * )malloc (strlen (data ));
89- for (i = 0 ; i < strlen (data ); i ++ )
90- {
91- if (i >= 21 )
92- {
93- res [i - 21 ] = data [i ];
94- }
95- }
96- return res ;
97- }
98-
9986void process (char * queuename , int loop )
10087{
10188 FILE * fp ;
10289 int black_sock ;
10390 char data [3 ];
104- char str [20 ][ 5000 ];
91+ char * str [9 ];
10592 char post [5000 ];
10693 char pattern [] = "Connection: close" ;
10794 int i = 0 ;
@@ -137,11 +124,13 @@ void process(char *queuename, int loop)
137124 {
138125 if (i != 0 )
139126 {
127+ str [j ] = (char * )realloc (str [j ], (i + 2 ) * sizeof (char ));
140128 str [j ][i + 1 ] == '\0' ;
141129 j ++ ;
142130 i = 0 ;
143131 }
144132 } else {
133+ str [j ] = (char * )realloc (str [j ], (i + 1 ) * sizeof (char ));
145134 str [j ][i ] = data [0 ];
146135 i ++ ;
147136 }
@@ -152,20 +141,20 @@ void process(char *queuename, int loop)
152141
153142 if (str [3 ][0 ] == 'P' )
154143 {
155- pos = malloc ((strlen (str [3 ])- 5 ) * sizeof (char ));
144+ pos = malloc ((strlen (str [3 ]) - 5 ) * sizeof (char ));
156145 for (i = 6 ; i < strlen (str [3 ]); i ++ )
157146 {
158147 pos [i - 6 ] = str [3 ][i ];
159148 }
160149 p = atoi (pos );
161150
162- queuedata = malloc (strlen (str [dataline ])* sizeof (char ));
151+ queuedata = malloc (strlen (str [dataline ]) * sizeof (char ));
163152 strcpy (queuedata , str [dataline ]);
164153
165154 if ((fp = fopen ("httpsqs_sms.log" , "a" )) >= 0 )
166155 fprintf (fp , "GET FROM HTTPSQS:\r\nPOS:%d\nDATA:%s\r\n" , p , queuedata );
167156
168- //这部分是获取队列内容后的操作部分,queuedata为队列内容,p为队列的Pos
157+ //这部分是获取队列内容后的操作部分,queuedata为队列内容,p为队列的Pos
169158 black_sock = htconnect (RemoteIp , RemotePort );
170159 if (black_sock < 0 ) return ;
171160 len = strlen (queuedata ) + 5 ;
@@ -176,7 +165,7 @@ void process(char *queuename, int loop)
176165 htsend (black_sock , "Connection: close\r\n" , 10 );
177166 htsend (black_sock , "\r\n" , 10 );
178167 htsend (black_sock , "data=%s" , queuedata , 10 );
179-
168+
180169 free (queuedata );
181170
182171 i = 0 ;
0 commit comments